Skip to content
This repository was archived by the owner on Jan 9, 2025. It is now read-only.

[KGA-65] fix: decode legacy chain id overflow #1581

Merged
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
16 changes: 16 additions & 0 deletions cairo_zero/tests/src/utils/test_eth_transaction.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,22 @@ async def test_should_raise_with_list_items(self, cairo_run):
with cairo_error():
cairo_run("test__decode", data=list(encode(list(transaction.values()))))

async def test_should_raise_if_chain_id_overflow_legacy_transaction(
self, cairo_run
):
transaction = {
"nonce": 0,
"gasPrice": 234567897654321,
"gas": 2_000_000,
"to": "0xF0109fC8DF283027b6285cc889F5aA624EaC1F55",
"value": 1_000_000_000,
"data": b"",
"chainId": 2**252,
}
with cairo_error(message="assert_nn(31 - items[6].data_len);"):
encoded_unsigned_tx = rlp_encode_signed_data(transaction)
cairo_run("test__decode", data=list(encoded_unsigned_tx))

@given(value=st.integers(min_value=2**248))
@pytest.mark.parametrize("transaction", TRANSACTIONS)
@pytest.mark.parametrize(
Expand Down
5 changes: 5 additions & 0 deletions cairo_zero/utils/eth_transaction.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -62,18 +62,23 @@ namespace EthTransaction {

// pre eip-155 txs have 6 fields, post eip-155 txs have 9 fields
if (items_len == 6) {
tempvar range_check_ptr = range_check_ptr;
tempvar is_some = 0;
tempvar chain_id = 0;
} else {
assert items_len = 9;
assert items[6].is_list = FALSE;
assert items[7].is_list = FALSE;
assert items[8].is_list = FALSE;

assert_nn(31 - items[6].data_len);
let chain_id = Helpers.bytes_to_felt(items[6].data_len, items[6].data);

tempvar range_check_ptr = range_check_ptr;
tempvar is_some = 1;
tempvar chain_id = chain_id;
}
let range_check_ptr = [ap - 3];
let is_some = [ap - 2];
let chain_id = [ap - 1];

Expand Down
Loading