diff --git a/cairo_zero/tests/src/utils/test_eth_transaction.py b/cairo_zero/tests/src/utils/test_eth_transaction.py index 664d00b2b..5ba3944b0 100644 --- a/cairo_zero/tests/src/utils/test_eth_transaction.py +++ b/cairo_zero/tests/src/utils/test_eth_transaction.py @@ -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( diff --git a/cairo_zero/utils/eth_transaction.cairo b/cairo_zero/utils/eth_transaction.cairo index f3a1758fd..1cca6eca2 100644 --- a/cairo_zero/utils/eth_transaction.cairo +++ b/cairo_zero/utils/eth_transaction.cairo @@ -62,6 +62,7 @@ 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 { @@ -69,11 +70,15 @@ namespace EthTransaction { 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];