Skip to content

Commit 5e2c0a8

Browse files
LouisTsai-CsieCarsons-Eels
authored andcommitted
feat(zkevm/test): add worst case test for multiple DUP opcodes (ethereum#1767)
* feat(zkevm/test): add worst case test for multiple DUP opcodes * fix(tests/zkevm): correct data type assignment * fix(tests/zkevm): update max stack height retrieval
1 parent 984143b commit 5e2c0a8

File tree

1 file changed

+56
-0
lines changed

1 file changed

+56
-0
lines changed

tests/zkevm/test_worst_compute.py

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1827,3 +1827,59 @@ def test_worst_swap(
18271827
post={},
18281828
tx=tx,
18291829
)
1830+
1831+
1832+
@pytest.mark.parametrize(
1833+
"opcode",
1834+
[
1835+
pytest.param(Op.DUP1),
1836+
pytest.param(Op.DUP2),
1837+
pytest.param(Op.DUP3),
1838+
pytest.param(Op.DUP4),
1839+
pytest.param(Op.DUP5),
1840+
pytest.param(Op.DUP6),
1841+
pytest.param(Op.DUP7),
1842+
pytest.param(Op.DUP8),
1843+
pytest.param(Op.DUP9),
1844+
pytest.param(Op.DUP10),
1845+
pytest.param(Op.DUP11),
1846+
pytest.param(Op.DUP12),
1847+
pytest.param(Op.DUP13),
1848+
pytest.param(Op.DUP14),
1849+
pytest.param(Op.DUP15),
1850+
pytest.param(Op.DUP16),
1851+
],
1852+
)
1853+
def test_worst_dup(
1854+
state_test: StateTestFiller,
1855+
pre: Alloc,
1856+
fork: Fork,
1857+
opcode: Op,
1858+
):
1859+
"""Test running a block with as many DUP as possible."""
1860+
env = Environment()
1861+
max_stack_height = fork.max_stack_height()
1862+
1863+
min_stack_height = opcode.min_stack_height
1864+
code_prefix = Op.PUSH0 * min_stack_height
1865+
opcode_sequence = opcode * (max_stack_height - min_stack_height)
1866+
target_contract_address = pre.deploy_contract(code=code_prefix + opcode_sequence)
1867+
1868+
calldata = Bytecode()
1869+
attack_block = Op.POP(Op.STATICCALL(Op.GAS, target_contract_address, 0, 0, 0, 0))
1870+
1871+
code = code_loop_precompile_call(calldata, attack_block, fork)
1872+
code_address = pre.deploy_contract(code=code)
1873+
1874+
tx = Transaction(
1875+
to=code_address,
1876+
gas_limit=env.gas_limit,
1877+
sender=pre.fund_eoa(),
1878+
)
1879+
1880+
state_test(
1881+
env=env,
1882+
pre=pre,
1883+
post={},
1884+
tx=tx,
1885+
)

0 commit comments

Comments
 (0)