Skip to content

test_worst_memory_access()

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

Generate fixtures for these test cases for Osaka with:

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

Test running a block with as many memory access instructions as possible.

Source code in tests/benchmark/test_worst_compute.py
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
@pytest.mark.parametrize("opcode", [Op.MLOAD, Op.MSTORE, Op.MSTORE8])
@pytest.mark.parametrize("offset", [0, 1, 31])
@pytest.mark.parametrize("offset_initialized", [True, False])
@pytest.mark.parametrize("big_memory_expansion", [True, False])
def test_worst_memory_access(
    state_test: StateTestFiller,
    pre: Alloc,
    fork: Fork,
    opcode: Op,
    offset: int,
    offset_initialized: bool,
    big_memory_expansion: bool,
    gas_benchmark_value: int,
):
    """Test running a block with as many memory access instructions as possible."""
    max_code_size = fork.max_code_size()

    mem_exp_code = Op.MSTORE8(10 * 1024, 1) if big_memory_expansion else Bytecode()
    offset_set_code = Op.MSTORE(offset, 43) if offset_initialized else Bytecode()
    code_prefix = mem_exp_code + offset_set_code + Op.PUSH1(42) + Op.PUSH1(offset) + Op.JUMPDEST

    code_suffix = Op.JUMP(len(code_prefix) - 1)

    loop_iter = Op.POP(Op.MLOAD(Op.DUP1)) if opcode == Op.MLOAD else opcode(Op.DUP2, Op.DUP2)

    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=code),
        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) big_memory_expansion offset_initialized offset opcode
...fork_Prague-state_test-big_memory_expansion_True-offset_initialized_True-offset_0-opcode_MLOAD True True 0 MLOAD
...fork_Prague-state_test-big_memory_expansion_True-offset_initialized_True-offset_0-opcode_MSTORE True True 0 MSTORE
...fork_Prague-state_test-big_memory_expansion_True-offset_initialized_True-offset_0-opcode_MSTORE8 True True 0 MSTORE8
...fork_Prague-state_test-big_memory_expansion_True-offset_initialized_True-offset_1-opcode_MLOAD True True 1 MLOAD
...fork_Prague-state_test-big_memory_expansion_True-offset_initialized_True-offset_1-opcode_MSTORE True True 1 MSTORE
...fork_Prague-state_test-big_memory_expansion_True-offset_initialized_True-offset_1-opcode_MSTORE8 True True 1 MSTORE8
...fork_Prague-state_test-big_memory_expansion_True-offset_initialized_True-offset_31-opcode_MLOAD True True 31 MLOAD
...fork_Prague-state_test-big_memory_expansion_True-offset_initialized_True-offset_31-opcode_MSTORE True True 31 MSTORE
...fork_Prague-state_test-big_memory_expansion_True-offset_initialized_True-offset_31-opcode_MSTORE8 True True 31 MSTORE8
...fork_Prague-state_test-big_memory_expansion_True-offset_initialized_False-offset_0-opcode_MLOAD True False 0 MLOAD
...fork_Prague-state_test-big_memory_expansion_True-offset_initialized_False-offset_0-opcode_MSTORE True False 0 MSTORE
...fork_Prague-state_test-big_memory_expansion_True-offset_initialized_False-offset_0-opcode_MSTORE8 True False 0 MSTORE8
...fork_Prague-state_test-big_memory_expansion_True-offset_initialized_False-offset_1-opcode_MLOAD True False 1 MLOAD
...fork_Prague-state_test-big_memory_expansion_True-offset_initialized_False-offset_1-opcode_MSTORE True False 1 MSTORE
...fork_Prague-state_test-big_memory_expansion_True-offset_initialized_False-offset_1-opcode_MSTORE8 True False 1 MSTORE8
...fork_Prague-state_test-big_memory_expansion_True-offset_initialized_False-offset_31-opcode_MLOAD True False 31 MLOAD
...fork_Prague-state_test-big_memory_expansion_True-offset_initialized_False-offset_31-opcode_MSTORE True False 31 MSTORE
...fork_Prague-state_test-big_memory_expansion_True-offset_initialized_False-offset_31-opcode_MSTORE8 True False 31 MSTORE8
...fork_Prague-state_test-big_memory_expansion_False-offset_initialized_True-offset_0-opcode_MLOAD False True 0 MLOAD
...fork_Prague-state_test-big_memory_expansion_False-offset_initialized_True-offset_0-opcode_MSTORE False True 0 MSTORE
...fork_Prague-state_test-big_memory_expansion_False-offset_initialized_True-offset_0-opcode_MSTORE8 False True 0 MSTORE8
...fork_Prague-state_test-big_memory_expansion_False-offset_initialized_True-offset_1-opcode_MLOAD False True 1 MLOAD
...fork_Prague-state_test-big_memory_expansion_False-offset_initialized_True-offset_1-opcode_MSTORE False True 1 MSTORE
...fork_Prague-state_test-big_memory_expansion_False-offset_initialized_True-offset_1-opcode_MSTORE8 False True 1 MSTORE8
...fork_Prague-state_test-big_memory_expansion_False-offset_initialized_True-offset_31-opcode_MLOAD False True 31 MLOAD
...fork_Prague-state_test-big_memory_expansion_False-offset_initialized_True-offset_31-opcode_MSTORE False True 31 MSTORE
...fork_Prague-state_test-big_memory_expansion_False-offset_initialized_True-offset_31-opcode_MSTORE8 False True 31 MSTORE8
...fork_Prague-state_test-big_memory_expansion_False-offset_initialized_False-offset_0-opcode_MLOAD False False 0 MLOAD
...fork_Prague-state_test-big_memory_expansion_False-offset_initialized_False-offset_0-opcode_MSTORE False False 0 MSTORE
...fork_Prague-state_test-big_memory_expansion_False-offset_initialized_False-offset_0-opcode_MSTORE8 False False 0 MSTORE8
...fork_Prague-state_test-big_memory_expansion_False-offset_initialized_False-offset_1-opcode_MLOAD False False 1 MLOAD
...fork_Prague-state_test-big_memory_expansion_False-offset_initialized_False-offset_1-opcode_MSTORE False False 1 MSTORE
...fork_Prague-state_test-big_memory_expansion_False-offset_initialized_False-offset_1-opcode_MSTORE8 False False 1 MSTORE8
...fork_Prague-state_test-big_memory_expansion_False-offset_initialized_False-offset_31-opcode_MLOAD False False 31 MLOAD
...fork_Prague-state_test-big_memory_expansion_False-offset_initialized_False-offset_31-opcode_MSTORE False False 31 MSTORE
...fork_Prague-state_test-big_memory_expansion_False-offset_initialized_False-offset_31-opcode_MSTORE8 False False 31 MSTORE8
...fork_Prague-blockchain_test_from_state_test-big_memory_expansion_True-offset_initialized_True-offset_0-opcode_MLOAD True True 0 MLOAD
...fork_Prague-blockchain_test_from_state_test-big_memory_expansion_True-offset_initialized_True-offset_0-opcode_MSTORE True True 0 MSTORE
...fork_Prague-blockchain_test_from_state_test-big_memory_expansion_True-offset_initialized_True-offset_0-opcode_MSTORE8 True True 0 MSTORE8
...fork_Prague-blockchain_test_from_state_test-big_memory_expansion_True-offset_initialized_True-offset_1-opcode_MLOAD True True 1 MLOAD
...fork_Prague-blockchain_test_from_state_test-big_memory_expansion_True-offset_initialized_True-offset_1-opcode_MSTORE True True 1 MSTORE
...fork_Prague-blockchain_test_from_state_test-big_memory_expansion_True-offset_initialized_True-offset_1-opcode_MSTORE8 True True 1 MSTORE8
...fork_Prague-blockchain_test_from_state_test-big_memory_expansion_True-offset_initialized_True-offset_31-opcode_MLOAD True True 31 MLOAD
...fork_Prague-blockchain_test_from_state_test-big_memory_expansion_True-offset_initialized_True-offset_31-opcode_MSTORE True True 31 MSTORE
...fork_Prague-blockchain_test_from_state_test-big_memory_expansion_True-offset_initialized_True-offset_31-opcode_MSTORE8 True True 31 MSTORE8
...fork_Prague-blockchain_test_from_state_test-big_memory_expansion_True-offset_initialized_False-offset_0-opcode_MLOAD True False 0 MLOAD
...fork_Prague-blockchain_test_from_state_test-big_memory_expansion_True-offset_initialized_False-offset_0-opcode_MSTORE True False 0 MSTORE
...fork_Prague-blockchain_test_from_state_test-big_memory_expansion_True-offset_initialized_False-offset_0-opcode_MSTORE8 True False 0 MSTORE8
...fork_Prague-blockchain_test_from_state_test-big_memory_expansion_True-offset_initialized_False-offset_1-opcode_MLOAD True False 1 MLOAD
...fork_Prague-blockchain_test_from_state_test-big_memory_expansion_True-offset_initialized_False-offset_1-opcode_MSTORE True False 1 MSTORE
...fork_Prague-blockchain_test_from_state_test-big_memory_expansion_True-offset_initialized_False-offset_1-opcode_MSTORE8 True False 1 MSTORE8
...fork_Prague-blockchain_test_from_state_test-big_memory_expansion_True-offset_initialized_False-offset_31-opcode_MLOAD True False 31 MLOAD
...fork_Prague-blockchain_test_from_state_test-big_memory_expansion_True-offset_initialized_False-offset_31-opcode_MSTORE True False 31 MSTORE
...fork_Prague-blockchain_test_from_state_test-big_memory_expansion_True-offset_initialized_False-offset_31-opcode_MSTORE8 True False 31 MSTORE8
...fork_Prague-blockchain_test_from_state_test-big_memory_expansion_False-offset_initialized_True-offset_0-opcode_MLOAD False True 0 MLOAD
...fork_Prague-blockchain_test_from_state_test-big_memory_expansion_False-offset_initialized_True-offset_0-opcode_MSTORE False True 0 MSTORE
...fork_Prague-blockchain_test_from_state_test-big_memory_expansion_False-offset_initialized_True-offset_0-opcode_MSTORE8 False True 0 MSTORE8
...fork_Prague-blockchain_test_from_state_test-big_memory_expansion_False-offset_initialized_True-offset_1-opcode_MLOAD False True 1 MLOAD
...fork_Prague-blockchain_test_from_state_test-big_memory_expansion_False-offset_initialized_True-offset_1-opcode_MSTORE False True 1 MSTORE
...fork_Prague-blockchain_test_from_state_test-big_memory_expansion_False-offset_initialized_True-offset_1-opcode_MSTORE8 False True 1 MSTORE8
...fork_Prague-blockchain_test_from_state_test-big_memory_expansion_False-offset_initialized_True-offset_31-opcode_MLOAD False True 31 MLOAD
...fork_Prague-blockchain_test_from_state_test-big_memory_expansion_False-offset_initialized_True-offset_31-opcode_MSTORE False True 31 MSTORE
...fork_Prague-blockchain_test_from_state_test-big_memory_expansion_False-offset_initialized_True-offset_31-opcode_MSTORE8 False True 31 MSTORE8
...fork_Prague-blockchain_test_from_state_test-big_memory_expansion_False-offset_initialized_False-offset_0-opcode_MLOAD False False 0 MLOAD
...fork_Prague-blockchain_test_from_state_test-big_memory_expansion_False-offset_initialized_False-offset_0-opcode_MSTORE False False 0 MSTORE
...fork_Prague-blockchain_test_from_state_test-big_memory_expansion_False-offset_initialized_False-offset_0-opcode_MSTORE8 False False 0 MSTORE8
...fork_Prague-blockchain_test_from_state_test-big_memory_expansion_False-offset_initialized_False-offset_1-opcode_MLOAD False False 1 MLOAD
...fork_Prague-blockchain_test_from_state_test-big_memory_expansion_False-offset_initialized_False-offset_1-opcode_MSTORE False False 1 MSTORE
...fork_Prague-blockchain_test_from_state_test-big_memory_expansion_False-offset_initialized_False-offset_1-opcode_MSTORE8 False False 1 MSTORE8
...fork_Prague-blockchain_test_from_state_test-big_memory_expansion_False-offset_initialized_False-offset_31-opcode_MLOAD False False 31 MLOAD
...fork_Prague-blockchain_test_from_state_test-big_memory_expansion_False-offset_initialized_False-offset_31-opcode_MSTORE False False 31 MSTORE
...fork_Prague-blockchain_test_from_state_test-big_memory_expansion_False-offset_initialized_False-offset_31-opcode_MSTORE8 False False 31 MSTORE8
...fork_Osaka-state_test-big_memory_expansion_True-offset_initialized_True-offset_0-opcode_MLOAD True True 0 MLOAD
...fork_Osaka-state_test-big_memory_expansion_True-offset_initialized_True-offset_0-opcode_MSTORE True True 0 MSTORE
...fork_Osaka-state_test-big_memory_expansion_True-offset_initialized_True-offset_0-opcode_MSTORE8 True True 0 MSTORE8
...fork_Osaka-state_test-big_memory_expansion_True-offset_initialized_True-offset_1-opcode_MLOAD True True 1 MLOAD
...fork_Osaka-state_test-big_memory_expansion_True-offset_initialized_True-offset_1-opcode_MSTORE True True 1 MSTORE
...fork_Osaka-state_test-big_memory_expansion_True-offset_initialized_True-offset_1-opcode_MSTORE8 True True 1 MSTORE8
...fork_Osaka-state_test-big_memory_expansion_True-offset_initialized_True-offset_31-opcode_MLOAD True True 31 MLOAD
...fork_Osaka-state_test-big_memory_expansion_True-offset_initialized_True-offset_31-opcode_MSTORE True True 31 MSTORE
...fork_Osaka-state_test-big_memory_expansion_True-offset_initialized_True-offset_31-opcode_MSTORE8 True True 31 MSTORE8
...fork_Osaka-state_test-big_memory_expansion_True-offset_initialized_False-offset_0-opcode_MLOAD True False 0 MLOAD
...fork_Osaka-state_test-big_memory_expansion_True-offset_initialized_False-offset_0-opcode_MSTORE True False 0 MSTORE
...fork_Osaka-state_test-big_memory_expansion_True-offset_initialized_False-offset_0-opcode_MSTORE8 True False 0 MSTORE8
...fork_Osaka-state_test-big_memory_expansion_True-offset_initialized_False-offset_1-opcode_MLOAD True False 1 MLOAD
...fork_Osaka-state_test-big_memory_expansion_True-offset_initialized_False-offset_1-opcode_MSTORE True False 1 MSTORE
...fork_Osaka-state_test-big_memory_expansion_True-offset_initialized_False-offset_1-opcode_MSTORE8 True False 1 MSTORE8
...fork_Osaka-state_test-big_memory_expansion_True-offset_initialized_False-offset_31-opcode_MLOAD True False 31 MLOAD
...fork_Osaka-state_test-big_memory_expansion_True-offset_initialized_False-offset_31-opcode_MSTORE True False 31 MSTORE
...fork_Osaka-state_test-big_memory_expansion_True-offset_initialized_False-offset_31-opcode_MSTORE8 True False 31 MSTORE8
...fork_Osaka-state_test-big_memory_expansion_False-offset_initialized_True-offset_0-opcode_MLOAD False True 0 MLOAD
...fork_Osaka-state_test-big_memory_expansion_False-offset_initialized_True-offset_0-opcode_MSTORE False True 0 MSTORE
...fork_Osaka-state_test-big_memory_expansion_False-offset_initialized_True-offset_0-opcode_MSTORE8 False True 0 MSTORE8
...fork_Osaka-state_test-big_memory_expansion_False-offset_initialized_True-offset_1-opcode_MLOAD False True 1 MLOAD
...fork_Osaka-state_test-big_memory_expansion_False-offset_initialized_True-offset_1-opcode_MSTORE False True 1 MSTORE
...fork_Osaka-state_test-big_memory_expansion_False-offset_initialized_True-offset_1-opcode_MSTORE8 False True 1 MSTORE8
...fork_Osaka-state_test-big_memory_expansion_False-offset_initialized_True-offset_31-opcode_MLOAD False True 31 MLOAD
...fork_Osaka-state_test-big_memory_expansion_False-offset_initialized_True-offset_31-opcode_MSTORE False True 31 MSTORE
...fork_Osaka-state_test-big_memory_expansion_False-offset_initialized_True-offset_31-opcode_MSTORE8 False True 31 MSTORE8
...fork_Osaka-state_test-big_memory_expansion_False-offset_initialized_False-offset_0-opcode_MLOAD False False 0 MLOAD
...fork_Osaka-state_test-big_memory_expansion_False-offset_initialized_False-offset_0-opcode_MSTORE False False 0 MSTORE
...fork_Osaka-state_test-big_memory_expansion_False-offset_initialized_False-offset_0-opcode_MSTORE8 False False 0 MSTORE8
...fork_Osaka-state_test-big_memory_expansion_False-offset_initialized_False-offset_1-opcode_MLOAD False False 1 MLOAD
...fork_Osaka-state_test-big_memory_expansion_False-offset_initialized_False-offset_1-opcode_MSTORE False False 1 MSTORE
...fork_Osaka-state_test-big_memory_expansion_False-offset_initialized_False-offset_1-opcode_MSTORE8 False False 1 MSTORE8
...fork_Osaka-state_test-big_memory_expansion_False-offset_initialized_False-offset_31-opcode_MLOAD False False 31 MLOAD
...fork_Osaka-state_test-big_memory_expansion_False-offset_initialized_False-offset_31-opcode_MSTORE False False 31 MSTORE
...fork_Osaka-state_test-big_memory_expansion_False-offset_initialized_False-offset_31-opcode_MSTORE8 False False 31 MSTORE8
...fork_Osaka-blockchain_test_from_state_test-big_memory_expansion_True-offset_initialized_True-offset_0-opcode_MLOAD True True 0 MLOAD
...fork_Osaka-blockchain_test_from_state_test-big_memory_expansion_True-offset_initialized_True-offset_0-opcode_MSTORE True True 0 MSTORE
...fork_Osaka-blockchain_test_from_state_test-big_memory_expansion_True-offset_initialized_True-offset_0-opcode_MSTORE8 True True 0 MSTORE8
...fork_Osaka-blockchain_test_from_state_test-big_memory_expansion_True-offset_initialized_True-offset_1-opcode_MLOAD True True 1 MLOAD
...fork_Osaka-blockchain_test_from_state_test-big_memory_expansion_True-offset_initialized_True-offset_1-opcode_MSTORE True True 1 MSTORE
...fork_Osaka-blockchain_test_from_state_test-big_memory_expansion_True-offset_initialized_True-offset_1-opcode_MSTORE8 True True 1 MSTORE8
...fork_Osaka-blockchain_test_from_state_test-big_memory_expansion_True-offset_initialized_True-offset_31-opcode_MLOAD True True 31 MLOAD
...fork_Osaka-blockchain_test_from_state_test-big_memory_expansion_True-offset_initialized_True-offset_31-opcode_MSTORE True True 31 MSTORE
...fork_Osaka-blockchain_test_from_state_test-big_memory_expansion_True-offset_initialized_True-offset_31-opcode_MSTORE8 True True 31 MSTORE8
...fork_Osaka-blockchain_test_from_state_test-big_memory_expansion_True-offset_initialized_False-offset_0-opcode_MLOAD True False 0 MLOAD
...fork_Osaka-blockchain_test_from_state_test-big_memory_expansion_True-offset_initialized_False-offset_0-opcode_MSTORE True False 0 MSTORE
...fork_Osaka-blockchain_test_from_state_test-big_memory_expansion_True-offset_initialized_False-offset_0-opcode_MSTORE8 True False 0 MSTORE8
...fork_Osaka-blockchain_test_from_state_test-big_memory_expansion_True-offset_initialized_False-offset_1-opcode_MLOAD True False 1 MLOAD
...fork_Osaka-blockchain_test_from_state_test-big_memory_expansion_True-offset_initialized_False-offset_1-opcode_MSTORE True False 1 MSTORE
...fork_Osaka-blockchain_test_from_state_test-big_memory_expansion_True-offset_initialized_False-offset_1-opcode_MSTORE8 True False 1 MSTORE8
...fork_Osaka-blockchain_test_from_state_test-big_memory_expansion_True-offset_initialized_False-offset_31-opcode_MLOAD True False 31 MLOAD
...fork_Osaka-blockchain_test_from_state_test-big_memory_expansion_True-offset_initialized_False-offset_31-opcode_MSTORE True False 31 MSTORE
...fork_Osaka-blockchain_test_from_state_test-big_memory_expansion_True-offset_initialized_False-offset_31-opcode_MSTORE8 True False 31 MSTORE8
...fork_Osaka-blockchain_test_from_state_test-big_memory_expansion_False-offset_initialized_True-offset_0-opcode_MLOAD False True 0 MLOAD
...fork_Osaka-blockchain_test_from_state_test-big_memory_expansion_False-offset_initialized_True-offset_0-opcode_MSTORE False True 0 MSTORE
...fork_Osaka-blockchain_test_from_state_test-big_memory_expansion_False-offset_initialized_True-offset_0-opcode_MSTORE8 False True 0 MSTORE8
...fork_Osaka-blockchain_test_from_state_test-big_memory_expansion_False-offset_initialized_True-offset_1-opcode_MLOAD False True 1 MLOAD
...fork_Osaka-blockchain_test_from_state_test-big_memory_expansion_False-offset_initialized_True-offset_1-opcode_MSTORE False True 1 MSTORE
...fork_Osaka-blockchain_test_from_state_test-big_memory_expansion_False-offset_initialized_True-offset_1-opcode_MSTORE8 False True 1 MSTORE8
...fork_Osaka-blockchain_test_from_state_test-big_memory_expansion_False-offset_initialized_True-offset_31-opcode_MLOAD False True 31 MLOAD
...fork_Osaka-blockchain_test_from_state_test-big_memory_expansion_False-offset_initialized_True-offset_31-opcode_MSTORE False True 31 MSTORE
...fork_Osaka-blockchain_test_from_state_test-big_memory_expansion_False-offset_initialized_True-offset_31-opcode_MSTORE8 False True 31 MSTORE8
...fork_Osaka-blockchain_test_from_state_test-big_memory_expansion_False-offset_initialized_False-offset_0-opcode_MLOAD False False 0 MLOAD
...fork_Osaka-blockchain_test_from_state_test-big_memory_expansion_False-offset_initialized_False-offset_0-opcode_MSTORE False False 0 MSTORE
...fork_Osaka-blockchain_test_from_state_test-big_memory_expansion_False-offset_initialized_False-offset_0-opcode_MSTORE8 False False 0 MSTORE8
...fork_Osaka-blockchain_test_from_state_test-big_memory_expansion_False-offset_initialized_False-offset_1-opcode_MLOAD False False 1 MLOAD
...fork_Osaka-blockchain_test_from_state_test-big_memory_expansion_False-offset_initialized_False-offset_1-opcode_MSTORE False False 1 MSTORE
...fork_Osaka-blockchain_test_from_state_test-big_memory_expansion_False-offset_initialized_False-offset_1-opcode_MSTORE8 False False 1 MSTORE8
...fork_Osaka-blockchain_test_from_state_test-big_memory_expansion_False-offset_initialized_False-offset_31-opcode_MLOAD False False 31 MLOAD
...fork_Osaka-blockchain_test_from_state_test-big_memory_expansion_False-offset_initialized_False-offset_31-opcode_MSTORE False False 31 MSTORE
...fork_Osaka-blockchain_test_from_state_test-big_memory_expansion_False-offset_initialized_False-offset_31-opcode_MSTORE8 False False 31 MSTORE8