Skip to content
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -736,6 +736,64 @@ def transform(bal: BlockAccessList) -> BlockAccessList:
return transform


def remove_slot_change(
address: Address, slot: int, block_access_index: int
) -> Callable[[BlockAccessList], BlockAccessList]:
"""
Remove a single slot change entry at a given block access index, while
keeping any other slot_changes entries for that same slot intact.

Unlike `remove_storage`, which drops all storage_changes for an
account, this targets one entry within one slot's slot_changes list.
Useful for testing that a slot's earliest recorded change must match
the transaction that actually performed it.
"""

def transform(bal: BlockAccessList) -> BlockAccessList:
found_address = False
found_slot = False
found_index = False
new_root = []
for account_change in bal.root:
if account_change.address == address:
found_address = True
new_account = account_change.model_copy(deep=True)
for storage_slot in new_account.storage_changes:
if storage_slot.slot != slot:
continue
found_slot = True
remaining = [
change
for change in storage_slot.slot_changes
if change.block_access_index != block_access_index
]
if len(remaining) != len(storage_slot.slot_changes):
found_index = True
storage_slot.slot_changes = remaining
new_root.append(new_account)
else:
new_root.append(account_change)

if not found_address:
raise ValueError(
f"Address {address} not found in BAL to remove slot change"
)
if not found_slot:
raise ValueError(
f"Storage slot {slot} not found in storage_changes of "
f"account {address}"
)
if not found_index:
raise ValueError(
f"Block access index {block_access_index} not found in "
f"storage slot {slot} of account {address}"
)

return BlockAccessList(root=new_root)

return transform


def reverse_accounts() -> Callable[[BlockAccessList], BlockAccessList]:
"""Reverse the order of accounts in the BAL."""

Expand Down Expand Up @@ -831,6 +889,7 @@ def transform(bal: BlockAccessList) -> BlockAccessList:
"modify_code",
# Block access index modifiers
"swap_bal_indices",
"remove_slot_change",
# Duplicate entry modifiers (uniqueness constraint testing)
"duplicate_nonce_change",
"duplicate_balance_change",
Expand Down
Loading
Loading