Skip to content

test_invalid()

Documentation for tests/prague/eip2537_bls_12_381_precompiles/test_bls12_g2msm.py::test_invalid@892e6d1e.

Generate fixtures for these test cases for Amsterdam with:

fill -v tests/prague/eip2537_bls_12_381_precompiles/test_bls12_g2msm.py::test_invalid --fork Amsterdam

Test invalid calls to the BLS12_G2MSM precompile.

Source code in tests/prague/eip2537_bls_12_381_precompiles/test_bls12_g2msm.py
122
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
155
156
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
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
@pytest.mark.parametrize(
    "input_data",
    # Test vectors from the reference spec (from the cryptography team)
    vectors_from_file("fail-msm_G2_bls.json")
    + [
        pytest.param(
            Spec.P2_NOT_IN_SUBGROUP + Scalar(1),
            id="not_in_subgroup_1_pos_0",
        ),
        pytest.param(
            Spec.P2_NOT_IN_SUBGROUP_TIMES_2 + Scalar(1),
            id="not_in_subgroup_2_pos_0",
        ),
        pytest.param(
            Spec.G2 + Scalar(1) + Spec.P2_NOT_IN_SUBGROUP + Scalar(1),
            id="not_in_subgroup_1_pos_1",
        ),
        pytest.param(
            Spec.G2 + Scalar(1) + Spec.P2_NOT_IN_SUBGROUP_TIMES_2 + Scalar(1),
            id="not_in_subgroup_2_pos_1",
        ),
        pytest.param(
            G2_POINTS_NOT_IN_SUBGROUP[0] + Scalar(1),
            id="rand_not_in_subgroup_0_pos_0",
        ),
        pytest.param(
            G2_POINTS_NOT_IN_SUBGROUP[1] + Scalar(1),
            id="rand_not_in_subgroup_1_pos_0",
        ),
        pytest.param(
            Spec.G2 + Scalar(1) + G2_POINTS_NOT_IN_SUBGROUP[0] + Scalar(1),
            id="rand_not_in_subgroup_0_pos_1",
        ),
        pytest.param(
            Spec.G2 + Scalar(1) + G2_POINTS_NOT_IN_SUBGROUP[1] + Scalar(1),
            id="rand_not_in_subgroup_1_pos_1",
        ),
        pytest.param(
            G2_POINTS_NOT_ON_CURVE[0] + Scalar(0),
            id="not_on_curve_0_pos_0",
        ),
        pytest.param(
            G2_POINTS_NOT_ON_CURVE[1] + Scalar(1),
            id="not_on_curve_1_pos_0",
        ),
        pytest.param(
            Spec.G2 + Scalar(1) + G2_POINTS_NOT_ON_CURVE[0] + Scalar(0),
            id="not_on_curve_0_pos_1",
        ),
        pytest.param(
            Spec.G2 + Scalar(1) + G2_POINTS_NOT_ON_CURVE[1] + Scalar(1),
            id="not_on_curve_1_pos_1",
        ),
        pytest.param(
            Spec.G2 + Scalar(1) + Spec.G2,
            id="incomplete_input_missing_scalar",
        ),
        pytest.param(
            Spec.G2 + Scalar(1) + bytes([0]),
            id="incomplete_input_extra_byte",
        ),
        pytest.param(
            Spec.G2 + Scalar(1) + Spec.G1 + Scalar(1),
            id="mixing_g2_with_g1",
        ),
        pytest.param(
            Spec.G2 + (b"\x01" + b"\x00" * 32),  # Scalar > UINT256_MAX
            id="scalar_too_large",
        ),
        pytest.param(
            # Invalid scalar length
            Spec.G2 + Scalar(1).x.to_bytes(16, byteorder="big"),
            id="scalar_too_short",
        ),
        pytest.param(
            bytes([0]) * 287,  # Just under minimum valid length
            id="input_too_short_by_1",
        ),
        # Coordinates above modulus p cases.
        pytest.param(
            PointG2((Spec.P2.x[0] + Spec.P, Spec.P2.x[1]), Spec.P2.y)
            + Scalar(1),
            id="x_c0_above_p_pos_0",
        ),
        pytest.param(
            PointG2((Spec.P2.x[0], Spec.P2.x[1] + Spec.P), Spec.P2.y)
            + Scalar(1),
            id="x_c1_above_p_pos_0",
        ),
        pytest.param(
            PointG2(Spec.P2.x, (Spec.P2.y[0] + Spec.P, Spec.P2.y[1]))
            + Scalar(1),
            id="y_c0_above_p_pos_0",
        ),
        pytest.param(
            PointG2(Spec.P2.x, (Spec.P2.y[0], Spec.P2.y[1] + Spec.P))
            + Scalar(1),
            id="y_c1_above_p_pos_0",
        ),
        pytest.param(
            Spec.G2
            + Scalar(1)
            + PointG2((Spec.P2.x[0] + Spec.P, Spec.P2.x[1]), Spec.P2.y)
            + Scalar(0),
            id="x_c0_above_p_pos_1",
        ),
        pytest.param(
            Spec.G2
            + Scalar(1)
            + PointG2((Spec.P2.x[0], Spec.P2.x[1] + Spec.P), Spec.P2.y)
            + Scalar(0),
            id="x_c1_above_p_pos_1",
        ),
        pytest.param(
            Spec.G2
            + Scalar(1)
            + PointG2(Spec.P2.x, (Spec.P2.y[0] + Spec.P, Spec.P2.y[1]))
            + Scalar(0),
            id="y_c0_above_p_pos_1",
        ),
        pytest.param(
            Spec.G2
            + Scalar(1)
            + PointG2(Spec.P2.x, (Spec.P2.y[0], Spec.P2.y[1] + Spec.P))
            + Scalar(0),
            id="y_c1_above_p_pos_1",
        ),
    ],
    # Input length tests can be found in
    # ./test_bls12_variable_length_input_contracts.py
)
@pytest.mark.parametrize(
    "precompile_gas_modifier", [100_000], ids=[""]
)  # Add gas so that won't be the cause of failure
@pytest.mark.parametrize("expected_output", [Spec.INVALID], ids=[""])
@pytest.mark.eels_base_coverage
def test_invalid(
    state_test: StateTestFiller,
    pre: Alloc,
    post: dict,
    tx: Transaction,
) -> None:
    """Test invalid calls to the BLS12_G2MSM precompile."""
    state_test(
        env=Environment(),
        pre=pre,
        tx=tx,
        post=post,
    )

Parametrized Test Cases

This test generates 33 parametrized test cases across 3 forks.