Skip to content

Commit ff3440e

Browse files
refactor(tests): add distinct offset and value
1 parent 6ed4bcd commit ff3440e

File tree

1 file changed

+30
-9
lines changed

1 file changed

+30
-9
lines changed

tests/zkevm/test_worst_compute.py

Lines changed: 30 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1715,22 +1715,43 @@ def test_worst_calldataload(
17151715
pytest.param(Op.LOG4, id="log4"),
17161716
],
17171717
)
1718-
def test_worst_log_opcodes(state_test: StateTestFiller, pre: Alloc, fork: Fork, opcode: Opcode):
1718+
@pytest.mark.parametrize("empty_value", [True, False])
1719+
@pytest.mark.parametrize("offset", [0, 1, 2, 3, 4])
1720+
def test_worst_log_opcodes(
1721+
state_test: StateTestFiller,
1722+
pre: Alloc,
1723+
fork: Fork,
1724+
opcode: Opcode,
1725+
empty_value: bool,
1726+
offset: int,
1727+
):
17191728
"""Test running a block with as many LOG opcodes as possible."""
17201729
env = Environment()
1721-
max_code_size = 20
1730+
max_code_size = fork.max_code_size()
17221731

1723-
iter_code = Op.PUSH0 * len(opcode.kwargs) + opcode
1724-
code_prefix = Op.JUMPDEST
1725-
code_suffix = Op.PUSH0 + Op.JUMP
1732+
push_value = Op.PUSH0 if empty_value else Op.PUSH32(0xFF)
17261733

1727-
iter_count = (max_code_size - len(code_prefix) - len(code_suffix)) // len(iter_code)
1734+
topic_count = len(opcode.kwargs) - 2
17281735

1729-
code = code_prefix + iter_code * iter_count + code_suffix
1730-
assert len(code) <= max_code_size
1736+
code_sequence = (
1737+
push_value * topic_count # Push topics
1738+
+ Op.PUSH32(2**offset) # Push memory size
1739+
+ Op.PUSH32(10**offset) # Push memory offset
1740+
+ opcode # Add the LOG opcode
1741+
)
17311742

1743+
# Calculate how many times we can repeat the sequence within code size limits
1744+
code_prefix = Op.MSTORE(10**offset, push_value) + Op.JUMPDEST
1745+
code_suffix = Op.PUSH1(len(code_prefix)) + Op.JUMP
1746+
max_iterations = (max_code_size - len(code_prefix) - len(code_suffix)) // len(code_sequence)
1747+
1748+
# Build the final code
1749+
deployed_code = code_prefix + (code_sequence * max_iterations) + code_suffix
1750+
assert len(deployed_code) <= max_code_size
1751+
1752+
# Create and execute the transaction
17321753
tx = Transaction(
1733-
to=pre.deploy_contract(code=code),
1754+
to=pre.deploy_contract(code=deployed_code),
17341755
gas_limit=env.gas_limit,
17351756
sender=pre.fund_eoa(),
17361757
)

0 commit comments

Comments
 (0)