-
Notifications
You must be signed in to change notification settings - Fork 309
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: use recover_eth_address Cairo1 Helper (#1114)
<!--- Please provide a general summary of your changes in the title above --> <!-- Give an estimate of the time you spent on this PR in terms of work days. Did you spend 0.5 days on this PR or rather 2 days? --> Time spent on this PR: 0.2d ## Pull request type <!-- Please try to limit your pull request to one type, submit multiple pull requests if needed. --> Please check the type of change your PR introduces: - [ ] Bugfix - [ ] Feature - [ ] Code style update (formatting, renaming) - [ ] Refactoring (no functional changes, no api changes) - [ ] Build related changes - [ ] Documentation content changes - [ ] Other (please describe): ## What is the current behavior? <!-- Please describe the current behavior that you are modifying, or link to a relevant issue. --> Resolves #1111 Closes #1095 ## What is the new behavior? <!-- Please describe the behavior or changes that are being added by this PR. --> - - - <!-- Reviewable:start --> - - - This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/kkrt-labs/kakarot/1114) <!-- Reviewable:end -->
- Loading branch information
Showing
5 changed files
with
75 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
%lang starknet | ||
|
||
from starkware.cairo.common.cairo_builtins import BitwiseBuiltin | ||
from starkware.cairo.common.cairo_secp.bigint3 import BigInt3, UnreducedBigInt3 | ||
from starkware.cairo.common.cairo_secp.signature import validate_signature_entry | ||
from starkware.cairo.common.uint256 import Uint256 | ||
from kakarot.interfaces.interfaces import ICairo1Helpers | ||
from starkware.cairo.common.cairo_secp.bigint import uint256_to_bigint | ||
|
||
namespace Signature { | ||
// A version of verify_eth_signature, with that msg_hash, r and s as Uint256 and | ||
// using the Cairo1 helpers class. | ||
func verify_eth_signature_uint256{ | ||
syscall_ptr: felt*, range_check_ptr, bitwise_ptr: BitwiseBuiltin* | ||
}(msg_hash: Uint256, r: Uint256, s: Uint256, v: felt, eth_address: felt, helpers_class: felt) { | ||
alloc_locals; | ||
let (msg_hash_bigint: BigInt3) = uint256_to_bigint(msg_hash); | ||
let (r_bigint: BigInt3) = uint256_to_bigint(r); | ||
let (s_bigint: BigInt3) = uint256_to_bigint(s); | ||
|
||
with_attr error_message("Signature out of range.") { | ||
validate_signature_entry(r_bigint); | ||
validate_signature_entry(s_bigint); | ||
} | ||
|
||
with_attr error_message("Invalid signature.") { | ||
let (success, recovered_address) = ICairo1Helpers.library_call_recover_eth_address( | ||
class_hash=helpers_class, msg_hash=msg_hash, r=r, s=s, y_parity=v | ||
); | ||
assert success = 1; | ||
assert eth_address = recovered_address; | ||
} | ||
return (); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters