Skip to content

Commit c7dd3dd

Browse files
committed
zkevm: calldataload
Signed-off-by: Ignacio Hagopian <jsign.uy@gmail.com>
1 parent 3810d22 commit c7dd3dd

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed

tests/zkevm/test_worst_compute.py

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
BlockchainTestFiller,
2020
Bytecode,
2121
Environment,
22+
StateTestFiller,
2223
Transaction,
2324
)
2425
from ethereum_test_tools.code.generators import While
@@ -955,3 +956,40 @@ def test_empty_block(
955956
post={},
956957
blocks=[Block(txs=[])],
957958
)
959+
960+
961+
@pytest.mark.valid_from("Cancun")
962+
@pytest.mark.parametrize(
963+
"empty_calldata",
964+
[False, True],
965+
)
966+
def test_worst_calldataload(
967+
state_test: StateTestFiller,
968+
pre: Alloc,
969+
fork: Fork,
970+
empty_calldata: bool,
971+
):
972+
"""Test running a block with as many CALLDATALOAD as possible."""
973+
env = Environment()
974+
975+
code_prefix = Op.JUMPDEST
976+
code_suffix = Op.PUSH0 + Op.JUMP
977+
code_body_len = MAX_CODE_SIZE - len(code_prefix) - len(code_suffix)
978+
code_loop_iter = Op.POP(Op.PUSH0 + Op.CALLDATALOAD)
979+
code_body = code_loop_iter * (code_body_len // len(code_loop_iter))
980+
code = code_prefix + code_body + code_suffix
981+
assert len(code) == MAX_CODE_SIZE
982+
983+
tx = Transaction(
984+
to=pre.deploy_contract(code=code),
985+
data=[] if empty_calldata else [0x42] * 32,
986+
gas_limit=env.gas_limit,
987+
sender=pre.fund_eoa(),
988+
)
989+
990+
state_test(
991+
env=env,
992+
pre=pre,
993+
post={},
994+
tx=tx,
995+
)

0 commit comments

Comments
 (0)