Skip to content

Commit bde77c8

Browse files
committed
fix(spec-specs): fix duplicate storage writes in state tracker
- Perform a similar check to balance changes and other tracker methods, check to make sure we keep the last write only.
1 parent 36443d2 commit bde77c8

File tree

1 file changed

+14
-2
lines changed
  • src/ethereum/forks/amsterdam/block_access_lists

1 file changed

+14
-2
lines changed

src/ethereum/forks/amsterdam/block_access_lists/builder.py

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -126,8 +126,8 @@ def add_storage_write(
126126
Add a storage write operation to the block access list.
127127
128128
Records a storage slot modification for a given address at a specific
129-
transaction index. Multiple writes to the same slot are tracked
130-
separately, maintaining the order and transaction index of each change.
129+
transaction index. If multiple writes occur to the same slot within the
130+
same transaction (same block_access_index), only the final value is kept.
131131
132132
Parameters
133133
----------
@@ -149,6 +149,18 @@ def add_storage_write(
149149
if slot not in builder.accounts[address].storage_changes:
150150
builder.accounts[address].storage_changes[slot] = []
151151

152+
# Check if there's already an entry with the same block_access_index
153+
# If so, update it with the new value, keeping only the final write
154+
changes = builder.accounts[address].storage_changes[slot]
155+
for i, existing_change in enumerate(changes):
156+
if existing_change.block_access_index == block_access_index:
157+
# Update the existing entry with the new value
158+
changes[i] = StorageChange(
159+
block_access_index=block_access_index, new_value=new_value
160+
)
161+
return
162+
163+
# No existing entry found, append new change
152164
change = StorageChange(
153165
block_access_index=block_access_index, new_value=new_value
154166
)

0 commit comments

Comments
 (0)