@@ -59,9 +59,9 @@ class StateChangeTracker:
59
59
60
60
pre_storage_cache : Dict [tuple , U256 ] = field (default_factory = dict )
61
61
"""
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 .
65
65
"""
66
66
67
67
current_block_access_index : int = 0
@@ -90,17 +90,20 @@ def set_transaction_index(
90
90
1..n for transactions, n+1 for post-execution).
91
91
"""
92
92
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 ()
93
96
94
97
95
98
def capture_pre_state (
96
99
tracker : StateChangeTracker , address : Address , key : Bytes32 , state : "State"
97
100
) -> U256 :
98
101
"""
99
- Capture and cache the pre-state value for a storage location.
102
+ Capture and cache the pre-transaction value for a storage location.
100
103
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 .
104
107
105
108
Parameters
106
109
----------
@@ -116,7 +119,7 @@ def capture_pre_state(
116
119
Returns
117
120
-------
118
121
value :
119
- The original storage value before any block modifications .
122
+ The storage value at the beginning of the current transaction .
120
123
"""
121
124
cache_key = (address , key )
122
125
if cache_key not in tracker .pre_storage_cache :
0 commit comments