-
Notifications
You must be signed in to change notification settings - Fork 11.2k
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
crypto: add Move contract and tests for ecrecover to address #4543
Conversation
@@ -1765,19 +1765,21 @@ B1: | |||
4: Gt | |||
5: BrTrue(7) | |||
B2: | |||
6: Branch(16) | |||
6: Branch(18) |
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.
cheking @oxade is this calibration related snapshot change expected? i added a new native move function
@@ -18,6 +18,11 @@ module sui::crypto { | |||
/// applied to Secp256k1 signatures. | |||
public native fun ecrecover(signature: vector<u8>, hashed_msg: vector<u8>): vector<u8>; | |||
|
|||
/// @param pubkey: A 33-bytes compressed public key, a prefix either 0x02 or 0x03 and a 256-bit integer. | |||
/// | |||
/// If the compressed public key is valid, return the 65-bytes uncompressed public key. |
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.
Nit: should say what will happen if it is invalid.
/// @param pubkey: A 33-bytes compressed public key, a prefix either 0x02 or 0x03 and a 256-bit integer. | ||
/// | ||
/// If the compressed public key is valid, return the 65-bytes uncompressed public key. | ||
public native fun decompress_pubkey(pubkey: vector<u8>): vector<u8>; |
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.
(Not to be addressed in this PR, but some ideas for improving this library)
- We could use type wrappers to represent compressed and decompressed public keys, signatures, etc. instead of always using
vector<u8>
. This should make it easier to avoid common mistakes/misuse - Instead of having one big
crypto
library, we could split it into a few smaller ones partitioned by (e.g.) signature scheme. No strong priors on how this should be done, but I think it will be easier to add new schemes in the future if we can do so by adding a fresh module instead of upgrading an existing on-chain module
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.
good point, will follow up a PR: #4567
…ct and tests for ecrecover to address
}; | ||
|
||
let pubkey = crypto::ecrecover(signature, hashed_msg); | ||
let uncompressed = crypto::decompress_pubkey(pubkey); |
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.
thanks! and good observation that in Eth they hash the uncompressed pub key.
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.
Approving this to unblock Eth bridging devs experimenting with Sui<>Eth. Agree with Sam re distinct PubKey types.
Addressed comments from #4461
Published contract on local testnet and call ecrecover_to_eth_address method:
Publish package:
Call method:
Get the output object with the value of address:
Verify the address: