Skip to content

Commit 65c63b1

Browse files
committed
fix(t8n): Only initialize the bal_change_tracker for amsterdam
1 parent 39dcb41 commit 65c63b1

File tree

1 file changed

+58
-36
lines changed

1 file changed

+58
-36
lines changed

src/ethereum_spec_tools/evm_tools/t8n/__init__.py

Lines changed: 58 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -244,15 +244,24 @@ def run_state_test(self) -> Any:
244244
if len(self.txs.transactions) > 0:
245245
tx = self.txs.transactions[0]
246246
try:
247-
self.fork.process_transaction(
248-
block_env=block_env,
249-
block_output=block_output,
250-
tx=tx,
251-
index=Uint(0),
252-
change_tracker=StateChangeTracker(
253-
block_output.block_access_list_builder
254-
),
255-
)
247+
# Only pass change_tracker for Amsterdam and later
248+
if self.fork.is_after_fork("ethereum.amsterdam"):
249+
self.fork.process_transaction(
250+
block_env=block_env,
251+
block_output=block_output,
252+
tx=tx,
253+
index=Uint(0),
254+
change_tracker=StateChangeTracker(
255+
block_output.block_access_list_builder
256+
),
257+
)
258+
else:
259+
self.fork.process_transaction(
260+
block_env=block_env,
261+
block_output=block_output,
262+
tx=tx,
263+
index=Uint(0),
264+
)
256265
except EthereumException as e:
257266
self.txs.rejected_txs[0] = f"Failed transaction: {e!r}"
258267
self.restore_state()
@@ -276,12 +285,12 @@ def _run_blockchain_test(self, block_env: Any, block_output: Any) -> None:
276285
data=block_env.parent_beacon_block_root,
277286
)
278287

279-
bal_change_tracker = StateChangeTracker(
280-
block_output.block_access_list_builder
281-
)
282-
283-
# EIP-7928: Set transaction index for block access lists
288+
bal_change_tracker = None
284289
if self.fork.is_after_fork("ethereum.amsterdam"):
290+
bal_change_tracker = StateChangeTracker(
291+
block_output.block_access_list_builder
292+
)
293+
# EIP-7928: Set transaction index for block access lists
285294
# pre-execution system contracts use index 0
286295
set_transaction_index(bal_change_tracker, 0)
287296

@@ -290,21 +299,26 @@ def _run_blockchain_test(self, block_env: Any, block_output: Any) -> None:
290299
)):
291300
self.backup_state()
292301
try:
293-
# use 1...n for transaction indices
302+
process_tx_args = [
303+
block_env,
304+
block_output,
305+
tx,
306+
Uint(original_idx),
307+
]
308+
294309
if self.fork.is_after_fork("ethereum.amsterdam"):
295-
set_transaction_index(bal_change_tracker, tx_index + 1)
310+
process_tx_args.append(bal_change_tracker)
296311

297-
self.fork.process_transaction(
298-
block_env,
299-
block_output,
300-
tx,
301-
Uint(original_idx),
302-
bal_change_tracker,
303-
)
304-
finalize_transaction_changes(
305-
bal_change_tracker,
306-
block_env.state,
307-
)
312+
assert bal_change_tracker is not None
313+
# use 1...n for transaction indices
314+
set_transaction_index(bal_change_tracker, tx_index + 1)
315+
self.fork.process_transaction(*process_tx_args)
316+
finalize_transaction_changes(
317+
bal_change_tracker,
318+
block_env.state,
319+
)
320+
else:
321+
self.fork.process_transaction(*process_tx_args)
308322

309323
except EthereumException as e:
310324
self.txs.rejected_txs[
@@ -324,19 +338,27 @@ def _run_blockchain_test(self, block_env: Any, block_output: Any) -> None:
324338
)
325339

326340
if self.fork.is_after_fork("ethereum.shanghai"):
327-
self.fork.process_withdrawals(
328-
block_env,
329-
block_output,
330-
self.env.withdrawals,
331-
bal_change_tracker,
332-
)
341+
process_withdrawal_args = [
342+
block_env, block_output, self.env.withdrawals
343+
]
344+
345+
if self.fork.is_after_fork("ethereum.amsterdam"):
346+
assert bal_change_tracker is not None
347+
process_withdrawal_args.append(bal_change_tracker)
348+
349+
self.fork.process_withdrawals(*process_withdrawal_args)
333350

334351
if self.fork.is_after_fork("ethereum.prague"):
335-
self.fork.process_general_purpose_requests(
336-
block_env, block_output, bal_change_tracker
337-
)
352+
process_general_purpose_args = [block_env, block_output]
353+
354+
if self.fork.is_after_fork("ethereum.amsterdam"):
355+
assert bal_change_tracker is not None
356+
process_general_purpose_args.append(bal_change_tracker)
357+
358+
self.fork.process_general_purpose_requests(*process_general_purpose_args)
338359

339360
if self.fork.is_after_fork("ethereum.amsterdam"):
361+
assert bal_change_tracker is not None
340362
num_transactions = len(
341363
[tx for tx in self.txs.successfully_parsed if tx]
342364
)

0 commit comments

Comments
 (0)