Skip to content

test_worst_mcopy()

Documentation for tests/benchmark/test_worst_memory.py::test_worst_mcopy@0f7c73a7.

Generate fixtures for these test cases for Prague with:

fill -v tests/benchmark/test_worst_memory.py::test_worst_mcopy --fork Prague

Test running a block filled with MCOPY executions.

Source code in tests/benchmark/test_worst_memory.py
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
@pytest.mark.valid_from("Cancun")
@pytest.mark.parametrize(
    "size",
    [
        pytest.param(0, id="0 bytes"),
        pytest.param(100, id="100 bytes"),
        pytest.param(10 * 1024, id="10KiB"),
        pytest.param(1024 * 1024, id="1MiB"),
    ],
)
@pytest.mark.parametrize(
    "fixed_src_dst",
    [
        True,
        False,
    ],
)
def test_worst_mcopy(
    state_test: StateTestFiller,
    pre: Alloc,
    fork: Fork,
    size: int,
    fixed_src_dst: bool,
):
    """Test running a block filled with MCOPY executions."""
    env = Environment()
    max_code_size = fork.max_code_size()

    mem_touch = (
        Op.MSTORE8(0, Op.GAS) + Op.MSTORE8(size // 2, Op.GAS) + Op.MSTORE8(size - 1, Op.GAS)
        if size > 0
        else Bytecode()
    )
    src_dst = 0 if fixed_src_dst else Op.MOD(Op.GAS, 7)
    attack_block = Op.MCOPY(src_dst, src_dst, size)

    jumpdest = Op.JUMPDEST
    jump_back = Op.JUMP(len(mem_touch))
    max_iters_loop = (max_code_size - 2 * len(mem_touch) - len(jumpdest) - len(jump_back)) // len(
        attack_block
    )
    code = mem_touch + jumpdest + sum([attack_block] * max_iters_loop) + mem_touch + jump_back
    assert len(code) <= max_code_size, (
        f"Code size {len(code)} is not equal to max code size {max_code_size}."
    )

    tx = Transaction(
        to=pre.deploy_contract(code=code),
        gas_limit=env.gas_limit,
        sender=pre.fund_eoa(),
    )

    state_test(
        genesis_environment=env,
        pre=pre,
        post={},
        tx=tx,
    )

Parametrized Test Cases

The interactive table below is also available as a standalone page.

Test ID (Abbreviated) fixed_src_dst size
...fork_Cancun-state_test-fixed_src_dst_True-0 bytes True 0
...fork_Cancun-state_test-fixed_src_dst_True-100 bytes True 100
...fork_Cancun-state_test-fixed_src_dst_True-10KiB True 10240
...fork_Cancun-state_test-fixed_src_dst_True-1MiB True 1048576
...fork_Cancun-state_test-fixed_src_dst_False-0 bytes False 0
...fork_Cancun-state_test-fixed_src_dst_False-100 bytes False 100
...fork_Cancun-state_test-fixed_src_dst_False-10KiB False 10240
...fork_Cancun-state_test-fixed_src_dst_False-1MiB False 1048576
...fork_Cancun-blockchain_test_from_state_test-fixed_src_dst_True-0 bytes True 0
...fork_Cancun-blockchain_test_from_state_test-fixed_src_dst_True-100 bytes True 100
...fork_Cancun-blockchain_test_from_state_test-fixed_src_dst_True-10KiB True 10240
...fork_Cancun-blockchain_test_from_state_test-fixed_src_dst_True-1MiB True 1048576
...fork_Cancun-blockchain_test_from_state_test-fixed_src_dst_False-0 bytes False 0
...fork_Cancun-blockchain_test_from_state_test-fixed_src_dst_False-100 bytes False 100
...fork_Cancun-blockchain_test_from_state_test-fixed_src_dst_False-10KiB False 10240
...fork_Cancun-blockchain_test_from_state_test-fixed_src_dst_False-1MiB False 1048576
...fork_Prague-state_test-fixed_src_dst_True-0 bytes True 0
...fork_Prague-state_test-fixed_src_dst_True-100 bytes True 100
...fork_Prague-state_test-fixed_src_dst_True-10KiB True 10240
...fork_Prague-state_test-fixed_src_dst_True-1MiB True 1048576
...fork_Prague-state_test-fixed_src_dst_False-0 bytes False 0
...fork_Prague-state_test-fixed_src_dst_False-100 bytes False 100
...fork_Prague-state_test-fixed_src_dst_False-10KiB False 10240
...fork_Prague-state_test-fixed_src_dst_False-1MiB False 1048576
...fork_Prague-blockchain_test_from_state_test-fixed_src_dst_True-0 bytes True 0
...fork_Prague-blockchain_test_from_state_test-fixed_src_dst_True-100 bytes True 100
...fork_Prague-blockchain_test_from_state_test-fixed_src_dst_True-10KiB True 10240
...fork_Prague-blockchain_test_from_state_test-fixed_src_dst_True-1MiB True 1048576
...fork_Prague-blockchain_test_from_state_test-fixed_src_dst_False-0 bytes False 0
...fork_Prague-blockchain_test_from_state_test-fixed_src_dst_False-100 bytes False 100
...fork_Prague-blockchain_test_from_state_test-fixed_src_dst_False-10KiB False 10240
...fork_Prague-blockchain_test_from_state_test-fixed_src_dst_False-1MiB False 1048576
...fork_Osaka-state_test-fixed_src_dst_True-0 bytes True 0
...fork_Osaka-state_test-fixed_src_dst_True-100 bytes True 100
...fork_Osaka-state_test-fixed_src_dst_True-10KiB True 10240
...fork_Osaka-state_test-fixed_src_dst_True-1MiB True 1048576
...fork_Osaka-state_test-fixed_src_dst_False-0 bytes False 0
...fork_Osaka-state_test-fixed_src_dst_False-100 bytes False 100
...fork_Osaka-state_test-fixed_src_dst_False-10KiB False 10240
...fork_Osaka-state_test-fixed_src_dst_False-1MiB False 1048576
...fork_Osaka-blockchain_test_from_state_test-fixed_src_dst_True-0 bytes True 0
...fork_Osaka-blockchain_test_from_state_test-fixed_src_dst_True-100 bytes True 100
...fork_Osaka-blockchain_test_from_state_test-fixed_src_dst_True-10KiB True 10240
...fork_Osaka-blockchain_test_from_state_test-fixed_src_dst_True-1MiB True 1048576
...fork_Osaka-blockchain_test_from_state_test-fixed_src_dst_False-0 bytes False 0
...fork_Osaka-blockchain_test_from_state_test-fixed_src_dst_False-100 bytes False 100
...fork_Osaka-blockchain_test_from_state_test-fixed_src_dst_False-10KiB False 10240
...fork_Osaka-blockchain_test_from_state_test-fixed_src_dst_False-1MiB False 1048576