Skip to content

test_valid()

Documentation for tests/prague/eip2537_bls_12_381_precompiles/test_bls12_g1add.py::test_valid@892e6d1e.

Generate fixtures for these test cases for Amsterdam with:

fill -v tests/prague/eip2537_bls_12_381_precompiles/test_bls12_g1add.py::test_valid --fork Amsterdam

Test the BLS12_G1ADD precompile.

Source code in tests/prague/eip2537_bls_12_381_precompiles/test_bls12_g1add.py
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
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
@pytest.mark.parametrize(
    "input_data,expected_output,vector_gas_value",
    # Test vectors from the reference spec (from the cryptography team)
    vectors_from_file("add_G1_bls.json")
    + [
        # Identity (infinity) element test cases. Checks that any point added
        # to the identity element (INF) equals itself.
        pytest.param(
            Spec.G1 + Spec.INF_G1,
            Spec.G1,
            None,
            id="generator_plus_inf",
        ),
        pytest.param(
            Spec.INF_G1 + Spec.G1,
            Spec.G1,
            None,
            id="inf_plus_generator",
        ),
        pytest.param(
            Spec.INF_G1 + Spec.INF_G1,
            Spec.INF_G1,
            None,
            id="inf_plus_inf",
        ),
        pytest.param(
            Spec.INF_G1 + Spec.P1,
            Spec.P1,
            None,
            id="inf_plus_point",
        ),
        # Basic arithmetic properties test cases.
        # Checks fundamental properties of the BLS12-381 curve.
        pytest.param(
            Spec.P1 + (-Spec.P1),
            Spec.INF_G1,
            None,
            id="point_plus_neg_point",
        ),
        pytest.param(
            Spec.G1 + (-Spec.G1),
            Spec.INF_G1,
            None,
            id="generator_plus_neg_point",
        ),
        pytest.param(
            Spec.P1 + Spec.G1,
            add_points_g1(Spec.G1, Spec.P1),
            None,
            id="commutative_check_a",
        ),
        pytest.param(
            Spec.G1 + Spec.P1,
            add_points_g1(Spec.P1, Spec.G1),
            None,
            id="commutative_check_b",
        ),
        pytest.param(
            Spec.P1 + Spec.P1,
            add_points_g1(Spec.P1, Spec.P1),
            None,
            id="point_doubling",
        ),
        pytest.param(  # (P + G) + P = P + (G + P)
            add_points_g1(Spec.P1, Spec.G1) + Spec.P1,
            add_points_g1(Spec.P1, add_points_g1(Spec.G1, Spec.P1)),
            None,
            id="associativity_check",
        ),
        pytest.param(  # -(P+G) = (-P)+(-G)
            (-(add_points_g1(Spec.P1, Spec.G1))) + Spec.INF_G1,
            add_points_g1((-Spec.P1), (-Spec.G1)),
            None,
            id="negation_of_sum",
        ),
        pytest.param(
            add_points_g1(Spec.G1, Spec.G1) + add_points_g1(Spec.P1, Spec.P1),
            add_points_g1(
                add_points_g1(Spec.G1, Spec.G1),
                add_points_g1(Spec.P1, Spec.P1),
            ),
            None,
            id="double_generator_plus_double_point",
        ),
        pytest.param(
            add_points_g1(Spec.G1, Spec.G1) + add_points_g1(Spec.G1, Spec.G1),
            add_points_g1(
                add_points_g1(Spec.G1, Spec.G1),
                add_points_g1(Spec.G1, Spec.G1),
            ),
            None,
            id="double_generator_plus_double_generator",
        ),
        pytest.param(  # (x,y) + (x,-y) = INF
            PointG1(Spec.P1.x, Spec.P1.y)
            + PointG1(Spec.P1.x, Spec.P - Spec.P1.y),
            Spec.INF_G1,
            None,
            id="point_plus_reflected_point",
        ),
        # Not in the r-order subgroup test cases. Checks that any point on the
        # curve but not in the subgroup is used for operations.
        pytest.param(
            Spec.P1_NOT_IN_SUBGROUP + Spec.P1_NOT_IN_SUBGROUP,
            Spec.P1_NOT_IN_SUBGROUP_TIMES_2,
            None,
            id="non_sub_plus_non_sub",
        ),
        pytest.param(  # `P1_NOT_IN_SUBGROUP` has an small order subgroup of 3:
            # 3P = INF.
            Spec.P1_NOT_IN_SUBGROUP + Spec.P1_NOT_IN_SUBGROUP_TIMES_2,
            Spec.INF_G1,
            None,
            id="non_sub_order_3_to_inf",
        ),
        pytest.param(
            Spec.P1_NOT_IN_SUBGROUP + Spec.INF_G1,
            Spec.P1_NOT_IN_SUBGROUP,
            None,
            id="non_sub_plus_inf",
        ),
        pytest.param(
            Spec.G1 + Spec.P1_NOT_IN_SUBGROUP,
            add_points_g1(Spec.G1, Spec.P1_NOT_IN_SUBGROUP),
            None,
            id="generator_plus_non_sub",
        ),
        pytest.param(
            Spec.P1_NOT_IN_SUBGROUP + (-Spec.P1_NOT_IN_SUBGROUP),
            Spec.INF_G1,
            None,
            id="non_sub_plus_neg_non_sub",
        ),
        pytest.param(
            Spec.P1 + Spec.P1_NOT_IN_SUBGROUP,
            add_points_g1(Spec.P1, Spec.P1_NOT_IN_SUBGROUP),
            None,
            id="in_sub_plus_non_sub",
        ),
        pytest.param(
            Spec.P1_NOT_IN_SUBGROUP_TIMES_2 + Spec.P1,
            add_points_g1(Spec.P1_NOT_IN_SUBGROUP_TIMES_2, Spec.P1),
            None,
            id="doubled_non_sub_plus_in_sub",
        ),
        pytest.param(
            Spec.P1_NOT_IN_SUBGROUP_TIMES_2 + (-Spec.P1_NOT_IN_SUBGROUP),
            Spec.P1_NOT_IN_SUBGROUP,
            None,
            id="doubled_non_sub_plus_neg",
        ),
        # More not in the r-order subgroup test cases, but using random
        # generated points.
        pytest.param(
            G1_POINTS_NOT_IN_SUBGROUP[0] + Spec.P1,
            add_points_g1(G1_POINTS_NOT_IN_SUBGROUP[0], Spec.P1),
            None,
            id="rand_not_in_subgroup_0_plus_point",
        ),
        pytest.param(
            G1_POINTS_NOT_IN_SUBGROUP[1] + Spec.G1,
            add_points_g1(G1_POINTS_NOT_IN_SUBGROUP[1], Spec.G1),
            None,
            id="rand_not_in_subgroup_1_plus_generator",
        ),
        pytest.param(
            G1_POINTS_NOT_IN_SUBGROUP[2] + Spec.INF_G1,
            G1_POINTS_NOT_IN_SUBGROUP[2],
            None,
            id="rand_not_in_subgroup_2_plus_inf",
        ),
        pytest.param(
            G1_POINTS_NOT_IN_SUBGROUP[3] + (-G1_POINTS_NOT_IN_SUBGROUP[3]),
            Spec.INF_G1,
            None,
            id="rand_not_in_subgroup_3_plus_neg_self",
        ),
        pytest.param(
            G1_POINTS_NOT_IN_SUBGROUP[4] + G1_POINTS_NOT_IN_SUBGROUP[0],
            add_points_g1(
                G1_POINTS_NOT_IN_SUBGROUP[4], G1_POINTS_NOT_IN_SUBGROUP[0]
            ),
            None,
            id="rand_not_in_subgroup_4_plus_0",
        ),
    ],
)
def test_valid(
    state_test: StateTestFiller,
    pre: Alloc,
    post: dict,
    tx: Transaction,
) -> None:
    """Test the BLS12_G1ADD precompile."""
    state_test(
        env=Environment(),
        pre=pre,
        tx=tx,
        post=post,
    )

Parametrized Test Cases

This test generates 34 parametrized test cases across 3 forks.