Skip to content

test_worst_tload()

Documentation for tests/benchmark/test_worst_compute.py::test_worst_tload@0f7c73a7.

Generate fixtures for these test cases for Prague with:

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

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

Source code in tests/benchmark/test_worst_compute.py
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
@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