Skip to content

test_creates_reverting_initcode()

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

Generate fixtures for these test cases for Bogota 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
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
@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 4 forks.