Skip to content

Commit ccc02a3

Browse files
committed
Fix bug in tracker
Manually cherry-picked from e72991b Author: nerolation
1 parent f522534 commit ccc02a3

File tree

1 file changed

+11
-8
lines changed
  • src/ethereum/amsterdam/block_access_lists

1 file changed

+11
-8
lines changed

src/ethereum/amsterdam/block_access_lists/tracker.py

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -59,9 +59,9 @@ class StateChangeTracker:
5959

6060
pre_storage_cache: Dict[tuple, U256] = field(default_factory=dict)
6161
"""
62-
Cache of pre-state storage values, keyed by (address, slot) tuples.
63-
This cache persists across transactions within a block to track the
64-
original state before any modifications.
62+
Cache of pre-transaction storage values, keyed by (address, slot) tuples.
63+
This cache is cleared at the start of each transaction to track values
64+
from the beginning of the current transaction.
6565
"""
6666

6767
current_block_access_index: int = 0
@@ -90,17 +90,20 @@ def set_transaction_index(
9090
1..n for transactions, n+1 for post-execution).
9191
"""
9292
tracker.current_block_access_index = block_access_index
93+
# Clear the pre-storage cache for each new transaction to ensure
94+
# no-op writes are detected relative to the transaction start
95+
tracker.pre_storage_cache.clear()
9396

9497

9598
def capture_pre_state(
9699
tracker: StateChangeTracker, address: Address, key: Bytes32, state: "State"
97100
) -> U256:
98101
"""
99-
Capture and cache the pre-state value for a storage location.
102+
Capture and cache the pre-transaction value for a storage location.
100103
101-
Retrieves the storage value from before any transactions in the current
102-
block modified it. The value is cached to avoid repeated lookups and
103-
to maintain consistency across multiple accesses.
104+
Retrieves the storage value from the beginning of the current transaction.
105+
The value is cached within the transaction to avoid repeated lookups and
106+
to maintain consistency across multiple accesses within the same transaction.
104107
105108
Parameters
106109
----------
@@ -116,7 +119,7 @@ def capture_pre_state(
116119
Returns
117120
-------
118121
value :
119-
The original storage value before any block modifications.
122+
The storage value at the beginning of the current transaction.
120123
"""
121124
cache_key = (address, key)
122125
if cache_key not in tracker.pre_storage_cache:

0 commit comments

Comments
 (0)