Skip to content

Commit 8b5fedc

Browse files
refactor(zkevm): refactor blobhash opcode worst case (ethereum#1783)
* refactor(zkevm): refactor blobhash opcode worst case * refactor(tests): optimize blobhash test
1 parent 64f949d commit 8b5fedc

File tree

1 file changed

+15
-7
lines changed

1 file changed

+15
-7
lines changed

tests/zkevm/test_worst_compute.py

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1295,15 +1295,23 @@ def test_worst_blobhash(
12951295
"""Test running a block with as many BLOBHASH instructions as possible."""
12961296
env = Environment()
12971297
max_code_size = fork.max_code_size()
1298+
max_stack_height = fork.max_stack_height()
12981299

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)
13051310
assert len(code) <= max_code_size
13061311

1312+
code_address = pre.deploy_contract(code=code)
1313+
1314+
# Create blob transaction if blobs are present.
13071315
tx_type = TransactionType.LEGACY
13081316
blob_versioned_hashes = None
13091317
max_fee_per_blob_gas = None
@@ -1317,7 +1325,7 @@ def test_worst_blobhash(
13171325

13181326
tx = Transaction(
13191327
ty=tx_type,
1320-
to=pre.deploy_contract(code=code),
1328+
to=code_address,
13211329
gas_limit=env.gas_limit,
13221330
max_fee_per_blob_gas=max_fee_per_blob_gas,
13231331
blob_versioned_hashes=blob_versioned_hashes,

0 commit comments

Comments
 (0)