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

fix: revert tx if multicall input is incoherent #1655

Merged
merged 3 commits into from
Dec 5, 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
7 changes: 3 additions & 4 deletions cairo_zero/kakarot/precompiles/kakarot_precompiles.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -150,10 +150,9 @@
) = 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;

Check warning on line 154 in cairo_zero/kakarot/precompiles/kakarot_precompiles.cairo

View check run for this annotation

Codecov / codecov/patch

cairo_zero/kakarot/precompiles/kakarot_precompiles.cairo#L154

Added line #L154 was not covered by tests
}
}

return (output_len, output, gas_cost, reverted);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,10 @@
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
from tests.utils.errors import evm_error
from tests.utils.errors import cairo_error, evm_error


@pytest_asyncio.fixture(scope="module")
Expand Down Expand Up @@ -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
):
Expand All @@ -107,16 +106,16 @@ 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 * max(wrong_nb_calls, 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
Expand Down
Loading