Skip to content

Commit

Permalink
fix: original storage tries arg gen (#471)
Browse files Browse the repository at this point in the history
Co-authored-by: Oba <obatirou@gmail.com>
  • Loading branch information
enitrat and obatirou committed Jan 17, 2025
1 parent 42fb04c commit 23d56dd
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 4 deletions.
3 changes: 2 additions & 1 deletion cairo/tests/ethereum/cancun/vm/instructions/test_block.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
BLOCK_HASHES_LIST,
address,
bytes32,
empty_state,
uint,
uint64,
uint256,
Expand Down Expand Up @@ -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(()),
Expand Down
6 changes: 5 additions & 1 deletion cairo/tests/utils/args_gen.py
Original file line number Diff line number Diff line change
Expand Up @@ -620,7 +620,11 @@ 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.
data.append(data[1])
# 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)
data.append(snapshots0_storage_tries_ptr)

segments.load_data(struct_ptr, data)

Expand Down
5 changes: 3 additions & 2 deletions cairo/tests/utils/evm_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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(()),
Expand Down
14 changes: 14 additions & 0 deletions cairo/tests/utils/strategies.py
Original file line number Diff line number Diff line change
Expand Up @@ -354,6 +354,20 @@ def tuple_strategy(thing):


# Fork
# A strategy for an empty state - the tries have no data.
empty_state = st.builds(
State,
_main_trie=st.just(
Trie[Address, Optional[Account]](secured=True, default=None, _data={})
),
_storage_tries=st.just({}),
_snapshots=st.just(
[(Trie[Address, Optional[Account]](secured=True, default=None, _data={}), {})]
),
created_accounts=st.just(set()),
)


state = st.lists(address, max_size=MAX_ADDRESS_SET_SIZE, unique=True).flatmap(
lambda addresses: st.builds(
State,
Expand Down

0 comments on commit 23d56dd

Please sign in to comment.