Skip to content

Commit 58df655

Browse files
LouisTsai-CsieCarsons-Eels
authored andcommitted
feat(zkevm/tests): add worst case tests for SWAP opcodes (ethereum#1769)
1 parent c54c1cf commit 58df655

File tree

1 file changed

+51
-0
lines changed

1 file changed

+51
-0
lines changed

tests/zkevm/test_worst_compute.py

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1706,3 +1706,54 @@ def test_worst_calldataload(
17061706
post={},
17071707
tx=tx,
17081708
)
1709+
1710+
1711+
@pytest.mark.parametrize(
1712+
"opcode",
1713+
[
1714+
Op.SWAP1,
1715+
Op.SWAP2,
1716+
Op.SWAP3,
1717+
Op.SWAP4,
1718+
Op.SWAP5,
1719+
Op.SWAP6,
1720+
Op.SWAP7,
1721+
Op.SWAP8,
1722+
Op.SWAP9,
1723+
Op.SWAP10,
1724+
Op.SWAP11,
1725+
Op.SWAP12,
1726+
Op.SWAP13,
1727+
Op.SWAP14,
1728+
Op.SWAP15,
1729+
Op.SWAP16,
1730+
],
1731+
)
1732+
def test_worst_swap(
1733+
state_test: StateTestFiller,
1734+
pre: Alloc,
1735+
fork: Fork,
1736+
opcode: Opcode,
1737+
):
1738+
"""Test running a block with as many SWAP as possible."""
1739+
env = Environment()
1740+
max_code_size = fork.max_code_size()
1741+
1742+
code_prefix = Op.JUMPDEST + Op.PUSH0 * opcode.min_stack_height
1743+
code_suffix = Op.PUSH0 + Op.JUMP
1744+
opcode_sequence = opcode * (max_code_size - len(code_prefix) - len(code_suffix))
1745+
code = code_prefix + opcode_sequence + code_suffix
1746+
assert len(code) <= max_code_size
1747+
1748+
tx = Transaction(
1749+
to=pre.deploy_contract(code=code),
1750+
gas_limit=env.gas_limit,
1751+
sender=pre.fund_eoa(),
1752+
)
1753+
1754+
state_test(
1755+
env=env,
1756+
pre=pre,
1757+
post={},
1758+
tx=tx,
1759+
)

0 commit comments

Comments
 (0)