Skip to content

test_creates_reverting_initcode()

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

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
@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.