diff --git a/cairo/ethereum/cancun/state.cairo b/cairo/ethereum/cancun/state.cairo index 09f199f96..a5a70351a 100644 --- a/cairo/ethereum/cancun/state.cairo +++ b/cairo/ethereum/cancun/state.cairo @@ -823,91 +823,6 @@ func close_transaction{ return (); } -func copy_storage_tries_recursive{ - range_check_ptr, - poseidon_ptr: PoseidonBuiltin*, - new_storage_tries: MappingTupleAddressBytes32U256, -}(dict_start: TupleAddressBytes32U256DictAccess*, dict_end: TupleAddressBytes32U256DictAccess*) { - alloc_locals; - // Base case: if start == end, return - if (dict_start == dict_end) { - return (); - } - - // Get the current entry - let key = [dict_start].key; - let trie_ptr = [dict_start].new_value; - - // Copy the trie - tempvar trie_to_copy = TrieAddressOptionalAccount( - cast(trie_ptr.value, TrieAddressOptionalAccountStruct*) - ); - let copied_trie = copy_TrieAddressOptionalAccount{trie=trie_to_copy}(); - - // Write to new storage tries mapping - let new_storage_trie_ptr = cast(new_storage_tries.value.dict_ptr, DictAccess*); - hashdict_write{poseidon_ptr=poseidon_ptr, dict_ptr=new_storage_trie_ptr}( - 1, &key.value, cast(copied_trie.value, felt) - ); - - // Update new_storage_tries with new dict_ptr - tempvar new_storage_tries = MappingTupleAddressBytes32U256( - new MappingTupleAddressBytes32U256Struct( - dict_ptr_start=new_storage_tries.value.dict_ptr_start, - dict_ptr=cast(new_storage_trie_ptr, TupleAddressBytes32U256DictAccess*), - parent_dict=new_storage_tries.value.parent_dict, - ), - ); - - // Recursive call with next entry - return copy_storage_tries_recursive( - dict_start + TupleAddressBytes32U256DictAccess.SIZE, dict_end - ); -} - -func copy_transient_storage_tries_recursive{ - range_check_ptr, - poseidon_ptr: PoseidonBuiltin*, - new_transient_tries: MappingTupleAddressBytes32U256, -}(dict_start: TupleAddressBytes32U256DictAccess*, dict_end: TupleAddressBytes32U256DictAccess*) { - alloc_locals; - - // Base case: if start == end, return - if (dict_start == dict_end) { - return (); - } - - // Get the current entry - let key = [dict_start].key; - let trie_ptr = [dict_start].new_value; - - // Copy the trie - let trie_to_copy = TrieTupleAddressBytes32U256( - cast(trie_ptr.value, TrieTupleAddressBytes32U256Struct*) - ); - let copied_trie = copy_TrieTupleAddressBytes32U256{trie=trie_to_copy}(); - - // Write to new transient storage tries mapping - let new_transient_trie_ptr = cast(new_transient_tries.value.dict_ptr, DictAccess*); - hashdict_write{poseidon_ptr=poseidon_ptr, dict_ptr=new_transient_trie_ptr}( - 1, &key.value, cast(copied_trie.value, felt) - ); - - // Update new_transient_tries with new dict_ptr - tempvar new_transient_tries = MappingTupleAddressBytes32U256( - new MappingTupleAddressBytes32U256Struct( - dict_ptr_start=new_transient_tries.value.dict_ptr_start, - dict_ptr=cast(new_transient_trie_ptr, TupleAddressBytes32U256DictAccess*), - parent_dict=new_transient_tries.value.parent_dict, - ), - ); - - // Recursive call with next entry - return copy_transient_storage_tries_recursive( - dict_start + TupleAddressBytes32U256DictAccess.SIZE, dict_end - ); -} - func set_code{poseidon_ptr: PoseidonBuiltin*, state: State}(address: Address, code: Bytes) { // Get the current account let account = get_account(address); diff --git a/cairo/tests/ethereum/cancun/test_state.py b/cairo/tests/ethereum/cancun/test_state.py index c893ac931..364a68754 100644 --- a/cairo/tests/ethereum/cancun/test_state.py +++ b/cairo/tests/ethereum/cancun/test_state.py @@ -2,7 +2,7 @@ from typing import Optional import pytest -from ethereum.cancun.fork_types import Account, Address +from ethereum.cancun.fork_types import EMPTY_ACCOUNT, Account, Address from ethereum.cancun.state import ( account_exists, account_exists_and_is_empty, @@ -383,6 +383,19 @@ def test_destroy_touched_empty_accounts(self, cairo_run, data): destroy_touched_empty_accounts(state, touched_accounts) assert state_cairo == state + @given(data=touched_accounts_strategy(), address=...) + def test_destroy_touched_empty_accounts_with_empty_account( + self, cairo_run, data, address: Address + ): + state, touched_accounts = data + touched_accounts.add(address) + set_account(state, address, EMPTY_ACCOUNT) + state_cairo = cairo_run( + "destroy_touched_empty_accounts", state, touched_accounts + ) + destroy_touched_empty_accounts(state, touched_accounts) + assert state_cairo == state + class TestStateStorage: @given(data=state_and_address_and_optional_key(key_strategy=bytes32))