Skip to content

test_bls12_pairing()

Documentation for tests/benchmark/compute/precompile/test_bls12_381.py::test_bls12_pairing@02aafd78.

Generate fixtures for these test cases for Bogota with:

fill -v tests/benchmark/compute/precompile/test_bls12_381.py::test_bls12_pairing --gas-benchmark-values 1

Benchmark BLS12_PAIRING precompile with varying number of pairs.

Source code in tests/benchmark/compute/precompile/test_bls12_381.py
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
@pytest.mark.repricing
@pytest.mark.parametrize("num_pairs", [1, 3, 6, 12, 24])
def test_bls12_pairing(
    benchmark_test: BenchmarkTestFiller,
    fork: Fork,
    num_pairs: int,
) -> None:
    """Benchmark BLS12_PAIRING precompile with varying number of pairs."""
    precompile_address = bls12381_spec.Spec.PAIRING
    if precompile_address not in fork.precompiles():
        pytest.skip("BLS12_PAIRING precompile not enabled")

    # Generate num_pairs pairs of (G1, G2) points
    calldata = Bytes(
        (bls12381_spec.Spec.G1 + bls12381_spec.Spec.G2) * num_pairs
    )

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

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

Parametrized Test Cases

This test generates 5 parametrized test cases across 4 forks.