Skip to content

Commit 0988892

Browse files
feat(tests): add worst case tests for PUSH opcodes (#1762)
* feat(tests): add worst case tests for PUSH opcodes * refactor(tests): simplify push opcode parameterization * refactor(tests): use dynamic max stack height
1 parent 6490fb4 commit 0988892

File tree

1 file changed

+71
-0
lines changed

1 file changed

+71
-0
lines changed

tests/zkevm/test_worst_compute.py

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1869,3 +1869,74 @@ def test_worst_dup(
18691869
post={},
18701870
tx=tx,
18711871
)
1872+
1873+
1874+
@pytest.mark.parametrize(
1875+
"opcode",
1876+
[
1877+
pytest.param(Op.PUSH0),
1878+
pytest.param(Op.PUSH1),
1879+
pytest.param(Op.PUSH2),
1880+
pytest.param(Op.PUSH3),
1881+
pytest.param(Op.PUSH4),
1882+
pytest.param(Op.PUSH5),
1883+
pytest.param(Op.PUSH6),
1884+
pytest.param(Op.PUSH7),
1885+
pytest.param(Op.PUSH8),
1886+
pytest.param(Op.PUSH9),
1887+
pytest.param(Op.PUSH10),
1888+
pytest.param(Op.PUSH11),
1889+
pytest.param(Op.PUSH12),
1890+
pytest.param(Op.PUSH13),
1891+
pytest.param(Op.PUSH14),
1892+
pytest.param(Op.PUSH15),
1893+
pytest.param(Op.PUSH16),
1894+
pytest.param(Op.PUSH17),
1895+
pytest.param(Op.PUSH18),
1896+
pytest.param(Op.PUSH19),
1897+
pytest.param(Op.PUSH20),
1898+
pytest.param(Op.PUSH21),
1899+
pytest.param(Op.PUSH22),
1900+
pytest.param(Op.PUSH23),
1901+
pytest.param(Op.PUSH24),
1902+
pytest.param(Op.PUSH25),
1903+
pytest.param(Op.PUSH26),
1904+
pytest.param(Op.PUSH27),
1905+
pytest.param(Op.PUSH28),
1906+
pytest.param(Op.PUSH29),
1907+
pytest.param(Op.PUSH30),
1908+
pytest.param(Op.PUSH31),
1909+
pytest.param(Op.PUSH32),
1910+
],
1911+
)
1912+
def test_worst_push(
1913+
state_test: StateTestFiller,
1914+
pre: Alloc,
1915+
fork: Fork,
1916+
opcode: Op,
1917+
):
1918+
"""Test running a block with as many PUSH as possible."""
1919+
env = Environment()
1920+
1921+
op = opcode[1] if opcode.has_data_portion() else opcode
1922+
opcode_sequence = op * fork.max_stack_height()
1923+
target_contract_address = pre.deploy_contract(code=opcode_sequence)
1924+
1925+
calldata = Bytecode()
1926+
attack_block = Op.POP(Op.STATICCALL(Op.GAS, target_contract_address, 0, 0, 0, 0))
1927+
1928+
code = code_loop_precompile_call(calldata, attack_block, fork)
1929+
code_address = pre.deploy_contract(code=code)
1930+
1931+
tx = Transaction(
1932+
to=code_address,
1933+
gas_limit=env.gas_limit,
1934+
sender=pre.fund_eoa(),
1935+
)
1936+
1937+
state_test(
1938+
env=env,
1939+
pre=pre,
1940+
post={},
1941+
tx=tx,
1942+
)

0 commit comments

Comments
 (0)