test_bls12_g2_msm()
Documentation for tests/benchmark/compute/precompile/test_bls12_381.py::test_bls12_g2_msm@21507778.
Generate fixtures for these test cases for Amsterdam with:
fill -v tests/benchmark/compute/precompile/test_bls12_381.py::test_bls12_g2_msm --gas-benchmark-values 1
Benchmark BLS12_G2_MSM precompile with varying number of points.
Source code in tests/benchmark/compute/precompile/test_bls12_381.py
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205 | @pytest.mark.repricing
@pytest.mark.parametrize(
"k",
[
1,
16,
64,
# G2 MSM k=128 costs 1.5M gas
pytest.param(128, marks=pytest.mark.slow),
],
)
def test_bls12_g2_msm(
benchmark_test: BenchmarkTestFiller,
fork: Fork,
gas_benchmark_value: int,
k: int,
) -> None:
"""Benchmark BLS12_G2_MSM precompile with varying number of points."""
precompile_address = bls12381_spec.Spec.G2MSM
if precompile_address not in fork.precompiles():
pytest.skip("BLS12_G2_MSM precompile not enabled")
# Generate k pairs of (point, scalar)
calldata = Bytes(
(bls12381_spec.Spec.P2 + bls12381_spec.Scalar(bls12381_spec.Spec.Q))
* k
)
intrinsic_gas_cost = fork.transaction_intrinsic_cost_calculator()(
calldata=calldata
)
if intrinsic_gas_cost > gas_benchmark_value:
pytest.skip("k configuration exceeds the gas limit")
attack_block = Op.POP(
Op.STATICCALL(
gas=Op.GAS, address=precompile_address, args_size=Op.CALLDATASIZE
),
)
benchmark_test(
target_opcode=Precompile.BLS12_G2MSM,
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.