7
7
8
8
import pytest
9
9
10
- from ethereum_test_forks import Fork
10
+ from ethereum_test_benchmark . benchmark_code_generator import JumpLoopGenerator
11
11
from ethereum_test_tools import (
12
12
Alloc ,
13
+ BenchmarkTestFiller ,
13
14
Bytecode ,
14
- StateTestFiller ,
15
- Transaction ,
16
15
)
17
16
from ethereum_test_vm import Opcode
18
17
from ethereum_test_vm import Opcodes as Op
19
18
20
- from .helpers import code_loop_precompile_call
21
-
22
19
23
20
@pytest .mark .parametrize (
24
21
"opcode" ,
43
40
)
44
41
@pytest .mark .parametrize ("fixed_offset" , [True , False ])
45
42
def test_worst_log_opcodes (
46
- state_test : StateTestFiller ,
43
+ benchmark_test : BenchmarkTestFiller ,
47
44
pre : Alloc ,
48
- fork : Fork ,
49
45
opcode : Opcode ,
50
46
zeros_topic : bool ,
51
47
size : int ,
52
48
fixed_offset : bool ,
53
49
non_zero_data : bool ,
54
- gas_benchmark_value : int ,
55
50
):
56
51
"""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 ()
60
53
61
54
# For non-zero data, load into memory.
62
55
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 )
64
57
65
58
# Push the size value onto the stack and access it using the DUP opcode.
66
- calldata += Op .PUSH3 (size )
59
+ setup += Op .PUSH3 (size )
67
60
68
61
# 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 )
70
63
71
64
topic_count = len (opcode .kwargs or []) - 2
72
65
offset = Op .PUSH0 if fixed_offset else Op .MOD (Op .GAS , 7 )
@@ -75,21 +68,10 @@ def test_worst_log_opcodes(
75
68
# 0 topics -> DUP1, 1 topic -> DUP2, N topics -> DUP(N+1)
76
69
size_op = getattr (Op , f"DUP{ topic_count + 2 } " )
77
70
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
90
72
91
- state_test (
73
+ benchmark_test (
92
74
pre = pre ,
93
75
post = {},
94
- tx = tx ,
76
+ code_generator = JumpLoopGenerator ( setup = setup , attack_block = attack_block ) ,
95
77
)
0 commit comments