-
Notifications
You must be signed in to change notification settings - Fork 5.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Introduce crypto
module and expand cryptographic functions
#6837
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't understand the cryptography that is going on, but the changes to std
look fine. I've added a few nits, but nothing that would prevent approval.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🚀
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
looks good otherwise
Description
This PR replaces #5747 and intends to introduce the crypto module.
The std-lib currently contains the
ecr.sw
andvm/evm/ecr.sw
files which have the following functions:There are a number of issues with this including no type safety for signatures from different elliptic curves, functions split across multiple files, poor naming, and generic arguments. All of these are resolved by this PR which deprecates both
ecr.sw
files and replaces them with a crypto module which syntactically matches Rust.The following new types are introduced:
PublicKey
- An Asymmetric public key, supporting both 64 and 32-byte public keysMessage
- Hashed message authenticated by a signature type that handles variable lengthsSecp256k1
- A secp256k1 signatureSecp256r1
- A secp256r1 signatureEd25519
- An ed25519 signatureSignature
- An ECDSA signatureAll original functionality is retained with the new module:
Secp256k1::recover()
- Recovers a public key.Secp256r1::recover()
- Recovers a public key.Secp256k1::address()
- Recovers an address.Secp256r1::address()
- Recovers an address.Secp256k1::evm_address()
- Recovers an EVM address.Ed25519::verify()
- Verify that a signature matches the given public key.The following new functionality has been added:
Secp256k1::verify()
- Verify that a signature matches the given public key.Secp256r1::verify()
- Verify that a signature matches the given public key.Secp256k1::verify_address()
- Verify that a signature matches the given address.Secp256r1::verify_address()
- Verify that a signature matches the given address.Secp256k1::verify_evm_address()
- Verify that a signature matches the given EVM address.Secp256r1::verify_evm_address()
- Verify that a signature matches the given EVM address.Secp256r1::evm_address()
- Recovers an EVM address.The following functions have been deprecated:
std::ecr::ec_recover()
std::ecr::ec_recover_r1()
std::ecr::ed_verify()
std::ecr::ec_recover_address()
std::ecr::ec_recover_address_r1()
std::vm::evm::ecr::ec_recover_evm_address()
Example of changes for recovering a public key:
Example of changes for recovering an Address:
Complete recovery example using the
Signature
type:Checklist
Breaking*
orNew Feature
labels where relevant.