Skip to content

Commit 50916a1

Browse files
refactor: update blockhash case
1 parent cbcac72 commit 50916a1

File tree

1 file changed

+29
-14
lines changed

1 file changed

+29
-14
lines changed

tests/benchmark/test_worst_stateful_opcodes.py

Lines changed: 29 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
from ethereum_test_benchmark.benchmark_code_generator import ExtCallGenerator, JumpLoopGenerator
1111
from ethereum_test_forks import Fork
12-
from ethereum_test_specs import BlockchainTestFiller, StateTestFiller
12+
from ethereum_test_specs import StateTestFiller
1313
from ethereum_test_specs.benchmark import BenchmarkTestFiller
1414
from ethereum_test_tools import (
1515
Account,
@@ -429,30 +429,45 @@ def test_worst_storage_access_warm(
429429

430430

431431
def test_worst_blockhash(
432-
blockchain_test: BlockchainTestFiller,
432+
benchmark_test: BenchmarkTestFiller,
433433
pre: Alloc,
434+
fork: Fork,
434435
gas_benchmark_value: int,
435-
) -> None:
436+
tx_gas_limit_cap: int,
437+
):
436438
"""
437439
Test running a block with as many blockhash accessing oldest allowed block
438440
as possible.
439441
"""
440442
# Create 256 dummy blocks to fill the blockhash window.
441443
blocks = [Block()] * 256
442444

443-
# Always ask for the oldest allowed BLOCKHASH block.
444-
execution_code = Op.PUSH1(1) + While(
445-
body=Op.POP(Op.BLOCKHASH(Op.DUP1)),
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,
446450
)
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(),
452-
)
453-
blocks.append(Block(txs=[op_tx]))
454451

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(
456471
pre=pre,
457472
post={},
458473
blocks=blocks,

0 commit comments

Comments
 (0)