Skip to content

test_creates_reverting_initcode()

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

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
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
@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.