17
18
19
20
21
22
23
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
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
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340 | @pytest.mark.parametrize(
"input_data, expected_output",
[
pytest.param(
Spec.G1 + Spec.INF_G1,
Spec.G1,
id="generator_plus_inf",
),
pytest.param(
Spec.INF_G1 + Spec.G1,
Spec.G1,
id="inf_plus_generator",
),
pytest.param(
Spec.G1 + Spec.INF_G1 + Spec.INF_G1,
Spec.G1,
id="generator_plus_inf_extra_inf",
),
pytest.param(
Spec.INF_G1 + Spec.G1 + Spec.INF_G1,
Spec.G1,
id="inf_plus_generator_extra_inf",
),
pytest.param(
b"",
Spec.INF_G1,
id="empty",
),
pytest.param(
Spec.INF_G1,
Spec.INF_G1,
id="single_inf",
),
pytest.param(
Spec.INF_G1 + Spec.INF_G1,
Spec.INF_G1,
id="double_inf",
),
pytest.param(
Spec.INF_G1 + Spec.INF_G1 + Spec.INF_G1,
Spec.INF_G1,
id="triple_inf",
),
pytest.param(
bytes(Spec.INF_G1)[:-1],
Spec.INF_G1,
id="inf_minus_1_byte",
),
pytest.param(
Spec.INF_G1 + b"\0" * 1,
Spec.INF_G1,
id="inf_plus_1_zero_byte",
),
pytest.param(
Spec.INF_G1 + Spec.INF_G1 + b"\0" * 1,
Spec.INF_G1,
id="double_inf_plus_1_zero_byte",
),
pytest.param(
b"\0" * 80,
Spec.INF_G1,
id="80_zero_bytes",
),
pytest.param(
Spec.G1,
Spec.G1,
id="single_generator",
),
pytest.param(
Spec.G1 + Spec.G1,
Spec.G1x2,
id="double_generator",
),
pytest.param(
Spec.G1 + Spec.G1 + Spec.G1,
Spec.G1x2, # Last generator is ignored data
id="triple_generator",
),
pytest.param(
Spec.G1 + Spec.G1 + Spec.INF_G1,
Spec.G1x2,
id="double_generator_extra_inf",
),
pytest.param(
Spec.G1 + Spec.G1 + PointG1(1, 3),
Spec.G1x2, # Extra invalid point is ignored
id="double_generator_extra_pt_1_3",
),
pytest.param(
Spec.P1 + Spec.Q1,
Spec.R1,
id="p1_plus_q1",
),
pytest.param(
Spec.P1 + PointG1(Spec.P1.x, Spec.P - Spec.P1.y),
Spec.INF_G1,
id="p1_plus_neg_p1",
),
pytest.param(
Spec.S1 + Spec.S1,
Spec.S1x2,
id="s1_doubled",
),
pytest.param(
Spec.S1 + Spec.S1x2,
Spec.S1x3,
id="s1_plus_s1x2",
),
pytest.param(
Spec.S1 + Spec.G1,
Spec.S1_PLUS_G1,
id="s1_plus_generator",
),
pytest.param(
Spec.S1,
Spec.S1,
id="single_s1",
),
# Ported from pointMulAdd / pointMulAdd2 (ECADD vs ECMUL)
pytest.param(
Spec.S1x2 + Spec.S1,
Spec.S1x3,
id="s1x2_plus_s1",
),
pytest.param(
PointG1(Spec.S1x3.x, Spec.P - Spec.S1x3.y) + Spec.S1x3,
Spec.INF_G1,
id="neg_s1x3_plus_s1x3",
),
pytest.param(
PointG1(Spec.S1x3.x, Spec.P - Spec.S1x3.y)
+ PointG1(Spec.S1x3.x, Spec.P - Spec.S1x3.y),
PointG1(
0x255E468453D7636CC1563E43F7521755F95E6C56043C7321B4AE04E772945FB0,
0x225C5F1623620FD84BFBAB2D861A9D1E570F7727C540F403085998EBAF407C4,
),
id="neg_s1x3_doubled",
),
pytest.param(
PointG1(Spec.S1x3.x, Spec.P - Spec.S1x3.y) + Spec.INF_G1,
PointG1(Spec.S1x3.x, Spec.P - Spec.S1x3.y),
id="neg_s1x3_plus_inf",
),
pytest.param(
Spec.S1x2 + Spec.INF_G1,
Spec.S1x2,
id="s1x2_plus_inf",
),
pytest.param(
Spec.G1 + PointG1(Spec.G1.x, Spec.P - Spec.G1.y),
Spec.INF_G1,
id="generator_plus_neg_generator",
),
pytest.param(
PointG1(Spec.G1.x, Spec.P - Spec.G1.y)
+ PointG1(Spec.G1.x, Spec.P - Spec.G1.y),
PointG1(Spec.G1x2.x, Spec.P - Spec.G1x2.y),
id="neg_generator_doubled",
),
pytest.param(
PointG1(Spec.G1x2.x, Spec.P - Spec.G1x2.y)
+ PointG1(Spec.G1.x, Spec.P - Spec.G1.y),
PointG1(
0x769BF9AC56BEA3FF40232BCB1B6BD159315D84715B8E679F2D355961915ABF0,
0x5ACB4B400E90C0063006A39F478F3E865E306DD5CD56F356E2E8CD8FE7EDAE6,
),
id="neg_g1x2_plus_neg_generator",
),
pytest.param(
PointG1(Spec.G1.x, Spec.P - Spec.G1.y) + Spec.INF_G1,
PointG1(Spec.G1.x, Spec.P - Spec.G1.y),
id="neg_generator_plus_inf",
),
pytest.param(
Spec.SAMPLE_G1 + PointG1(Spec.G1.x, Spec.P - Spec.G1.y),
PointG1(
0x113AECCECDAF57CD8C0AACE591774949DCDAF892555FA86726FA7E679B89C067,
0xBFFBA84127A19ABDE488A8251A9A3FCE33B34A76F96AAFB11AB4A6CEF3E9979,
),
id="sample_plus_neg_generator",
),
pytest.param(
Spec.SAMPLE_G1 + Spec.SAMPLE_G1,
PointG1(
0x1FD3B816D9951DCB9AA9797D25E51A865987703AE83CD69C4658679F0350AE2B,
0x29CE3D80A74DDC13784BEB25CA9FBFD048A3265A32C6F38B92060C5093A0E7A7,
),
id="sample_doubled",
),
pytest.param(
Spec.SAMPLE_G1 + Spec.INF_G1,
Spec.SAMPLE_G1,
id="sample_plus_inf",
),
pytest.param(
PointG1(Spec.G1x2_256_1.x, Spec.P - Spec.G1x2_256_1.y)
+ PointG1(Spec.G1.x, Spec.P - Spec.G1.y),
PointG1(
0x1D78954C630B3895FBBFAFAC1294F2C0158879FDC70BFE18222890E7BFB66FBA,
0x101C3346E98B136A7078AEBD427DCED763722D77E3D7985342E0BFFCC6EA4D56,
),
id="neg_g1x2_256_1_plus_neg_generator",
),
pytest.param(
PointG1(Spec.G1x2_256_1.x, Spec.P - Spec.G1x2_256_1.y)
+ PointG1(Spec.G1x2_256_1.x, Spec.P - Spec.G1x2_256_1.y),
PointG1(
0x2FA739D4CDE056D8FD75427345CBB34159856E06A4FFAD64159C4773F23FBF4B,
0x1EED5D5325C31FC89DD541A13D7F63B981FAE8D4BF78A6B08A38A601FCFEA97B,
),
id="neg_g1x2_256_1_doubled",
),
pytest.param(
PointG1(Spec.G1x2_256_1.x, Spec.P - Spec.G1x2_256_1.y)
+ Spec.INF_G1,
PointG1(Spec.G1x2_256_1.x, Spec.P - Spec.G1x2_256_1.y),
id="neg_g1x2_256_1_plus_inf",
),
pytest.param(
Spec.G1x2 + Spec.G1,
PointG1(
0x769BF9AC56BEA3FF40232BCB1B6BD159315D84715B8E679F2D355961915ABF0,
0x2AB799BEE0489429554FDB7C8D086475319E63B40B9C5B57CDF1FF3DD9FE2261,
),
id="g1x2_plus_generator",
),
pytest.param(
PointG1(Spec.G1.x, Spec.P - Spec.G1.y) + Spec.G1,
Spec.INF_G1,
id="neg_generator_plus_generator",
),
pytest.param(
PointG1(Spec.SAMPLE_G1.x, Spec.P - Spec.SAMPLE_G1.y) + Spec.G1,
PointG1(
0x113AECCECDAF57CD8C0AACE591774949DCDAF892555FA86726FA7E679B89C067,
0x246493EECEB7867DDA07BB342FD7B460B44635E9F8DB1F922A7541A9E93E63CE,
),
id="neg_sample_plus_generator",
),
pytest.param(
PointG1(Spec.SAMPLE_G1.x, Spec.P - Spec.SAMPLE_G1.y)
+ PointG1(Spec.SAMPLE_G1.x, Spec.P - Spec.SAMPLE_G1.y),
PointG1(
0x1FD3B816D9951DCB9AA9797D25E51A865987703AE83CD69C4658679F0350AE2B,
0x69610F239E3C41640045A90B6E1988D4EDE443735AAD701AA1A7FC644DC15A0,
),
id="neg_sample_doubled",
),
pytest.param(
PointG1(Spec.SAMPLE_G1.x, Spec.P - Spec.SAMPLE_G1.y) + Spec.INF_G1,
PointG1(Spec.SAMPLE_G1.x, Spec.P - Spec.SAMPLE_G1.y),
id="neg_sample_plus_inf",
),
pytest.param(
Spec.G1x2_256_1 + Spec.G1,
PointG1(
0x1D78954C630B3895FBBFAFAC1294F2C0158879FDC70BFE18222890E7BFB66FBA,
0x20481B2BF7A68CBF47D796F93F038986340F3D19849A3239F93FCC1A1192AFF1,
),
id="g1x2_256_1_plus_generator",
),
pytest.param(
Spec.G1x2_256_1 + Spec.G1x2_256_1,
PointG1(
0x2FA739D4CDE056D8FD75427345CBB34159856E06A4FFAD64159C4773F23FBF4B,
0x1176F11FBB6E80611A7B04154401F4A4158681BCA8F923DCB1E7E614DB7E53CC,
),
id="g1x2_256_1_doubled",
),
pytest.param(
Spec.G1x2_256_1 + Spec.INF_G1,
Spec.G1x2_256_1,
id="g1x2_256_1_plus_inf",
),
],
)
@pytest.mark.ported_from(
[
"https://github.com/ethereum/tests/blob/v13.3/src/GeneralStateTestsFiller/stZeroKnowledge/pointAddFiller.json",
"https://github.com/ethereum/tests/blob/v13.3/src/GeneralStateTestsFiller/stZeroKnowledge/pointAddTruncFiller.json",
"https://github.com/ethereum/tests/blob/v13.3/src/GeneralStateTestsFiller/stZeroKnowledge2/ecadd_0-0_0-0_21000_0Filler.json",
"https://github.com/ethereum/tests/blob/v13.3/src/GeneralStateTestsFiller/stZeroKnowledge2/ecadd_0-0_0-0_21000_64Filler.json",
"https://github.com/ethereum/tests/blob/v13.3/src/GeneralStateTestsFiller/stZeroKnowledge2/ecadd_0-0_0-0_21000_80_ParisFiller.json",
"https://github.com/ethereum/tests/blob/v13.3/src/GeneralStateTestsFiller/stZeroKnowledge2/ecadd_0-0_0-0_21000_128Filler.json",
"https://github.com/ethereum/tests/blob/v13.3/src/GeneralStateTestsFiller/stZeroKnowledge2/ecadd_0-0_0-0_21000_192Filler.json",
"https://github.com/ethereum/tests/blob/v13.3/src/GeneralStateTestsFiller/stZeroKnowledge2/ecadd_0-0_0-0_25000_0Filler.json",
"https://github.com/ethereum/tests/blob/v13.3/src/GeneralStateTestsFiller/stZeroKnowledge2/ecadd_0-0_0-0_25000_64Filler.json",
"https://github.com/ethereum/tests/blob/v13.3/src/GeneralStateTestsFiller/stZeroKnowledge2/ecadd_0-0_0-0_25000_80Filler.json",
"https://github.com/ethereum/tests/blob/v13.3/src/GeneralStateTestsFiller/stZeroKnowledge2/ecadd_0-0_0-0_25000_128Filler.json",
"https://github.com/ethereum/tests/blob/v13.3/src/GeneralStateTestsFiller/stZeroKnowledge2/ecadd_0-0_0-0_25000_192Filler.json",
"https://github.com/ethereum/tests/blob/v13.3/src/GeneralStateTestsFiller/stZeroKnowledge2/ecadd_0-0_1-2_21000_128Filler.json",
"https://github.com/ethereum/tests/blob/v13.3/src/GeneralStateTestsFiller/stZeroKnowledge2/ecadd_0-0_1-2_21000_192Filler.json",
"https://github.com/ethereum/tests/blob/v13.3/src/GeneralStateTestsFiller/stZeroKnowledge2/ecadd_0-0_1-2_25000_128Filler.json",
"https://github.com/ethereum/tests/blob/v13.3/src/GeneralStateTestsFiller/stZeroKnowledge2/ecadd_0-0_1-2_25000_192Filler.json",
"https://github.com/ethereum/tests/blob/v13.3/src/GeneralStateTestsFiller/stZeroKnowledge2/ecadd_1-2_0-0_21000_64Filler.json",
"https://github.com/ethereum/tests/blob/v13.3/src/GeneralStateTestsFiller/stZeroKnowledge2/ecadd_1-2_0-0_21000_128Filler.json",
"https://github.com/ethereum/tests/blob/v13.3/src/GeneralStateTestsFiller/stZeroKnowledge2/ecadd_1-2_0-0_21000_192Filler.json",
"https://github.com/ethereum/tests/blob/v13.3/src/GeneralStateTestsFiller/stZeroKnowledge2/ecadd_1-2_0-0_25000_64Filler.json",
"https://github.com/ethereum/tests/blob/v13.3/src/GeneralStateTestsFiller/stZeroKnowledge2/ecadd_1-2_0-0_25000_128Filler.json",
"https://github.com/ethereum/tests/blob/v13.3/src/GeneralStateTestsFiller/stZeroKnowledge2/ecadd_1-2_0-0_25000_192Filler.json",
"https://github.com/ethereum/tests/blob/v13.3/src/GeneralStateTestsFiller/stZeroKnowledge2/ecadd_1-2_1-2_21000_128Filler.json",
"https://github.com/ethereum/tests/blob/v13.3/src/GeneralStateTestsFiller/stZeroKnowledge2/ecadd_1-2_1-2_21000_192Filler.json",
"https://github.com/ethereum/tests/blob/v13.3/src/GeneralStateTestsFiller/stZeroKnowledge2/ecadd_1-2_1-2_25000_128Filler.json",
"https://github.com/ethereum/tests/blob/v13.3/src/GeneralStateTestsFiller/stZeroKnowledge2/ecadd_1-2_1-2_25000_192Filler.json",
"https://github.com/ethereum/tests/blob/v13.3/src/GeneralStateTestsFiller/stZeroKnowledge2/ecadd_1145-3932_1145-4651_21000_192Filler.json",
"https://github.com/ethereum/tests/blob/v13.3/src/GeneralStateTestsFiller/stZeroKnowledge2/ecadd_1145-3932_1145-4651_25000_192Filler.json",
"https://github.com/ethereum/tests/blob/v13.3/src/GeneralStateTestsFiller/stZeroKnowledge2/ecadd_1145-3932_2969-1336_21000_128Filler.json",
"https://github.com/ethereum/tests/blob/v13.3/src/GeneralStateTestsFiller/stZeroKnowledge2/ecadd_1145-3932_2969-1336_25000_128Filler.json",
"https://github.com/ethereum/tests/blob/v13.3/src/GeneralStateTestsFiller/stZeroKnowledge/pointMulAddFiller.json",
"https://github.com/ethereum/tests/blob/v13.3/src/GeneralStateTestsFiller/stZeroKnowledge/pointMulAdd2Filler.json",
],
pr=[
"https://github.com/ethereum/execution-specs/pull/1935",
"https://github.com/ethereum/execution-specs/pull/2477",
],
)
def test_valid(
state_test: StateTestFiller,
pre: Alloc,
post: dict,
tx: Transaction,
) -> None:
"""Test the valid inputs to the ECADD precompile."""
state_test(pre=pre, tx=tx, post=post)
|