Skip to content

test_worst_tload()

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

Generate fixtures for these test cases for Osaka with:

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

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

Source code in tests/benchmark/test_worst_compute.py
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
@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_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