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: original storage tries arg gen #471

Merged
merged 4 commits into from
Jan 17, 2025
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
5 changes: 3 additions & 2 deletions cairo/tests/ethereum/cancun/vm/instructions/test_block.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
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
Loading