Skip to content

test_worst_calldataload()

Documentation for tests/benchmark/test_worst_compute.py::test_worst_calldataload@v5.1.0.

Generate fixtures for these test cases for Osaka with:

fill -v tests/benchmark/test_worst_compute.py::test_worst_calldataload -m benchmark

Test running a block with as many CALLDATALOAD as possible.

Source code in tests/benchmark/test_worst_compute.py
2705
2706
2707
2708
2709
2710
2711
2712
2713
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723
2724
2725
2726
2727
2728
2729
2730
2731
2732
2733
2734
2735
2736
2737
2738
2739
2740
2741
2742
@pytest.mark.parametrize(
    "calldata",
    [
        pytest.param(b"", id="empty"),
        pytest.param(b"\x00", id="zero-loop"),
        pytest.param(b"\x00" * 31 + b"\x20", id="one-loop"),
    ],
)
def test_worst_calldataload(
    state_test: StateTestFiller,
    pre: Alloc,
    fork: Fork,
    calldata: bytes,
    gas_benchmark_value: int,
):
    """Test running a block with as many CALLDATALOAD as possible."""
    max_code_size = fork.max_code_size()

    code_prefix = Op.PUSH0 + Op.JUMPDEST
    code_suffix = Op.PUSH1(1) + Op.JUMP
    code_body_len = max_code_size - len(code_prefix) - len(code_suffix)
    code_loop_iter = Op.CALLDATALOAD
    code_body = code_loop_iter * (code_body_len // len(code_loop_iter))
    code = code_prefix + code_body + code_suffix
    assert len(code) <= max_code_size

    tx = Transaction(
        to=pre.deploy_contract(code=code),
        data=calldata,
        gas_limit=gas_benchmark_value,
        sender=pre.fund_eoa(),
    )

    state_test(
        pre=pre,
        post={},
        tx=tx,
    )

Parametrized Test Cases

The interactive table below is also available as a standalone page.

Test ID (Abbreviated) calldata
...fork_Prague-state_test-empty
...fork_Prague-state_test-zero-loop 00
...fork_Prague-state_test-one-loop 00000000000000000000000000000000 00000000000000000000000000000020
...fork_Prague-blockchain_test_from_state_test-empty
...fork_Prague-blockchain_test_from_state_test-zero-loop 00
...fork_Prague-blockchain_test_from_state_test-one-loop 00000000000000000000000000000000 00000000000000000000000000000020
...fork_Osaka-state_test-empty
...fork_Osaka-state_test-zero-loop 00
...fork_Osaka-state_test-one-loop 00000000000000000000000000000000 00000000000000000000000000000020
...fork_Osaka-blockchain_test_from_state_test-empty
...fork_Osaka-blockchain_test_from_state_test-zero-loop 00
...fork_Osaka-blockchain_test_from_state_test-one-loop 00000000000000000000000000000000 00000000000000000000000000000020