Skip to content

Commit 6ed3832

Browse files
authored
feat(tests/zkevm): add CALLDATALOAD benchmark (#1658)
* zkevm: calldataload Signed-off-by: Ignacio Hagopian <jsign.uy@gmail.com> * fix assertion Signed-off-by: Ignacio Hagopian <jsign.uy@gmail.com> * avoid POPs * rebase Signed-off-by: Ignacio Hagopian <jsign.uy@gmail.com> * generalize calldata argument Signed-off-by: Ignacio Hagopian <jsign.uy@gmail.com> --------- Signed-off-by: Ignacio Hagopian <jsign.uy@gmail.com>
1 parent 41a30ca commit 6ed3832

File tree

1 file changed

+40
-0
lines changed

1 file changed

+40
-0
lines changed

tests/zkevm/test_worst_compute.py

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1159,3 +1159,43 @@ def _generate_bn128_pairs(n: int, seed: int = 0):
11591159
calldata = Bytes(calldata + pair_calldata)
11601160

11611161
return calldata
1162+
1163+
1164+
@pytest.mark.parametrize(
1165+
"calldata",
1166+
[
1167+
pytest.param(b"", id="empty"),
1168+
pytest.param(b"\x00", id="zero-loop"),
1169+
pytest.param(b"\x00" * 31 + b"\x20", id="one-loop"),
1170+
],
1171+
)
1172+
def test_worst_calldataload(
1173+
state_test: StateTestFiller,
1174+
pre: Alloc,
1175+
fork: Fork,
1176+
calldata: bytes,
1177+
):
1178+
"""Test running a block with as many CALLDATALOAD as possible."""
1179+
env = Environment()
1180+
1181+
code_prefix = Op.PUSH0 + Op.JUMPDEST
1182+
code_suffix = Op.PUSH1(1) + Op.JUMP
1183+
code_body_len = MAX_CODE_SIZE - len(code_prefix) - len(code_suffix)
1184+
code_loop_iter = Op.CALLDATALOAD
1185+
code_body = code_loop_iter * (code_body_len // len(code_loop_iter))
1186+
code = code_prefix + code_body + code_suffix
1187+
assert len(code) <= MAX_CODE_SIZE
1188+
1189+
tx = Transaction(
1190+
to=pre.deploy_contract(code=code),
1191+
data=calldata,
1192+
gas_limit=env.gas_limit,
1193+
sender=pre.fund_eoa(),
1194+
)
1195+
1196+
state_test(
1197+
env=env,
1198+
pre=pre,
1199+
post={},
1200+
tx=tx,
1201+
)

0 commit comments

Comments
 (0)