@@ -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