From 184fe73e5f22abbf25480991e7c1698d73152d99 Mon Sep 17 00:00:00 2001 From: enitrat Date: Thu, 5 Dec 2024 21:42:11 +0800 Subject: [PATCH 1/3] revert tx if multicall input is incoherent --- .../precompiles/kakarot_precompiles.cairo | 7 +++---- .../test_multicall_cairo_precompile.py | 20 +++++++++---------- 2 files changed, 12 insertions(+), 15 deletions(-) diff --git a/cairo_zero/kakarot/precompiles/kakarot_precompiles.cairo b/cairo_zero/kakarot/precompiles/kakarot_precompiles.cairo index 812313e02..80798cdb3 100644 --- a/cairo_zero/kakarot/precompiles/kakarot_precompiles.cairo +++ b/cairo_zero/kakarot/precompiles/kakarot_precompiles.cairo @@ -150,10 +150,9 @@ namespace KakarotPrecompiles { ) = Internals.execute_multiple_cairo_calls(caller_address, calls_len, calls_ptr, 0); if (reverted == FALSE and nb_executed_calls != number_of_calls) { - let (revert_reason_len, revert_reason) = Errors.precompileInputError(); - return ( - revert_reason_len, revert_reason, CAIRO_PRECOMPILE_GAS, Errors.EXCEPTIONAL_HALT - ); + with_attr error_message("Number of executed calls does not match precompile input") { + assert nb_executed_calls = number_of_calls; + } } return (output_len, output, gas_cost, reverted); diff --git a/tests/end_to_end/CairoPrecompiles/test_multicall_cairo_precompile.py b/tests/end_to_end/CairoPrecompiles/test_multicall_cairo_precompile.py index 2b103f0a8..6656d2210 100644 --- a/tests/end_to_end/CairoPrecompiles/test_multicall_cairo_precompile.py +++ b/tests/end_to_end/CairoPrecompiles/test_multicall_cairo_precompile.py @@ -9,7 +9,7 @@ from kakarot_scripts.utils.kakarot import deploy, eth_send_transaction from kakarot_scripts.utils.starknet import get_contract, invoke -from tests.utils.errors import evm_error +from tests.utils.errors import cairo_error, evm_error @pytest_asyncio.fixture(scope="module") @@ -107,16 +107,14 @@ async def test_should_fail_when_number_of_calls_mismatch_actual_calls( # modify the number of calls to be different than the actual calls tx_data = f"{wrong_nb_calls:064x}" + tx_data[64:] - _, response, success, _ = await eth_send_transaction( - to=f"0x{0x75003:040x}", - gas=21000 + 20000 * (len(calls)), - data=tx_data, - value=0, - caller_eoa=owner.starknet_contract, - ) - - assert not success - assert "Precompile: input error".encode() == bytes(response) + with cairo_error("Number of executed calls does not match precompile input"): + await eth_send_transaction( + to=f"0x{0x75003:040x}", + gas=21000 + 20000 * (len(calls)), + data=tx_data, + value=0, + caller_eoa=owner.starknet_contract, + ) async def test_should_increase_counter_single_call_from_solidity( self, cairo_counter, multicall_cairo_counter_caller From ba5752e1306c3520e19d002fe3bedf1afb1221ee Mon Sep 17 00:00:00 2001 From: enitrat Date: Thu, 5 Dec 2024 22:07:25 +0800 Subject: [PATCH 2/3] fmt test file --- .../CairoPrecompiles/test_multicall_cairo_precompile.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/tests/end_to_end/CairoPrecompiles/test_multicall_cairo_precompile.py b/tests/end_to_end/CairoPrecompiles/test_multicall_cairo_precompile.py index 6656d2210..9504ff2cf 100644 --- a/tests/end_to_end/CairoPrecompiles/test_multicall_cairo_precompile.py +++ b/tests/end_to_end/CairoPrecompiles/test_multicall_cairo_precompile.py @@ -107,7 +107,9 @@ async def test_should_fail_when_number_of_calls_mismatch_actual_calls( # modify the number of calls to be different than the actual calls tx_data = f"{wrong_nb_calls:064x}" + tx_data[64:] - with cairo_error("Number of executed calls does not match precompile input"): + with cairo_error( + "Number of executed calls does not match precompile input" + ): await eth_send_transaction( to=f"0x{0x75003:040x}", gas=21000 + 20000 * (len(calls)), From 8d98d932b50a6bdb248d9bd4fc2a819d880be571 Mon Sep 17 00:00:00 2001 From: enitrat Date: Thu, 5 Dec 2024 22:19:39 +0800 Subject: [PATCH 3/3] adapt range of input and gas passed to tx. --- .../CairoPrecompiles/test_multicall_cairo_precompile.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/tests/end_to_end/CairoPrecompiles/test_multicall_cairo_precompile.py b/tests/end_to_end/CairoPrecompiles/test_multicall_cairo_precompile.py index 9504ff2cf..29e316146 100644 --- a/tests/end_to_end/CairoPrecompiles/test_multicall_cairo_precompile.py +++ b/tests/end_to_end/CairoPrecompiles/test_multicall_cairo_precompile.py @@ -5,7 +5,6 @@ from eth_abi import encode from hypothesis import assume, given, settings from hypothesis import strategies as st -from starkware.cairo.lang.cairo_constants import DEFAULT_PRIME from kakarot_scripts.utils.kakarot import deploy, eth_send_transaction from kakarot_scripts.utils.starknet import get_contract, invoke @@ -94,7 +93,7 @@ async def test_should_set_and_increase_counter_in_batch( expected_count = new_counter + 1 assert new_count == expected_count - @given(wrong_nb_calls=st.integers(min_value=0, max_value=DEFAULT_PRIME - 1)) + @given(wrong_nb_calls=st.integers(min_value=0, max_value=2**8 - 1)) async def test_should_fail_when_number_of_calls_mismatch_actual_calls( self, cairo_counter, owner, wrong_nb_calls ): @@ -112,7 +111,7 @@ async def test_should_fail_when_number_of_calls_mismatch_actual_calls( ): await eth_send_transaction( to=f"0x{0x75003:040x}", - gas=21000 + 20000 * (len(calls)), + gas=21000 + 20000 * max(wrong_nb_calls, len(calls)), data=tx_data, value=0, caller_eoa=owner.starknet_contract,