Skip to content

test_return_revert()

Documentation for tests/benchmark/compute/instruction/test_system.py::test_return_revert@622620d8.

Generate fixtures for these test cases for Amsterdam with:

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

Benchmark RETURN and REVERT instructions.

Source code in tests/benchmark/compute/instruction/test_system.py
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
770
771
772
@pytest.mark.parametrize(
    "opcode",
    [Op.RETURN, Op.REVERT],
)
@pytest.mark.parametrize(
    "return_size, return_non_zero_data",
    [
        pytest.param(0, False, id="empty"),
        pytest.param(1024, True, id="1KiB of non-zero data"),
        pytest.param(1024, False, id="1KiB of zero data"),
        pytest.param(1024 * 1024, True, id="1MiB of non-zero data"),
        pytest.param(1024 * 1024, False, id="1MiB of zero data"),
    ],
)
def test_return_revert(
    benchmark_test: BenchmarkTestFiller,
    opcode: Op,
    return_size: int,
    return_non_zero_data: bool,
) -> None:
    """Benchmark RETURN and REVERT instructions."""
    # Create the contract that will be called repeatedly.
    # The bytecode of the contract is:
    # ```
    # [CODECOPY(returned_size) -- Conditional if return_non_zero_data]
    # opcode(returned_size)
    # <Fill with INVALID opcodes up to the max contract size>
    # ```
    # Filling the contract up to the max size is a cheap way of leveraging
    # CODECOPY to return non-zero bytes if requested. Note that since this
    # is a pre-deploy this cost isn't
    # relevant for the benchmark.
    mem_preparation = (
        Op.CODECOPY(size=return_size) if return_non_zero_data else Bytecode()
    )
    benchmark_test(
        target_opcode=opcode,
        code_generator=ExtCallGenerator(
            setup=mem_preparation,
            attack_block=opcode(size=return_size),
            code_padding_opcode=Op.INVALID,
        ),
    )

Parametrized Test Cases

This test generates 10 parametrized test cases across 3 forks.