diff --git a/cairo/tests/ethereum/cancun/vm/instructions/test_block.py b/cairo/tests/ethereum/cancun/vm/instructions/test_block.py index d238d3c4..90c0ca28 100644 --- a/cairo/tests/ethereum/cancun/vm/instructions/test_block.py +++ b/cairo/tests/ethereum/cancun/vm/instructions/test_block.py @@ -13,12 +13,13 @@ prev_randao, timestamp, ) -from tests.utils.args_gen import Environment, Evm, State, TransientStorage +from tests.utils.args_gen import Environment, Evm, TransientStorage from tests.utils.evm_builder import EvmBuilder, address_zero from tests.utils.strategies import ( BLOCK_HASHES_LIST, address, bytes32, + empty_state, uint, uint64, uint256, @@ -53,7 +54,7 @@ gas_price=st.just(Uint(0)), time=uint256, prev_randao=bytes32, - state=st.just(State()), + state=empty_state, chain_id=uint64, excess_blob_gas=st.just(U64(0)), blob_versioned_hashes=st.just(()), diff --git a/cairo/tests/utils/args_gen.py b/cairo/tests/utils/args_gen.py index 2ae03da7..1f0c4a34 100644 --- a/cairo/tests/utils/args_gen.py +++ b/cairo/tests/utils/args_gen.py @@ -620,6 +620,7 @@ def _gen_arg( # In case of a Trie, we need to put the original_storage_tries (state._snapshots[0][1]) in a # special field of the State. We want easy access / overrides to this specific snapshot in # Cairo, as each `sstore` performs an update of this original trie. + # The state strategy should always generate a valid snapshots[0], corresponding to the initial state. snapshots_ptr = segments.memory.get(data[2]) snapshots0_ptr = segments.memory.get(snapshots_ptr) snapshots0_storage_tries_ptr = segments.memory.get(snapshots0_ptr + 1) diff --git a/cairo/tests/utils/evm_builder.py b/cairo/tests/utils/evm_builder.py index ca9e7b0d..45271c07 100644 --- a/cairo/tests/utils/evm_builder.py +++ b/cairo/tests/utils/evm_builder.py @@ -2,11 +2,12 @@ from ethereum_types.numeric import U64, U256, Bytes32, Uint from hypothesis import strategies as st -from ethereum.cancun.state import State, TransientStorage +from ethereum.cancun.state import TransientStorage from ethereum.exceptions import EthereumException from tests.utils.args_gen import Environment, Evm, Message, Stack from tests.utils.strategies import ( Memory, + empty_state, environment_lite, gas_left, memory_lite, @@ -31,7 +32,7 @@ gas_price=st.just(Uint(0)), time=st.just(U256(0)), prev_randao=st.just(Bytes32(b"\x00" * 32)), - state=st.just(State()), + state=empty_state, chain_id=st.just(U64(0)), excess_blob_gas=st.just(U64(0)), blob_versioned_hashes=st.just(()), diff --git a/cairo/tests/utils/strategies.py b/cairo/tests/utils/strategies.py index be43bf48..c8dc520d 100644 --- a/cairo/tests/utils/strategies.py +++ b/cairo/tests/utils/strategies.py @@ -354,6 +354,33 @@ def tuple_strategy(thing): # Fork +# A strategy for an empty state - the tries have no data. +empty_state = st.builds( + State, + _main_trie=st.builds( + Trie[Address, Optional[Account]], + secured=st.just(True), + default=st.none(), + _data=st.just({}), + ), + _storage_tries=st.just({}), + _snapshots=st.just([]), + created_accounts=st.just(set()), +).map( + lambda state: State( + _main_trie=state._main_trie, + _storage_tries=state._storage_tries, + _snapshots=[ + ( + copy_trie(state._main_trie), + {addr: copy_trie(trie) for addr, trie in state._storage_tries.items()}, + ) + ], + created_accounts=state.created_accounts, + ) +) + + state = st.lists(address, max_size=MAX_ADDRESS_SET_SIZE, unique=True).flatmap( lambda addresses: st.builds( State,