Skip to content

Commit 61d6357

Browse files
LouisTsai-CsieCarsons-Eels
authored andcommitted
refactor(zkevm): optimize the zero param opcode case (ethereum#1737)
* refactor: optimize the zero param opcode case * fix(tests): correct parameter naming in worst compute test * refactor: optimize gas cost for staticcall loop
1 parent 0517b99 commit 61d6357

File tree

1 file changed

+10
-9
lines changed

1 file changed

+10
-9
lines changed

tests/zkevm/test_worst_compute.py

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
REFERENCE_SPEC_GIT_PATH = "TODO"
4343
REFERENCE_SPEC_VERSION = "TODO"
4444

45+
MAX_STACK_HEIGHT = 1024
4546
KECCAK_RATE = 136
4647

4748

@@ -84,22 +85,22 @@ def make_dup(index: int) -> Opcode:
8485
def test_worst_zero_param(
8586
state_test: StateTestFiller,
8687
pre: Alloc,
87-
fork: Fork,
8888
opcode: Op,
89+
fork: Fork,
8990
):
9091
"""Test running a block with as many zero-parameter opcodes as possible."""
9192
env = Environment()
92-
max_code_size = fork.max_code_size()
9393

94-
code_prefix = Op.JUMPDEST
95-
iter_loop = Op.POP(opcode)
96-
code_suffix = Op.PUSH0 + Op.JUMP
97-
code_iter_len = (max_code_size - len(code_prefix) - len(code_suffix)) // len(iter_loop)
98-
code = code_prefix + iter_loop * code_iter_len + code_suffix
99-
assert len(code) <= max_code_size
94+
opcode_sequence = opcode * MAX_STACK_HEIGHT
95+
target_contract_address = pre.deploy_contract(code=opcode_sequence)
96+
97+
calldata = Bytecode()
98+
attack_block = Op.POP(Op.STATICCALL(Op.GAS, target_contract_address, 0, 0, 0, 0))
99+
code = code_loop_precompile_call(calldata, attack_block, fork)
100+
code_address = pre.deploy_contract(code=code)
100101

101102
tx = Transaction(
102-
to=pre.deploy_contract(code=bytes(code)),
103+
to=code_address,
103104
gas_limit=env.gas_limit,
104105
sender=pre.fund_eoa(),
105106
)

0 commit comments

Comments
 (0)