30
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 | @pytest.mark.parametrize(
"input_data,expected_output,vector_gas_value",
# Test vectors from the reference spec (from the cryptography team)
vectors_from_file("mul_G2_bls.json")
+ [
# Basic multiplication test cases.
pytest.param(
Spec.INF_G2 + Scalar(0),
Spec.INF_G2,
None,
id="zero_times_inf",
),
pytest.param(
Spec.INF_G2 + Scalar(1),
Spec.INF_G2,
None,
id="one_times_inf",
),
pytest.param(
Spec.INF_G2 + Scalar(2),
Spec.INF_G2,
None,
id="two_times_inf",
),
pytest.param(
Spec.INF_G2 + Scalar(Spec.Q),
Spec.INF_G2,
None,
id="q_times_inf",
),
pytest.param(
Spec.INF_G2 + Scalar(2**256 - 1),
Spec.INF_G2,
None,
id="max_scalar_times_inf",
),
pytest.param(
Spec.G2 + Scalar(0),
Spec.INF_G2,
None,
id="zero_times_generator",
),
pytest.param(
Spec.P2 + Scalar(0),
Spec.INF_G2,
None,
id="zero_times_point",
),
pytest.param(
Spec.G2 + Scalar(1),
Spec.G2,
None,
id="one_times_generator",
),
pytest.param(
Spec.P2 + Scalar(1),
Spec.P2,
None,
id="one_times_point",
),
pytest.param(
Spec.P2 + Scalar(2**256 - 1),
PointG2(
(
0x2663E1C3431E174CA80E5A84489569462E13B52DA27E7720AF5567941603475F1F9BC0102E13B92A0A21D96B94E9B22,
0x6A80D056486365020A6B53E2680B2D72D8A93561FC2F72B960936BB16F509C1A39C4E4174A7C9219E3D7EF130317C05,
),
(
0xC49EAD39E9EB7E36E8BC25824299661D5B6D0E200BBC527ECCB946134726BF5DBD861E8E6EC946260B82ED26AFE15FB,
0x5397DAD1357CF8333189821B737172B18099ECF7EE8BDB4B3F05EBCCDF40E1782A6C71436D5ACE0843D7F361CBC6DB2,
),
),
None,
id="max_scalar_times_point",
),
# Subgroup related test cases.
pytest.param(
Spec.P2 + Scalar(Spec.Q - 1),
-Spec.P2, # negated P2
None,
id="q_minus_1_times_point",
),
pytest.param(
Spec.P2 + Scalar(Spec.Q),
Spec.INF_G2,
None,
id="q_times_point",
),
pytest.param(
Spec.G2 + Scalar(Spec.Q),
Spec.INF_G2,
None,
id="q_times_generator",
),
pytest.param(
Spec.P2 + Scalar(Spec.Q + 1),
Spec.P2,
None,
id="q_plus_1_times_point",
),
pytest.param(
Spec.P2 + Scalar(2 * Spec.Q),
Spec.INF_G2,
None,
id="2q_times_point",
),
pytest.param(
Spec.P2 + Scalar((2**256 // Spec.Q) * Spec.Q),
Spec.INF_G2,
None,
id="large_multiple_of_q_times_point",
),
],
)
def test_valid(
state_test: StateTestFiller,
pre: Alloc,
post: dict,
tx: Transaction,
) -> None:
"""Test the BLS12_G2MUL precompile."""
state_test(
env=Environment(),
pre=pre,
tx=tx,
post=post,
)
|