24
25
26
27
28
29
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
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 | @pytest.mark.parametrize(
"input_data, expected_output",
[
pytest.param(
b"",
Spec.PAIRING_TRUE,
id="empty",
),
pytest.param(
Spec.INF_G1 + Spec.G2,
Spec.PAIRING_TRUE,
id="one_pair_g1_zero",
),
pytest.param(
Spec.G1 + Spec.INF_G2,
Spec.PAIRING_TRUE,
id="one_pair_g2_zero",
),
pytest.param(
Spec.G1 + Spec.G2 + Spec.NEG_G1 + Spec.G2,
Spec.PAIRING_TRUE,
id="two_pairs_negated_g1",
),
pytest.param(
Spec.G1
+ Spec.G2
+ Spec.G1
+ PointG2(
Spec.G2.x,
(
0x275DC4A288D1AFB3CBB1AC09187524C7DB36395DF7BE3B99E673B13A075A65EC,
0x1D9BEFCD05A5323E6DA4D435F3B617CDB3AF83285C2DF711EF39C01571827F9D,
),
),
Spec.PAIRING_TRUE,
id="two_point_match_2",
),
pytest.param(
Spec.G1
+ PointG2(
(
0x203E205DB4F19B37B60121B83A7333706DB86431C6D835849957ED8C3928AD79,
0x27DC7234FD11D3E8C36C59277C3E6F149D5CD3CFA9A62AEE49F8130962B4B3B9,
),
(
0x195E8AA5B7827463722B8C153931579D3505566B4EDF48D498E185F0509DE152,
0x04BB53B8977E5F92A0BC372742C4830944A59B4FE6B1C0466E2A6DAD122B5D2E,
),
)
+ PointG1(
0x030644E72E131A029B85045B68181585D97816A916871CA8D3C208C16D87CFD3,
0x1A76DAE6D3272396D0CBE61FCED2BC532EDAC647851E3AC53CE1CC9C7E645A83,
)
+ Spec.G2,
Spec.PAIRING_TRUE,
id="two_point_match_3",
),
pytest.param(
PointG1(
0x105456A333E6D636854F987EA7BB713DFD0AE8371A72AEA313AE0C32C0BF1016,
0x0CF031D41B41557F3E7E3BA0C51BEBE5DA8E6ECD855EC50FC87EFCDEAC168BCC,
)
+ PointG2(
(
0x0476BE093A6D2B4BBF907172049874AF11E1B6267606E00804D3FF0037EC57FD,
0x3010C68CB50161B7D1D96BB71EDFEC9880171954E56871ABF3D93CC94D745FA1,
),
(
0x14C059D74E5B6C4EC14AE5864EBE23A71781D86C29FB8FB6CCE94F70D3DE7A21,
0x01B33461F39D9E887DBB100F170A2345DDE3C07E256D1DFA2B657BA5CD030427,
),
)
+ Spec.G1
+ PointG2(
(
0x1A2C3013D2EA92E13C800CDE68EF56A294B883F6AC35D25F587C09B1B3C635F7,
0x290158A80CD3D66530F74DC94C94ADB88F5CDB481ACCA997B6E60071F08A115F,
),
(
0x2F997F3DBD66A7AFE07FE7862CE239EDBA9E05C5AFFF7F8A1259C9733B2DFBB9,
0x29D1691530CA701B4A106054688728C9972C8512E9789E9567AAE23E302CCD75,
),
),
Spec.PAIRING_TRUE,
id="two_point_match_4",
),
pytest.param(
Spec.G1 + Spec.INF_G2 + Spec.INF_G1 + Spec.G2,
Spec.PAIRING_TRUE,
id="two_point_match_5",
),
pytest.param(
PointG1(
0x105456A333E6D636854F987EA7BB713DFD0AE8371A72AEA313AE0C32C0BF1016,
0x0CF031D41B41557F3E7E3BA0C51BEBE5DA8E6ECD855EC50FC87EFCDEAC168BCC,
)
+ PointG2(
(
0x0476BE093A6D2B4BBF907172049874AF11E1B6267606E00804D3FF0037EC57FD,
0x3010C68CB50161B7D1D96BB71EDFEC9880171954E56871ABF3D93CC94D745FA1,
),
(
0x14C059D74E5B6C4EC14AE5864EBE23A71781D86C29FB8FB6CCE94F70D3DE7A21,
0x01B33461F39D9E887DBB100F170A2345DDE3C07E256D1DFA2B657BA5CD030427,
),
)
+ Spec.G1
+ PointG2(
(
0x1A2C3013D2EA92E13C800CDE68EF56A294B883F6AC35D25F587C09B1B3C635F7,
0x290158A80CD3D66530F74DC94C94ADB88F5CDB481ACCA997B6E60071F08A115F,
),
(
0x2F997F3DBD66A7AFE07FE7862CE239EDBA9E05C5AFFF7F8A1259C9733B2DFBB9,
0x29D1691530CA701B4A106054688728C9972C8512E9789E9567AAE23E302CCD75,
),
)
+ Spec.G1
+ Spec.INF_G2,
Spec.PAIRING_TRUE,
id="three_point_match_1",
),
pytest.param(
# e(16*G1, G2) * e(G1, -16*G2) == 1
# Exercises the FQ2 multiplicative inverse for scalar 16,
# which previously triggered a bug in the specification.
PointG1(
0x17F485337F6E10FCA0E385F7A93D1AC0A977E43995C3E4D9B8F89DAA6A183F44,
0x05CCDC1561DB963516DA62C66EDD39D1BB9C6C4674990C4440403C88025C95AD,
)
+ Spec.G2
+ Spec.G1
+ PointG2(
(
0x27A819BCF5C2C30229550CC0D34EE9C923EE6C3033A89F0BE27204893B112207,
0x29E39258393EE0C24EB66B69973E9FEB8B02E9D94A9897492C98EFE5B0EB459A,
),
(
0x12C79F74D498D73F3F1C4F2489FF4C5EF88C6A2C932560FEC4B5D2A1AE20D274,
0x1FBD1A0CA265F11112AF813152C1AD30B95AA1CBF94F7571552CA27658A6940C,
),
),
Spec.PAIRING_TRUE,
id="fq2_inverse_scalar_16",
),
],
)
@pytest.mark.ported_from(
[
"https://github.com/ethereum/legacytests/tree/master/Cancun/GeneralStateTests/stZeroKnowledge/ecpairing_empty_dataFiller.json",
"https://github.com/ethereum/legacytests/tree/master/Cancun/GeneralStateTests/stZeroKnowledge/ecpairing_one_point_with_g1_zeroFiller.json",
"https://github.com/ethereum/legacytests/tree/master/Cancun/GeneralStateTests/stZeroKnowledge/ecpairing_one_point_with_g2_zeroFiller.json",
"https://github.com/ethereum/legacytests/tree/master/Cancun/GeneralStateTests/stZeroKnowledge/ecpairing_two_point_match_1Filler.json",
"https://github.com/ethereum/legacytests/tree/master/Cancun/GeneralStateTests/stZeroKnowledge/ecpairing_two_point_match_2Filler.json",
"https://github.com/ethereum/legacytests/tree/master/Cancun/GeneralStateTests/stZeroKnowledge/ecpairing_two_point_match_3Filler.json",
"https://github.com/ethereum/legacytests/tree/master/Cancun/GeneralStateTests/stZeroKnowledge/ecpairing_two_point_match_4Filler.json",
"https://github.com/ethereum/legacytests/tree/master/Cancun/GeneralStateTests/stZeroKnowledge/ecpairing_two_point_match_5Filler.json",
"https://github.com/ethereum/legacytests/tree/master/Cancun/GeneralStateTests/stZeroKnowledge/ecpairing_three_point_match_1Filler.json",
],
pr=["https://github.com/ethereum/execution-specs/pull/2422"],
)
def test_valid(
state_test: StateTestFiller,
pre: Alloc,
post: dict,
tx: Transaction,
) -> None:
"""Test valid inputs where the pairing check succeeds."""
state_test(
env=Environment(),
pre=pre,
tx=tx,
post=post,
)
|