-
Notifications
You must be signed in to change notification settings - Fork 596
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
Added verify_eth_signature
to secp256k1
#2929
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.
Reviewable status: 0 of 1 files reviewed, 1 unresolved discussion
a discussion (no related file):
change target branch to main
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.
Reviewable status: 0 of 1 files reviewed, 4 unresolved discussions (waiting on @yuvalsw)
corelib/src/starknet/secp256k1.cairo
line 109 at r2 (raw file):
// TODO(yg): either have 2 syscalls to get x and y of a point, and use the keccak libfunc (if // it makes sense), or have a single syscall to get the keccak of a point. Seconds seems better, // unless getters of x and y are needed anywhere else.
I think having a syscall returning x and y is better - since it makes the other libfuncs usable.
otherwise we simply would have had the recover libfunc and nothing else.
Code quote:
// TODO(yg): either have 2 syscalls to get x and y of a point, and use the keccak libfunc (if
// it makes sense), or have a single syscall to get the keccak of a point. Seconds seems better,
// unless getters of x and y are needed anywhere else.
corelib/src/starknet/secp256k1.cairo
line 112 at r2 (raw file):
let x = secp256k1_ec_point_get_x(public_key_point); let y = secp256k1_ec_point_get_y(public_key_point); let point_hash = keccak(x, y);
Suggestion:
let mut keccak_input = ArrayTrait::new();
keccak::keccak_add_uint256_be(ref keccak_input, x);
keccak::keccak_add_uint256_be(ref keccak_input, y);
keccak::add_padding(ref keccak_input);
let point_hash = starknet::syscalls::keccak_syscall(keccak_input.span()).unwrap_syscall();
corelib/src/starknet/secp256k1.cairo
line 120 at r2 (raw file):
let address_u256 = u256 { high: high_32_bits, low: point_hash.low }; // TODO(yg): need U256TryIntoFelt, and use the relevant trait. EthAddress { address: address_u256.try_into().unwrap() }
let high_32_bits = point_hash.high % 0x100000000;
Suggestion:
// The Ethereum address is the 160 (128+32) least significant bits of the keccak of the public key.
let high_32_bits = point_hash.high % 0x100000000;
let address: felt252 = high_32_bits * 0x100000000000000000000000000000000 + point_hash.low;
EthAddress { address }
cff858d
to
6e071c1
Compare
15ba7fc
to
86cd5df
Compare
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.
Reviewed 36 of 36 files at r8.
Reviewable status: 36 of 37 files reviewed, 5 unresolved discussions (waiting on @yuvalsw)
corelib/src/starknet/secp256k1.cairo
line 109 at r8 (raw file):
/// Checks whether `value` is in the range [1, N). fn is_signature_entry_valid(value: u256) -> bool { value > u256 { high: 0, low: 0 } & value < get_N()
no need for the rangechecks
Suggestion:
value != u256 { high: 0, low: 0 }
81463a5
to
fe0887a
Compare
cda7d98
to
dd41931
Compare
f87a1b0
to
56f119a
Compare
c5b05fb
to
8958064
Compare
8958064
to
b2c5c45
Compare
b2c5c45
to
c414774
Compare
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.
Reviewable status: 32 of 39 files reviewed, 5 unresolved discussions (waiting on @orizi)
corelib/src/starknet/secp256k1.cairo
line 109 at r2 (raw file):
Previously, orizi wrote…
I think having a syscall returning x and y is better - since it makes the other libfuncs usable.
otherwise we simply would have had the recover libfunc and nothing else.
Done.
corelib/src/starknet/secp256k1.cairo
line 112 at r2 (raw file):
let x = secp256k1_ec_point_get_x(public_key_point); let y = secp256k1_ec_point_get_y(public_key_point); let point_hash = keccak(x, y);
Done.
corelib/src/starknet/secp256k1.cairo
line 120 at r2 (raw file):
Previously, orizi wrote…
let high_32_bits = point_hash.high % 0x100000000;
Done.
corelib/src/starknet/secp256k1.cairo
line 109 at r8 (raw file):
Previously, orizi wrote…
no need for the rangechecks
Done.
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.
Reviewed 1 of 3 files at r11, 1 of 1 files at r12, all commit messages.
Reviewable status: 34 of 39 files reviewed, 2 unresolved discussions (waiting on @yuvalsw)
corelib/src/test/secp256k1_test.cairo
line 94 at r12 (raw file):
#[test] #[should_panic]
Suggestion:
#[should_panic(expected: ('Invalid signature', ))]
corelib/src/test/secp256k1_test.cairo
line 107 at r12 (raw file):
#[test] #[should_panic]
Suggestion:
#[should_panic(expected: ('Signature out of range', ))]
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.
Reviewed 2 of 6 files at r9, 1 of 2 files at r10.
Reviewable status: 37 of 39 files reviewed, 2 unresolved discussions (waiting on @yuvalsw)
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.
Reviewed 1 of 6 files at r9, 1 of 3 files at r11.
Reviewable status: all files reviewed, 2 unresolved discussions (waiting on @yuvalsw)
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.
Reviewed 2 of 2 files at r13, all commit messages.
Reviewable status:complete! all files reviewed, all discussions resolved (waiting on @yuvalsw)
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.
Reviewable status:
complete! all files reviewed, all discussions resolved (waiting on @yuvalsw)
corelib/src/test/secp256k1_test.cairo
line 94 at r12 (raw file):
#[test] #[should_panic]
Done.
corelib/src/test/secp256k1_test.cairo
line 107 at r12 (raw file):
#[test] #[should_panic]
Done.
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.
Reviewable status:
complete! all files reviewed, all discussions resolved (waiting on @yuvalsw)
This change is