Skip to content
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
Original file line number Diff line number Diff line change
Expand Up @@ -52,14 +52,14 @@ class BalAccountAbsentValues(CamelModel):
absent_values = BalAccountAbsentValues(
nonce_changes=[
# Forbid exact nonce change at this tx
BalNonceChange(tx_index=1, post_nonce=5),
BalNonceChange(block_access_index=1, post_nonce=5),
],
storage_changes=[
BalStorageSlot(
slot=0x42,
slot_changes=[
# Forbid exact storage change at this slot and tx
BalStorageChange(tx_index=2, post_value=0x99)
BalStorageChange(block_access_index=2, post_value=0x99)
],
)
],
Expand Down Expand Up @@ -173,22 +173,23 @@ def validate_against(self, account: BalAccountChange) -> None:
self._validate_forbidden_changes(
account.nonce_changes,
self.nonce_changes,
lambda a, f: a.tx_index == f.tx_index
lambda a, f: a.block_access_index == f.block_access_index
and a.post_nonce == f.post_nonce,
lambda a: f"Unexpected nonce change found at tx {a.tx_index}",
lambda a: f"Unexpected nonce change found at tx {a.block_access_index}",
)
self._validate_forbidden_changes(
account.balance_changes,
self.balance_changes,
lambda a, f: a.tx_index == f.tx_index
lambda a, f: a.block_access_index == f.block_access_index
and a.post_balance == f.post_balance,
lambda a: f"Unexpected balance change found at tx {a.tx_index}",
lambda a: f"Unexpected balance change found at tx {a.block_access_index}",
)
self._validate_forbidden_changes(
account.code_changes,
self.code_changes,
lambda a, f: a.tx_index == f.tx_index and a.new_code == f.new_code,
lambda a: f"Unexpected code change found at tx {a.tx_index}",
lambda a, f: a.block_access_index == f.block_access_index
and a.new_code == f.new_code,
lambda a: f"Unexpected code change found at tx {a.block_access_index}",
)

for forbidden_storage_slot in self.storage_changes:
Expand All @@ -199,11 +200,11 @@ def validate_against(self, account: BalAccountChange) -> None:
actual_storage_slot.slot_changes,
forbidden_storage_slot.slot_changes,
lambda a, f: (
a.tx_index == f.tx_index
a.block_access_index == f.block_access_index
and a.post_value == f.post_value
),
lambda a, slot=slot_id: (
f"Unexpected storage change found at slot {slot} in tx {a.tx_index}"
f"Unexpected storage change found at slot {slot} in tx {a.block_access_index}"
),
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
CamelModel,
HexNumber,
RLPSerializable,
StorageKey,
)


Expand All @@ -24,69 +23,69 @@ class BalNonceChange(CamelModel, RLPSerializable):

model_config = CamelModel.model_config | {"extra": "forbid"}

tx_index: HexNumber = Field(
block_access_index: HexNumber = Field(
HexNumber(1),
description="Transaction index where the change occurred",
)
post_nonce: HexNumber = Field(
..., description="Nonce value after the transaction"
)

rlp_fields: ClassVar[List[str]] = ["tx_index", "post_nonce"]
rlp_fields: ClassVar[List[str]] = ["block_access_index", "post_nonce"]


class BalBalanceChange(CamelModel, RLPSerializable):
"""Represents a balance change in the block access list."""

model_config = CamelModel.model_config | {"extra": "forbid"}

tx_index: HexNumber = Field(
block_access_index: HexNumber = Field(
HexNumber(1),
description="Transaction index where the change occurred",
)
post_balance: HexNumber = Field(
..., description="Balance after the transaction"
)

rlp_fields: ClassVar[List[str]] = ["tx_index", "post_balance"]
rlp_fields: ClassVar[List[str]] = ["block_access_index", "post_balance"]


class BalCodeChange(CamelModel, RLPSerializable):
"""Represents a code change in the block access list."""

model_config = CamelModel.model_config | {"extra": "forbid"}

tx_index: HexNumber = Field(
block_access_index: HexNumber = Field(
HexNumber(1),
description="Transaction index where the change occurred",
)
new_code: Bytes = Field(..., description="New code bytes")

rlp_fields: ClassVar[List[str]] = ["tx_index", "new_code"]
rlp_fields: ClassVar[List[str]] = ["block_access_index", "new_code"]


class BalStorageChange(CamelModel, RLPSerializable):
"""Represents a change to a specific storage slot."""

model_config = CamelModel.model_config | {"extra": "forbid"}

tx_index: HexNumber = Field(
block_access_index: HexNumber = Field(
HexNumber(1),
description="Transaction index where the change occurred",
)
post_value: StorageKey = Field(
post_value: HexNumber = Field(
..., description="Value after the transaction"
)

rlp_fields: ClassVar[List[str]] = ["tx_index", "post_value"]
rlp_fields: ClassVar[List[str]] = ["block_access_index", "post_value"]


class BalStorageSlot(CamelModel, RLPSerializable):
"""Represents all changes to a specific storage slot."""

model_config = CamelModel.model_config | {"extra": "forbid"}

slot: StorageKey = Field(..., description="Storage slot key")
slot: HexNumber = Field(..., description="Storage slot key")
slot_changes: List[BalStorageChange] = Field(
default_factory=list, description="List of changes to this slot"
)
Expand All @@ -112,7 +111,7 @@ class BalAccountChange(CamelModel, RLPSerializable):
storage_changes: List[BalStorageSlot] = Field(
default_factory=list, description="List of storage changes"
)
storage_reads: List[StorageKey] = Field(
storage_reads: List[HexNumber] = Field(
default_factory=list,
description="List of storage slots that were read",
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ class BlockAccessListExpectation(CamelModel):
expected_block_access_list = BlockAccessListExpectation(
account_expectations={
alice: BalAccountExpectation(
nonce_changes=[BalNonceChange(tx_index=1, post_nonce=1)]
nonce_changes=[BalNonceChange(block_access_index=1, post_nonce=1)]
),
bob: None, # Bob should NOT be in the BAL
}
Expand Down Expand Up @@ -326,8 +326,8 @@ def _compare_account_expectations(
slot_actual_idx
]
if (
actual_change.tx_index
== expected_change.tx_index
actual_change.block_access_index
== expected_change.block_access_index
and actual_change.post_value
== expected_change.post_value
):
Expand Down Expand Up @@ -361,27 +361,32 @@ def _compare_account_expectations(
# Create tuples for comparison (ordering already validated)
if field_name == "nonce_changes":
expected_tuples = [
(c.tx_index, c.post_nonce) for c in expected_list
(c.block_access_index, c.post_nonce)
for c in expected_list
]
actual_tuples = [
(c.tx_index, c.post_nonce) for c in actual_list
(c.block_access_index, c.post_nonce)
for c in actual_list
]
item_type = "nonce"
elif field_name == "balance_changes":
expected_tuples = [
(c.tx_index, int(c.post_balance))
(c.block_access_index, int(c.post_balance))
for c in expected_list
]
actual_tuples = [
(c.tx_index, int(c.post_balance)) for c in actual_list
(c.block_access_index, int(c.post_balance))
for c in actual_list
]
item_type = "balance"
elif field_name == "code_changes":
expected_tuples = [
(c.tx_index, bytes(c.new_code)) for c in expected_list
(c.block_access_index, bytes(c.new_code))
for c in expected_list
]
actual_tuples = [
(c.tx_index, bytes(c.new_code)) for c in actual_list
(c.block_access_index, bytes(c.new_code))
for c in actual_list
]
item_type = "code"
else:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ def transform(bal: BlockAccessList) -> BlockAccessList:

def _modify_field_value(
address: Address,
tx_index: int,
block_access_index: int,
field_name: str,
change_class: type,
new_value: Any,
Expand Down Expand Up @@ -85,9 +85,12 @@ def transform(bal: BlockAccessList) -> BlockAccessList:
for j, change in enumerate(
storage_slot.slot_changes
):
if change.tx_index == tx_index:
if (
change.block_access_index
== block_access_index
):
kwargs = {
"tx_index": tx_index,
"block_access_index": block_access_index,
value_field: new_value,
}
storage_slot.slot_changes[j] = (
Expand All @@ -98,9 +101,9 @@ def transform(bal: BlockAccessList) -> BlockAccessList:
else:
# flat structure (nonce, balance, code)
for i, change in enumerate(changes):
if change.tx_index == tx_index:
if change.block_access_index == block_access_index:
kwargs = {
"tx_index": tx_index,
"block_access_index": block_access_index,
value_field: new_value,
}
changes[i] = change_class(**kwargs)
Expand Down Expand Up @@ -172,23 +175,28 @@ def remove_code(


def modify_nonce(
address: Address, tx_index: int, nonce: int
address: Address, block_access_index: int, nonce: int
) -> Callable[[BlockAccessList], BlockAccessList]:
"""Set an incorrect nonce value for a specific account and transaction."""
return _modify_field_value(
address, tx_index, "nonce_changes", BalNonceChange, nonce, "post_nonce"
address,
block_access_index,
"nonce_changes",
BalNonceChange,
nonce,
"post_nonce",
)


def modify_balance(
address: Address, tx_index: int, balance: int
address: Address, block_access_index: int, balance: int
) -> Callable[[BlockAccessList], BlockAccessList]:
"""
Set an incorrect balance value for a specific account and transaction.
"""
return _modify_field_value(
address,
tx_index,
block_access_index,
"balance_changes",
BalBalanceChange,
balance,
Expand All @@ -197,15 +205,15 @@ def modify_balance(


def modify_storage(
address: Address, tx_index: int, slot: int, value: int
address: Address, block_access_index: int, slot: int, value: int
) -> Callable[[BlockAccessList], BlockAccessList]:
"""
Set an incorrect storage value for a specific account, transaction, and
slot.
"""
return _modify_field_value(
address,
tx_index,
block_access_index,
"storage_changes",
BalStorageChange,
value,
Expand All @@ -216,11 +224,16 @@ def modify_storage(


def modify_code(
address: Address, tx_index: int, code: bytes
address: Address, block_access_index: int, code: bytes
) -> Callable[[BlockAccessList], BlockAccessList]:
"""Set an incorrect code value for a specific account and transaction."""
return _modify_field_value(
address, tx_index, "code_changes", BalCodeChange, code, "post_code"
address,
block_access_index,
"code_changes",
BalCodeChange,
code,
"post_code",
)


Expand All @@ -242,46 +255,46 @@ def transform(bal: BlockAccessList) -> BlockAccessList:
# Swap in nonce changes
if new_account.nonce_changes:
for nonce_change in new_account.nonce_changes:
if nonce_change.tx_index == tx1:
if nonce_change.block_access_index == tx1:
nonce_indices[tx1] = True
nonce_change.tx_index = HexNumber(tx2)
elif nonce_change.tx_index == tx2:
nonce_change.block_access_index = HexNumber(tx2)
elif nonce_change.block_access_index == tx2:
nonce_indices[tx2] = True
nonce_change.tx_index = HexNumber(tx1)
nonce_change.block_access_index = HexNumber(tx1)

# Swap in balance changes
if new_account.balance_changes:
for balance_change in new_account.balance_changes:
if balance_change.tx_index == tx1:
if balance_change.block_access_index == tx1:
balance_indices[tx1] = True
balance_change.tx_index = HexNumber(tx2)
elif balance_change.tx_index == tx2:
balance_change.block_access_index = HexNumber(tx2)
elif balance_change.block_access_index == tx2:
balance_indices[tx2] = True
balance_change.tx_index = HexNumber(tx1)
balance_change.block_access_index = HexNumber(tx1)

# Swap in storage changes (nested structure)
if new_account.storage_changes:
for storage_slot in new_account.storage_changes:
for storage_change in storage_slot.slot_changes:
if storage_change.tx_index == tx1:
if storage_change.block_access_index == tx1:
balance_indices[tx1] = True
storage_change.tx_index = HexNumber(tx2)
elif storage_change.tx_index == tx2:
storage_change.block_access_index = HexNumber(tx2)
elif storage_change.block_access_index == tx2:
balance_indices[tx2] = True
storage_change.tx_index = HexNumber(tx1)
storage_change.block_access_index = HexNumber(tx1)

# Note: storage_reads is just a list of StorageKey, no tx_index to
# Note: storage_reads is just a list of StorageKey, no block_access_index to
# swap

# Swap in code changes
if new_account.code_changes:
for code_change in new_account.code_changes:
if code_change.tx_index == tx1:
if code_change.block_access_index == tx1:
code_indices[tx1] = True
code_change.tx_index = HexNumber(tx2)
elif code_change.tx_index == tx2:
code_change.block_access_index = HexNumber(tx2)
elif code_change.block_access_index == tx2:
code_indices[tx2] = True
code_change.tx_index = HexNumber(tx1)
code_change.block_access_index = HexNumber(tx1)

new_root.append(new_account)

Expand Down
Loading
Loading