Skip to content

test_bls12_g1_msm()

Documentation for tests/benchmark/compute/precompile/test_bls12_381.py::test_bls12_g1_msm@7b8124a7.

Generate fixtures for these test cases for Osaka 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
133
134
135
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
@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=Op.STATICCALL,
        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 2 forks.