Skip to content

Commit 7f1a99f

Browse files
feat(benchmark): add jumpi-intense test case (#1693)
* feat: add zkevm jumpi-intense op * refactor: update jumpi fallthrough case * feat(tests): add jumpi intensive contract test * chore: fix typo * refactor: optimize jumpi-intensive test case * refactor(tests): replace hardcoded value with fork specific variable * Apply suggestions from code review --------- Co-authored-by: Mario Vega <[email protected]>
1 parent 0fdd974 commit 7f1a99f

File tree

1 file changed

+67
-0
lines changed

1 file changed

+67
-0
lines changed

tests/benchmark/test_worst_compute.py

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1159,6 +1159,73 @@ def test_worst_jumps(state_test: StateTestFiller, pre: Alloc):
11591159
)
11601160

11611161

1162+
@pytest.mark.zkevm
1163+
@pytest.mark.valid_from("Cancun")
1164+
@pytest.mark.slow
1165+
def test_worst_jumpi_fallthrough(
1166+
state_test: StateTestFiller,
1167+
pre: Alloc,
1168+
fork: Fork,
1169+
):
1170+
"""Test running a JUMPI-intensive contract with fallthrough."""
1171+
env = Environment()
1172+
max_code_size = fork.max_code_size()
1173+
1174+
def jumpi_seq():
1175+
return Op.JUMPI(Op.PUSH0, Op.PUSH0)
1176+
1177+
prefix_seq = Op.JUMPDEST
1178+
suffix_seq = Op.JUMP(Op.PUSH0)
1179+
bytes_per_seq = len(jumpi_seq())
1180+
seqs_per_call = (max_code_size - len(prefix_seq) - len(suffix_seq)) // bytes_per_seq
1181+
1182+
# Create and deploy the jumpi-intensive contract
1183+
jumpis_code = prefix_seq + jumpi_seq() * seqs_per_call + suffix_seq
1184+
assert len(jumpis_code) <= max_code_size
1185+
1186+
jumpis_address = pre.deploy_contract(code=bytes(jumpis_code))
1187+
1188+
tx = Transaction(
1189+
to=jumpis_address,
1190+
gas_limit=env.gas_limit,
1191+
sender=pre.fund_eoa(),
1192+
)
1193+
1194+
state_test(
1195+
env=env,
1196+
pre=pre,
1197+
post={},
1198+
tx=tx,
1199+
)
1200+
1201+
1202+
@pytest.mark.zkevm
1203+
@pytest.mark.valid_from("Cancun")
1204+
@pytest.mark.slow
1205+
def test_worst_jumpis(
1206+
state_test: StateTestFiller,
1207+
pre: Alloc,
1208+
):
1209+
"""Test running a JUMPI-intensive contract."""
1210+
env = Environment()
1211+
1212+
jumpi_code = Op.JUMPDEST + Op.JUMPI(Op.PUSH0, Op.NUMBER)
1213+
jumpi_address = pre.deploy_contract(jumpi_code)
1214+
1215+
tx = Transaction(
1216+
to=jumpi_address,
1217+
gas_limit=env.gas_limit,
1218+
sender=pre.fund_eoa(),
1219+
)
1220+
1221+
state_test(
1222+
env=env,
1223+
pre=pre,
1224+
post={},
1225+
tx=tx,
1226+
)
1227+
1228+
11621229
@pytest.mark.valid_from("Cancun")
11631230
@pytest.mark.slow
11641231
def test_worst_jumpdests(state_test: StateTestFiller, pre: Alloc, fork: Fork):

0 commit comments

Comments
 (0)