Skip to content

test_worst_tload()

Documentation for tests/benchmark/test_worst_compute.py::test_worst_tload@v5.0.0.

Generate fixtures for these test cases for Osaka with:

fill -v tests/benchmark/test_worst_compute.py::test_worst_tload --fork Osaka

Test running a block with as many TLOAD calls as possible.

Source code in tests/benchmark/test_worst_compute.py
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
@pytest.mark.valid_from("Cancun")
# `key_mut` indicates the key isn't fixed.
@pytest.mark.parametrize("key_mut", [True, False])
# `val_mut` indicates that at the end of each big-loop, the value of the target key changes.
@pytest.mark.parametrize("val_mut", [True, False])
def test_worst_tload(
    state_test: StateTestFiller,
    fork: Fork,
    pre: Alloc,
    key_mut: bool,
    val_mut: bool,
    gas_benchmark_value: int,
):
    """Test running a block with as many TLOAD calls as possible."""
    max_code_size = fork.max_code_size()

    start_key = 41
    code_key_mut = Bytecode()
    code_val_mut = Bytecode()
    if key_mut and val_mut:
        code_prefix = Op.PUSH1(start_key) + Op.JUMPDEST
        loop_iter = Op.POP(Op.TLOAD(Op.DUP1))
        code_key_mut = Op.POP + Op.GAS
        code_val_mut = Op.TSTORE(Op.DUP2, Op.GAS)
    if key_mut and not val_mut:
        code_prefix = Op.JUMPDEST
        loop_iter = Op.POP(Op.TLOAD(Op.GAS))
    if not key_mut and val_mut:
        code_prefix = Op.JUMPDEST
        loop_iter = Op.POP(Op.TLOAD(Op.CALLVALUE))
        code_val_mut = Op.TSTORE(Op.CALLVALUE, Op.GAS)  # CALLVALUE configured in the tx
    if not key_mut and not val_mut:
        code_prefix = Op.JUMPDEST
        loop_iter = Op.POP(Op.TLOAD(Op.CALLVALUE))

    code_suffix = code_key_mut + code_val_mut + Op.JUMP(len(code_prefix) - 1)

    code_body_len = (max_code_size - len(code_prefix) - len(code_suffix)) // len(loop_iter)
    code_body = loop_iter * code_body_len
    code = code_prefix + code_body + code_suffix
    assert len(code) <= max_code_size

    tx = Transaction(
        to=pre.deploy_contract(code),
        gas_limit=gas_benchmark_value,
        sender=pre.fund_eoa(),
        value=start_key if not key_mut and val_mut else 0,
    )

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

Parametrized Test Cases

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

Test ID (Abbreviated) val_mut key_mut
...fork_Cancun-state_test-val_mut_True-key_mut_True True True
...fork_Cancun-state_test-val_mut_True-key_mut_False True False
...fork_Cancun-state_test-val_mut_False-key_mut_True False True
...fork_Cancun-state_test-val_mut_False-key_mut_False False False
...fork_Cancun-blockchain_test_from_state_test-val_mut_True-key_mut_True True True
...fork_Cancun-blockchain_test_from_state_test-val_mut_True-key_mut_False True False
...fork_Cancun-blockchain_test_from_state_test-val_mut_False-key_mut_True False True
...fork_Cancun-blockchain_test_from_state_test-val_mut_False-key_mut_False False False
...fork_Prague-state_test-val_mut_True-key_mut_True True True
...fork_Prague-state_test-val_mut_True-key_mut_False True False
...fork_Prague-state_test-val_mut_False-key_mut_True False True
...fork_Prague-state_test-val_mut_False-key_mut_False False False
...fork_Prague-blockchain_test_from_state_test-val_mut_True-key_mut_True True True
...fork_Prague-blockchain_test_from_state_test-val_mut_True-key_mut_False True False
...fork_Prague-blockchain_test_from_state_test-val_mut_False-key_mut_True False True
...fork_Prague-blockchain_test_from_state_test-val_mut_False-key_mut_False False False
...fork_Osaka-state_test-val_mut_True-key_mut_True True True
...fork_Osaka-state_test-val_mut_True-key_mut_False True False
...fork_Osaka-state_test-val_mut_False-key_mut_True False True
...fork_Osaka-state_test-val_mut_False-key_mut_False False False
...fork_Osaka-blockchain_test_from_state_test-val_mut_True-key_mut_True True True
...fork_Osaka-blockchain_test_from_state_test-val_mut_True-key_mut_False True False
...fork_Osaka-blockchain_test_from_state_test-val_mut_False-key_mut_True False True
...fork_Osaka-blockchain_test_from_state_test-val_mut_False-key_mut_False False False