Skip to content

Commit ee857db

Browse files
authored
feat(tests): add benchmarks with mass unop opcodes (#1620)
This adds the benchmarks for EVM execution focused on unary instructions (takes one value, produces one). The benchmark has simple structure: the contract code is the infinite loop filled up to the code size limit with the parametrized opcode.
1 parent 709b20b commit ee857db

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

tests/zkevm/test_worst_compute.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -519,3 +519,37 @@ def test_worst_binop_simple(
519519
post={},
520520
blocks=[Block(txs=[tx])],
521521
)
522+
523+
524+
@pytest.mark.valid_from("Cancun")
525+
@pytest.mark.parametrize("opcode", [Op.ISZERO, Op.NOT])
526+
def test_worst_unop(
527+
blockchain_test: BlockchainTestFiller,
528+
pre: Alloc,
529+
opcode: Op,
530+
):
531+
"""
532+
Test running a block with as many unary instructions (takes one arg, produces one value)
533+
as possible.
534+
"""
535+
env = Environment()
536+
537+
code_prefix = Op.JUMPDEST + Op.PUSH0 # Start with the arg 0.
538+
code_suffix = Op.POP + Op.PUSH0 + Op.JUMP
539+
code_body_len = MAX_CODE_SIZE - len(code_prefix) - len(code_suffix)
540+
code_body = opcode * code_body_len
541+
code = code_prefix + code_body + code_suffix
542+
assert len(code) == MAX_CODE_SIZE
543+
544+
tx = Transaction(
545+
to=pre.deploy_contract(code=code),
546+
gas_limit=env.gas_limit,
547+
sender=pre.fund_eoa(),
548+
)
549+
550+
blockchain_test(
551+
env=env,
552+
pre=pre,
553+
post={},
554+
blocks=[Block(txs=[tx])],
555+
)

0 commit comments

Comments
 (0)