Skip to content
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

feat: validate signature values #1331

Merged
merged 4 commits into from
Aug 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions src/kakarot/accounts/library.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,16 @@ namespace AccountContract {
with_attr error_message("Incorrect signature length") {
assert signature_len = 5;
}

with_attr error_message("Signatures values not in range") {
assert [range_check_ptr] = signature[0];
assert [range_check_ptr + 1] = signature[1];
assert [range_check_ptr + 2] = signature[2];
assert [range_check_ptr + 3] = signature[3];
assert [range_check_ptr + 4] = signature[4];
let range_check_ptr = range_check_ptr + 5;
}

let r = Uint256(signature[0], signature[1]);
let s = Uint256(signature[2], signature[3]);
let v = signature[4];
Expand Down
28 changes: 27 additions & 1 deletion tests/src/kakarot/accounts/test_account_contract.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from eth_account.account import Account
from eth_utils import keccak
from hypothesis import assume, given, settings
from hypothesis.strategies import binary, composite, integers
from hypothesis.strategies import binary, composite, integers, lists, permutations
from starkware.cairo.lang.cairo_constants import DEFAULT_PRIME
from starkware.starknet.public.abi import (
get_selector_from_name,
Expand Down Expand Up @@ -367,6 +367,32 @@ def test_should_raise_with_wrong_signature(self, cairo_run):
chain_id=CHAIN_ID,
)

@composite
def draw_signature_not_in_range(draw):
# create signature with 4 elements < 2 ** 128 and one > 2 ** 128
signature = draw(
lists(
integers(min_value=0, max_value=2**128 - 1), min_size=4, max_size=4
)
)
signature.append(
draw(integers(min_value=2**128, max_value=DEFAULT_PRIME - 1))
)
# Draw randomly signature elements
return draw(permutations(signature))

@given(draw_signature_not_in_range())
def test_should_raise_with_signature_values_not_in_range(
self, cairo_run, draw_signature_not_in_range
):
with cairo_error(message="Signatures values not in range"):
cairo_run(
"test__execute_from_outside",
tx_data=[1],
signature=draw_signature_not_in_range,
chain_id=CHAIN_ID,
)

@SyscallHandler.patch("Account_evm_address", int(ARACHNID_PROXY_DEPLOYER, 16))
def test_should_raise_unauthorized_pre_eip155_tx(self, cairo_run):
rlp_decoded = rlp.decode(ARACHNID_PROXY_SIGNED_TX)
Expand Down
Loading