Skip to content

test_memory_access()

Documentation for tests/benchmark/compute/instruction/test_memory.py::test_memory_access@7b8124a7.

Generate fixtures for these test cases for Osaka with:

fill -v tests/benchmark/compute/instruction/test_memory.py::test_memory_access --gas-benchmark-values 1

Benchmark memory access instructions.

Source code in tests/benchmark/compute/instruction/test_memory.py
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
@pytest.mark.repricing(offset=0, offset_initialized=True)
@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("mem_size", [0, 32, 256, 1024, 10 * 1024])
def test_memory_access(
    benchmark_test: BenchmarkTestFiller,
    opcode: Op,
    offset: int,
    offset_initialized: bool,
    mem_size: int,
) -> None:
    """Benchmark memory access instructions."""
    setup = Bytecode()

    setup += Op.MSTORE8(mem_size - 1, 1) if mem_size > 0 else Bytecode()
    setup += Op.MSTORE(offset, 43) if offset_initialized else Bytecode()
    setup += Op.PUSH1(42) + Op.PUSH1(offset)

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

    benchmark_test(
        target_opcode=opcode,
        code_generator=JumpLoopGenerator(
            setup=setup, attack_block=attack_block
        ),
    )

Parametrized Test Cases

This test generates 90 parametrized test cases across 2 forks.