9
9
10
10
import pytest
11
11
12
+ from ethereum_test_benchmark .benchmark_code_generator import JumpLoopGenerator
12
13
from ethereum_test_forks import Fork
13
14
from ethereum_test_tools import (
14
15
Account ,
15
16
Alloc ,
17
+ BenchmarkTestFiller ,
16
18
Block ,
17
19
BlockchainTestFiller ,
18
20
Bytecode ,
21
+ Bytes ,
19
22
Environment ,
20
23
Hash ,
21
24
StateTestFiller ,
@@ -245,7 +248,7 @@ def test_worst_bytecode_single_opcode(
245
248
ids = lambda x : x .hex (),
246
249
)
247
250
def test_worst_initcode_jumpdest_analysis (
248
- state_test : StateTestFiller ,
251
+ benchmark_test : BenchmarkTestFiller ,
249
252
pre : Alloc ,
250
253
fork : Fork ,
251
254
pattern : Bytecode ,
@@ -260,7 +263,6 @@ def test_worst_initcode_jumpdest_analysis(
260
263
The initicode is modified by mixing-in the returned create address between CREATE invocations
261
264
to prevent caching.
262
265
"""
263
- max_code_size = fork .max_code_size ()
264
266
initcode_size = fork .max_initcode_size ()
265
267
266
268
# Expand the initcode pattern to the transaction data so it can be used in CALLDATACOPY
@@ -290,32 +292,20 @@ def test_worst_initcode_jumpdest_analysis(
290
292
# Make sure the last opcode in the initcode is JUMPDEST.
291
293
code_prepare_initcode += Op .MSTORE (initcode_size - 32 , Op .PUSH32 [bytes (Op .JUMPDEST ) * 32 ])
292
294
293
- code_invoke_create = (
295
+ attack_block = (
294
296
Op .PUSH1 [len (initcode_prefix )]
295
297
+ Op .MSTORE
296
298
+ Op .CREATE (value = Op .PUSH0 , offset = Op .PUSH0 , size = Op .MSIZE )
297
299
)
298
300
299
- initial_random = Op .PUSH0
300
- code_prefix = code_prepare_initcode + initial_random
301
- code_loop_header = Op .JUMPDEST
302
- code_loop_footer = Op .JUMP (len (code_prefix ))
303
- code_loop_body_len = (
304
- max_code_size - len (code_prefix ) - len (code_loop_header ) - len (code_loop_footer )
305
- )
306
-
307
- code_loop_body = (code_loop_body_len // len (code_invoke_create )) * bytes (code_invoke_create )
308
- code = code_prefix + code_loop_header + code_loop_body + code_loop_footer
309
- assert (max_code_size - len (code_invoke_create )) < len (code ) <= max_code_size
301
+ setup = code_prepare_initcode + Op .PUSH0
310
302
311
- tx = Transaction (
312
- to = pre .deploy_contract (code = code ),
313
- data = tx_data ,
314
- gas_limit = gas_benchmark_value ,
315
- sender = pre .fund_eoa (),
316
- )
303
+ generator = JumpLoopGenerator (setup = setup , attack_block = attack_block , cleanup = Bytecode ())
304
+ generator .deploy_contracts (pre , fork )
305
+ tx = generator .generate_transaction (pre , gas_benchmark_value , fork )
306
+ tx .data = Bytes (tx_data )
317
307
318
- state_test (
308
+ benchmark_test (
319
309
pre = pre ,
320
310
post = {},
321
311
tx = tx ,
0 commit comments