Skip to content

test_creates_reverting_initcode()

Documentation for tests/benchmark/compute/instruction/test_system.py::test_creates_reverting_initcode@c17999c0.

Generate fixtures for these test cases for Amsterdam with:

fill -v tests/benchmark/compute/instruction/test_system.py::test_creates_reverting_initcode --gas-benchmark-values 1

Benchmark CREATE and CREATE2 whose initcode reverts.

Source code in tests/benchmark/compute/instruction/test_system.py
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
@pytest.mark.parametrize(
    "opcode",
    [
        Op.CREATE,
        Op.CREATE2,
    ],
)
@pytest.mark.parametrize(
    "revert_size",
    [
        pytest.param(0, id="empty revert data"),
        pytest.param(32, id="32 bytes of revert data"),
        pytest.param(1024, id="1KiB of revert data"),
    ],
)
def test_creates_reverting_initcode(
    benchmark_test: BenchmarkTestFiller,
    opcode: Op,
    revert_size: int,
) -> None:
    """Benchmark CREATE and CREATE2 whose initcode reverts."""
    initcode = Op.REVERT(0, revert_size)

    salt_kwarg: dict[str, Any] = {}
    if opcode == Op.CREATE2:
        salt_kwarg = {"salt": 0}

    attack_block = Op.POP(
        opcode(
            value=0,
            offset=32 - len(initcode),
            size=len(initcode),
            **salt_kwarg,
        )
    )

    benchmark_test(
        target_opcode=opcode,
        code_generator=JumpLoopGenerator(
            setup=Op.MSTORE(0, initcode.hex()),
            attack_block=attack_block,
        ),
    )

Parametrized Test Cases

This test generates 6 parametrized test cases across 3 forks.