@@ -1295,15 +1295,23 @@ def test_worst_blobhash(
1295
1295
"""Test running a block with as many BLOBHASH instructions as possible."""
1296
1296
env = Environment ()
1297
1297
max_code_size = fork .max_code_size ()
1298
+ max_stack_height = fork .max_stack_height ()
1298
1299
1299
- code_prefix = Op .PUSH1 (blob_index ) + Op .JUMPDEST
1300
- code_suffix = Op .JUMP (len (code_prefix ) - 1 )
1301
- loop_iter = Op .POP (Op .BLOBHASH (Op .DUP1 ))
1302
- code_body_len = (max_code_size - len (code_prefix ) - len (code_suffix )) // len (loop_iter )
1303
- code_body = loop_iter * code_body_len
1304
- code = code_prefix + code_body + code_suffix
1300
+ # Contract that contains a collection of BLOBHASH instructions.
1301
+ opcode_sequence = Op .BLOBHASH (blob_index ) * max_stack_height
1302
+ assert len (opcode_sequence ) <= max_code_size
1303
+
1304
+ target_contract_address = pre .deploy_contract (code = opcode_sequence )
1305
+
1306
+ # Contract that contains a loop of STATICCALLs to the target contract.
1307
+ calldata = Bytecode ()
1308
+ attack_block = Op .POP (Op .STATICCALL (Op .GAS , target_contract_address , 0 , 0 , 0 , 0 ))
1309
+ code = code_loop_precompile_call (calldata , attack_block , fork )
1305
1310
assert len (code ) <= max_code_size
1306
1311
1312
+ code_address = pre .deploy_contract (code = code )
1313
+
1314
+ # Create blob transaction if blobs are present.
1307
1315
tx_type = TransactionType .LEGACY
1308
1316
blob_versioned_hashes = None
1309
1317
max_fee_per_blob_gas = None
@@ -1317,7 +1325,7 @@ def test_worst_blobhash(
1317
1325
1318
1326
tx = Transaction (
1319
1327
ty = tx_type ,
1320
- to = pre . deploy_contract ( code = code ) ,
1328
+ to = code_address ,
1321
1329
gas_limit = env .gas_limit ,
1322
1330
max_fee_per_blob_gas = max_fee_per_blob_gas ,
1323
1331
blob_versioned_hashes = blob_versioned_hashes ,
0 commit comments