Skip to content

test_nested_frame_memory()

Documentation for tests/benchmark/compute/instruction/test_memory.py::test_nested_frame_memory@814481c0.

Generate fixtures for these test cases for Amsterdam with:

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

Benchmark a deep frame stack where every frame holds live memory.

Source code in tests/benchmark/compute/instruction/test_memory.py
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
@pytest.mark.parametrize("depth", [1, 64, 256])
@pytest.mark.parametrize("mem_size", [0, 8 * 1024, 64 * 1024])
def test_nested_frame_memory(
    benchmark_test: BenchmarkTestFiller,
    pre: Alloc,
    fork: Fork,
    depth: int,
    mem_size: int,
) -> None:
    """Benchmark a deep frame stack where every frame holds live memory."""
    leaf_address = pre.deploy_contract(
        code=WhileGas(body=Op.POP(Op.MLOAD(Op.PUSH0)), fork=fork)
    )

    # The frame's own memory is claimed before the descent, and must not
    # overlap memory[0:32], which carries the depth to the next frame.
    frame_memory = (
        Op.MSTORE8(mem_size - 1, 0xFF) if mem_size > 0 else Bytecode()
    )

    descend = Op.MSTORE(0, Op.SUB(Op.CALLDATALOAD(0), 1)) + Conditional(
        condition=Op.CALL(
            gas=Op.GAS,
            address=Op.ADDRESS,
            args_offset=0,
            args_size=32,
        ),
        if_false=Op.REVERT(0, 0),
    )

    entry_address = pre.deploy_contract(
        code=frame_memory
        + Conditional(
            condition=Op.ISZERO(Op.CALLDATALOAD(0)),
            if_true=Op.POP(Op.CALL(gas=Op.GAS, address=leaf_address)),
            if_false=descend,
        )
    )

    benchmark_test(
        tx=Transaction(
            to=entry_address,
            data=Hash(depth),
            sender=pre.fund_eoa(),
        ),
        skip_gas_used_validation=True,
    )

Parametrized Test Cases

This test generates 9 parametrized test cases across 3 forks.