77
88import pytest
99
10- from ethereum_test_forks import Fork
10+ from ethereum_test_benchmark . benchmark_code_generator import JumpLoopGenerator
1111from ethereum_test_tools import (
1212 Alloc ,
13+ BenchmarkTestFiller ,
1314 Bytecode ,
14- StateTestFiller ,
15- Transaction ,
1615)
1716from ethereum_test_tools .vm .opcode import Opcodes as Op
1817from ethereum_test_vm .opcode import Opcode
1918
20- from .helpers import code_loop_precompile_call
21-
2219
2320@pytest .mark .parametrize (
2421 "opcode" ,
4340)
4441@pytest .mark .parametrize ("fixed_offset" , [True , False ])
4542def test_worst_log_opcodes (
46- state_test : StateTestFiller ,
43+ benchmark_test : BenchmarkTestFiller ,
4744 pre : Alloc ,
48- fork : Fork ,
4945 opcode : Opcode ,
5046 zeros_topic : bool ,
5147 size : int ,
5248 fixed_offset : bool ,
5349 non_zero_data : bool ,
54- gas_benchmark_value : int ,
5550):
5651 """Test running a block with as many LOG opcodes as possible."""
57- max_code_size = fork .max_code_size ()
58-
59- calldata = Bytecode ()
52+ setup = Bytecode ()
6053
6154 # For non-zero data, load into memory.
6255 if non_zero_data :
63- calldata += Op .CODECOPY (dest_offset = 0 , offset = 0 , size = Op .CODESIZE )
56+ setup += Op .CODECOPY (dest_offset = 0 , offset = 0 , size = Op .CODESIZE )
6457
6558 # Push the size value onto the stack and access it using the DUP opcode.
66- calldata += Op .PUSH3 (size )
59+ setup += Op .PUSH3 (size )
6760
6861 # For non-zeros topic, push a non-zero value for topic.
69- calldata += Op .PUSH0 if zeros_topic else Op .PUSH32 (2 ** 256 - 1 )
62+ setup += Op .PUSH0 if zeros_topic else Op .PUSH32 (2 ** 256 - 1 )
7063
7164 topic_count = len (opcode .kwargs or []) - 2
7265 offset = Op .PUSH0 if fixed_offset else Op .MOD (Op .GAS , 7 )
@@ -75,21 +68,10 @@ def test_worst_log_opcodes(
7568 # 0 topics -> DUP1, 1 topic -> DUP2, N topics -> DUP(N+1)
7669 size_op = getattr (Op , f"DUP{ topic_count + 2 } " )
7770
78- code_sequence = Op .DUP1 * topic_count + size_op + offset + opcode
79-
80- code = code_loop_precompile_call (calldata , code_sequence , fork )
81- assert len (code ) <= max_code_size
82-
83- code_address = pre .deploy_contract (code = code )
84-
85- tx = Transaction (
86- to = code_address ,
87- gas_limit = gas_benchmark_value ,
88- sender = pre .fund_eoa (),
89- )
71+ attack_block = Op .DUP1 * topic_count + size_op + offset + opcode
9072
91- state_test (
73+ benchmark_test (
9274 pre = pre ,
9375 post = {},
94- tx = tx ,
76+ code_generator = JumpLoopGenerator ( setup = setup , attack_block = attack_block ) ,
9577 )
0 commit comments