Skip to content

test_worst_tload()

Documentation for tests/zkevm/test_worst_compute.py::test_worst_tload@64f949d0.

Generate fixtures for these test cases for Prague with:

fill -v tests/zkevm/test_worst_compute.py::test_worst_tload --fork Prague

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

Source code in tests/zkevm/test_worst_compute.py
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
@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,
):
    """Test running a block with as many TLOAD calls as possible."""
    env = Environment()
    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=env.gas_limit,
        sender=pre.fund_eoa(),
        value=start_key if not key_mut and val_mut else 0,
    )

    state_test(
        env=env,
        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