Skip to content

test_bls12_g1_msm()

Documentation for tests/benchmark/compute/precompile/test_bls12_381.py::test_bls12_g1_msm@892e6d1e.

Generate fixtures for these test cases for Amsterdam with:

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

Benchmark BLS12_G1_MSM precompile with varying number of points.

Source code in tests/benchmark/compute/precompile/test_bls12_381.py
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
@pytest.mark.repricing
@pytest.mark.parametrize("k", [1, 16, 64, 128])
def test_bls12_g1_msm(
    benchmark_test: BenchmarkTestFiller,
    fork: Fork,
    k: int,
) -> None:
    """Benchmark BLS12_G1_MSM precompile with varying number of points."""
    precompile_address = bls12381_spec.Spec.G1MSM
    if precompile_address not in fork.precompiles():
        pytest.skip("BLS12_G1_MSM precompile not enabled")

    # Generate k pairs of (point, scalar)
    calldata = Bytes(
        (bls12381_spec.Spec.P1 + bls12381_spec.Scalar(bls12381_spec.Spec.Q))
        * k
    )

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

    benchmark_test(
        target_opcode=Precompile.BLS12_G1MSM,
        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.