9
9
10
10
from ethereum_test_benchmark .benchmark_code_generator import ExtCallGenerator , JumpLoopGenerator
11
11
from ethereum_test_forks import Fork
12
- from ethereum_test_specs import BlockchainTestFiller , StateTestFiller
12
+ from ethereum_test_specs import StateTestFiller
13
13
from ethereum_test_specs .benchmark import BenchmarkTestFiller
14
14
from ethereum_test_tools import (
15
15
Account ,
@@ -429,9 +429,11 @@ def test_worst_storage_access_warm(
429
429
430
430
431
431
def test_worst_blockhash (
432
- blockchain_test : BlockchainTestFiller ,
432
+ benchmark_test : BenchmarkTestFiller ,
433
433
pre : Alloc ,
434
+ fork : Fork ,
434
435
gas_benchmark_value : int ,
436
+ tx_gas_limit_cap : int ,
435
437
):
436
438
"""
437
439
Test running a block with as many blockhash accessing oldest allowed block
@@ -440,19 +442,32 @@ def test_worst_blockhash(
440
442
# Create 256 dummy blocks to fill the blockhash window.
441
443
blocks = [Block ()] * 256
442
444
443
- # Always ask for the oldest allowed BLOCKHASH block.
444
- execution_code = Op .PUSH1 (1 ) + While (
445
- body = Op .POP (Op .BLOCKHASH (Op .DUP1 )),
446
- )
447
- execution_code_address = pre .deploy_contract (code = execution_code )
448
- op_tx = Transaction (
449
- to = execution_code_address ,
450
- gas_limit = gas_benchmark_value ,
451
- sender = pre .fund_eoa (),
445
+ code = ExtCallGenerator (setup = Bytecode (), attack_block = Op .BLOCKHASH (0 )).generate_repeated_code (
446
+ repeated_code = Op .BLOCKHASH (1 ),
447
+ setup = Bytecode (),
448
+ cleanup = Bytecode (),
449
+ fork = fork ,
452
450
)
453
- blocks .append (Block (txs = [op_tx ]))
454
451
455
- blockchain_test (
452
+ iteration_count = math .ceil (gas_benchmark_value / tx_gas_limit_cap )
453
+ code_address = pre .deploy_contract (code = code )
454
+
455
+ txs = []
456
+ for i in range (iteration_count ):
457
+ tx_gas_limit = (
458
+ tx_gas_limit_cap
459
+ if i != iteration_count - 1
460
+ else gas_benchmark_value % tx_gas_limit_cap
461
+ )
462
+ tx = Transaction (
463
+ to = code_address ,
464
+ gas_limit = tx_gas_limit ,
465
+ sender = pre .fund_eoa (),
466
+ )
467
+ txs .append (tx )
468
+ blocks .append (Block (txs = txs ))
469
+
470
+ benchmark_test (
456
471
pre = pre ,
457
472
post = {},
458
473
blocks = blocks ,
0 commit comments