Skip to content

test_blake2f_benchmark()

Documentation for tests/benchmark/compute/precompile/test_blake2f.py::test_blake2f_benchmark@8db70f93.

Generate fixtures for these test cases for Amsterdam with:

fill -v tests/benchmark/compute/precompile/test_blake2f.py::test_blake2f_benchmark --gas-benchmark-values 1

Benchmark BLAKE2F precompile with varying number of rounds.

Source code in tests/benchmark/compute/precompile/test_blake2f.py
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
@pytest.mark.repricing
@pytest.mark.parametrize("num_rounds", [1, 6, 12, 24])
def test_blake2f_benchmark(
    benchmark_test: BenchmarkTestFiller,
    fork: Fork,
    num_rounds: int,
) -> None:
    """Benchmark BLAKE2F precompile with varying number of rounds."""
    precompile_address = Blake2bSpec.BLAKE2_PRECOMPILE_ADDRESS
    if precompile_address not in fork.precompiles():
        pytest.skip("Precompile not enabled")

    calldata = Blake2bInput(rounds=num_rounds, f=True).create_blake2b_tx_data()

    attack_block = Op.POP(
        Op.STATICCALL(
            gas=Op.GAS, address=precompile_address, args_size=Op.CALLDATASIZE
        ),
    )

    benchmark_test(
        target_opcode=Precompile.BLAKE2F,
        code_generator=JumpLoopGenerator(
            setup=Op.CALLDATACOPY(0, 0, Op.CALLDATASIZE),
            attack_block=attack_block,
            tx_kwargs={"data": calldata},
        ),
    )

Parametrized Test Cases

This test generates 4 parametrized test cases across 3 forks.