-
Notifications
You must be signed in to change notification settings - Fork 163
/
element_exp.go
623 lines (484 loc) · 13.3 KB
/
element_exp.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
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
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
// Copyright 2020 ConsenSys Software Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// Code generated by consensys/gnark-crypto DO NOT EDIT
package fr
// expBySqrtExp is equivalent to z.Exp(x, 12ab655e9a2ca55660b44d1e5c37b00159aa76fed00000010a11)
//
// uses github.com/mmcloughlin/addchain v0.4.0 to generate a shorter addition chain
func (z *Element) expBySqrtExp(x Element) *Element {
// addition chain:
//
// _10 = 2*1
// _11 = 1 + _10
// _101 = _10 + _11
// _1000 = _11 + _101
// _1011 = _11 + _1000
// _10000 = _101 + _1011
// _10001 = 1 + _10000
// _10110 = _101 + _10001
// _100000 = 2*_10000
// _101011 = _1011 + _100000
// _101101 = _10 + _101011
// _1011010 = 2*_101101
// _1011011 = 1 + _1011010
// _1111011 = _100000 + _1011011
// _10000101 = _101011 + _1011010
// _10001011 = _10000 + _1111011
// _10100101 = _100000 + _10000101
// _10101011 = _100000 + _10001011
// _11000001 = _10110 + _10101011
// _11000011 = _10 + _11000001
// _11010001 = _10000 + _11000001
// _11010011 = _10 + _11010001
// _11010101 = _10 + _11010011
// _11100101 = _10000 + _11010101
// _11101101 = _1000 + _11100101
// i45 = ((_10000101 + _10100101) << 7 + _1011011) << 10 + _10101011
// i74 = ((i45 << 8 + _11010011) << 9 + _10001011) << 10
// i94 = ((_10100101 + i74) << 7 + _101011) << 10 + _11000001
// i123 = ((i94 << 9 + _11010001) << 10 + _11010001) << 8
// i142 = ((_11100101 + i123) << 8 + _11000011) << 8 + _1111011
// i181 = ((i142 << 17 + _101011) << 10 + _11010101) << 10
// i195 = ((_11101101 + i181) << 8 + _11101101 + _10000) << 3
// return ((_101 + i195) << 35 + _10000101) << 9 + _10001
//
// Operations: 199 squares 43 multiplies
// Allocate Temporaries.
var (
t0 = new(Element)
t1 = new(Element)
t2 = new(Element)
t3 = new(Element)
t4 = new(Element)
t5 = new(Element)
t6 = new(Element)
t7 = new(Element)
t8 = new(Element)
t9 = new(Element)
t10 = new(Element)
t11 = new(Element)
t12 = new(Element)
t13 = new(Element)
t14 = new(Element)
t15 = new(Element)
t16 = new(Element)
)
// var t0,t1,t2,t3,t4,t5,t6,t7,t8,t9,t10,t11,t12,t13,t14,t15,t16 Element
// Step 1: t4 = x^0x2
t4.Square(&x)
// Step 2: z = x^0x3
z.Mul(&x, t4)
// Step 3: t1 = x^0x5
t1.Mul(t4, z)
// Step 4: t3 = x^0x8
t3.Mul(z, t1)
// Step 5: t0 = x^0xb
t0.Mul(z, t3)
// Step 6: t2 = x^0x10
t2.Mul(t1, t0)
// Step 7: z = x^0x11
z.Mul(&x, t2)
// Step 8: t7 = x^0x16
t7.Mul(t1, z)
// Step 9: t8 = x^0x20
t8.Square(t2)
// Step 10: t5 = x^0x2b
t5.Mul(t0, t8)
// Step 11: t0 = x^0x2d
t0.Mul(t4, t5)
// Step 12: t0 = x^0x5a
t0.Square(t0)
// Step 13: t15 = x^0x5b
t15.Mul(&x, t0)
// Step 14: t6 = x^0x7b
t6.Mul(t8, t15)
// Step 15: t0 = x^0x85
t0.Mul(t5, t0)
// Step 16: t12 = x^0x8b
t12.Mul(t2, t6)
// Step 17: t11 = x^0xa5
t11.Mul(t8, t0)
// Step 18: t14 = x^0xab
t14.Mul(t8, t12)
// Step 19: t10 = x^0xc1
t10.Mul(t7, t14)
// Step 20: t7 = x^0xc3
t7.Mul(t4, t10)
// Step 21: t9 = x^0xd1
t9.Mul(t2, t10)
// Step 22: t13 = x^0xd3
t13.Mul(t4, t9)
// Step 23: t4 = x^0xd5
t4.Mul(t4, t13)
// Step 24: t8 = x^0xe5
t8.Mul(t2, t4)
// Step 25: t3 = x^0xed
t3.Mul(t3, t8)
// Step 26: t16 = x^0x12a
t16.Mul(t0, t11)
// Step 33: t16 = x^0x9500
for s := 0; s < 7; s++ {
t16.Square(t16)
}
// Step 34: t15 = x^0x955b
t15.Mul(t15, t16)
// Step 44: t15 = x^0x2556c00
for s := 0; s < 10; s++ {
t15.Square(t15)
}
// Step 45: t14 = x^0x2556cab
t14.Mul(t14, t15)
// Step 53: t14 = x^0x2556cab00
for s := 0; s < 8; s++ {
t14.Square(t14)
}
// Step 54: t13 = x^0x2556cabd3
t13.Mul(t13, t14)
// Step 63: t13 = x^0x4aad957a600
for s := 0; s < 9; s++ {
t13.Square(t13)
}
// Step 64: t12 = x^0x4aad957a68b
t12.Mul(t12, t13)
// Step 74: t12 = x^0x12ab655e9a2c00
for s := 0; s < 10; s++ {
t12.Square(t12)
}
// Step 75: t11 = x^0x12ab655e9a2ca5
t11.Mul(t11, t12)
// Step 82: t11 = x^0x955b2af4d165280
for s := 0; s < 7; s++ {
t11.Square(t11)
}
// Step 83: t11 = x^0x955b2af4d1652ab
t11.Mul(t5, t11)
// Step 93: t11 = x^0x2556cabd34594aac00
for s := 0; s < 10; s++ {
t11.Square(t11)
}
// Step 94: t10 = x^0x2556cabd34594aacc1
t10.Mul(t10, t11)
// Step 103: t10 = x^0x4aad957a68b295598200
for s := 0; s < 9; s++ {
t10.Square(t10)
}
// Step 104: t10 = x^0x4aad957a68b2955982d1
t10.Mul(t9, t10)
// Step 114: t10 = x^0x12ab655e9a2ca55660b4400
for s := 0; s < 10; s++ {
t10.Square(t10)
}
// Step 115: t9 = x^0x12ab655e9a2ca55660b44d1
t9.Mul(t9, t10)
// Step 123: t9 = x^0x12ab655e9a2ca55660b44d100
for s := 0; s < 8; s++ {
t9.Square(t9)
}
// Step 124: t8 = x^0x12ab655e9a2ca55660b44d1e5
t8.Mul(t8, t9)
// Step 132: t8 = x^0x12ab655e9a2ca55660b44d1e500
for s := 0; s < 8; s++ {
t8.Square(t8)
}
// Step 133: t7 = x^0x12ab655e9a2ca55660b44d1e5c3
t7.Mul(t7, t8)
// Step 141: t7 = x^0x12ab655e9a2ca55660b44d1e5c300
for s := 0; s < 8; s++ {
t7.Square(t7)
}
// Step 142: t6 = x^0x12ab655e9a2ca55660b44d1e5c37b
t6.Mul(t6, t7)
// Step 159: t6 = x^0x2556cabd34594aacc1689a3cb86f60000
for s := 0; s < 17; s++ {
t6.Square(t6)
}
// Step 160: t5 = x^0x2556cabd34594aacc1689a3cb86f6002b
t5.Mul(t5, t6)
// Step 170: t5 = x^0x955b2af4d1652ab305a268f2e1bd800ac00
for s := 0; s < 10; s++ {
t5.Square(t5)
}
// Step 171: t4 = x^0x955b2af4d1652ab305a268f2e1bd800acd5
t4.Mul(t4, t5)
// Step 181: t4 = x^0x2556cabd34594aacc1689a3cb86f6002b35400
for s := 0; s < 10; s++ {
t4.Square(t4)
}
// Step 182: t4 = x^0x2556cabd34594aacc1689a3cb86f6002b354ed
t4.Mul(t3, t4)
// Step 190: t4 = x^0x2556cabd34594aacc1689a3cb86f6002b354ed00
for s := 0; s < 8; s++ {
t4.Square(t4)
}
// Step 191: t3 = x^0x2556cabd34594aacc1689a3cb86f6002b354eded
t3.Mul(t3, t4)
// Step 192: t2 = x^0x2556cabd34594aacc1689a3cb86f6002b354edfd
t2.Mul(t2, t3)
// Step 195: t2 = x^0x12ab655e9a2ca55660b44d1e5c37b00159aa76fe8
for s := 0; s < 3; s++ {
t2.Square(t2)
}
// Step 196: t1 = x^0x12ab655e9a2ca55660b44d1e5c37b00159aa76fed
t1.Mul(t1, t2)
// Step 231: t1 = x^0x955b2af4d1652ab305a268f2e1bd800acd53b7f6800000000
for s := 0; s < 35; s++ {
t1.Square(t1)
}
// Step 232: t0 = x^0x955b2af4d1652ab305a268f2e1bd800acd53b7f6800000085
t0.Mul(t0, t1)
// Step 241: t0 = x^0x12ab655e9a2ca55660b44d1e5c37b00159aa76fed00000010a00
for s := 0; s < 9; s++ {
t0.Square(t0)
}
// Step 242: z = x^0x12ab655e9a2ca55660b44d1e5c37b00159aa76fed00000010a11
z.Mul(z, t0)
return z
}
// expByLegendreExp is equivalent to z.Exp(x, 955b2af4d1652ab305a268f2e1bd800acd53b7f680000008508c00000000000)
//
// uses github.com/mmcloughlin/addchain v0.4.0 to generate a shorter addition chain
func (z *Element) expByLegendreExp(x Element) *Element {
// addition chain:
//
// _10 = 2*1
// _11 = 1 + _10
// _101 = _10 + _11
// _110 = 1 + _101
// _1000 = _10 + _110
// _10000 = 2*_1000
// _10110 = _110 + _10000
// _100000 = 2*_10000
// _100011 = _11 + _100000
// _101011 = _1000 + _100011
// _101101 = _10 + _101011
// _1011010 = 2*_101101
// _1011011 = 1 + _1011010
// _1111011 = _100000 + _1011011
// _10000101 = _101011 + _1011010
// _10001011 = _110 + _10000101
// _10100101 = _100000 + _10000101
// _10101011 = _110 + _10100101
// _11000001 = _10110 + _10101011
// _11000011 = _10 + _11000001
// _11010001 = _10000 + _11000001
// _11010011 = _10 + _11010001
// _11010101 = _10 + _11010011
// _11100101 = _10000 + _11010101
// _11101101 = _1000 + _11100101
// i45 = ((_10000101 + _10100101) << 7 + _1011011) << 10 + _10101011
// i74 = ((i45 << 8 + _11010011) << 9 + _10001011) << 10
// i94 = ((_10100101 + i74) << 7 + _101011) << 10 + _11000001
// i123 = ((i94 << 9 + _11010001) << 10 + _11010001) << 8
// i142 = ((_11100101 + i123) << 8 + _11000011) << 8 + _1111011
// i181 = ((i142 << 17 + _101011) << 10 + _11010101) << 10
// i195 = ((_11101101 + i181) << 8 + _11101101 + _10000) << 3
// i243 = ((_101 + i195) << 35 + _10000101) << 10 + _100011
// return i243 << 46
//
// Operations: 247 squares 42 multiplies
// Allocate Temporaries.
var (
t0 = new(Element)
t1 = new(Element)
t2 = new(Element)
t3 = new(Element)
t4 = new(Element)
t5 = new(Element)
t6 = new(Element)
t7 = new(Element)
t8 = new(Element)
t9 = new(Element)
t10 = new(Element)
t11 = new(Element)
t12 = new(Element)
t13 = new(Element)
t14 = new(Element)
t15 = new(Element)
t16 = new(Element)
)
// var t0,t1,t2,t3,t4,t5,t6,t7,t8,t9,t10,t11,t12,t13,t14,t15,t16 Element
// Step 1: t4 = x^0x2
t4.Square(&x)
// Step 2: z = x^0x3
z.Mul(&x, t4)
// Step 3: t1 = x^0x5
t1.Mul(t4, z)
// Step 4: t8 = x^0x6
t8.Mul(&x, t1)
// Step 5: t3 = x^0x8
t3.Mul(t4, t8)
// Step 6: t2 = x^0x10
t2.Square(t3)
// Step 7: t7 = x^0x16
t7.Mul(t8, t2)
// Step 8: t9 = x^0x20
t9.Square(t2)
// Step 9: z = x^0x23
z.Mul(z, t9)
// Step 10: t5 = x^0x2b
t5.Mul(t3, z)
// Step 11: t0 = x^0x2d
t0.Mul(t4, t5)
// Step 12: t0 = x^0x5a
t0.Square(t0)
// Step 13: t15 = x^0x5b
t15.Mul(&x, t0)
// Step 14: t6 = x^0x7b
t6.Mul(t9, t15)
// Step 15: t0 = x^0x85
t0.Mul(t5, t0)
// Step 16: t12 = x^0x8b
t12.Mul(t8, t0)
// Step 17: t11 = x^0xa5
t11.Mul(t9, t0)
// Step 18: t14 = x^0xab
t14.Mul(t8, t11)
// Step 19: t10 = x^0xc1
t10.Mul(t7, t14)
// Step 20: t7 = x^0xc3
t7.Mul(t4, t10)
// Step 21: t9 = x^0xd1
t9.Mul(t2, t10)
// Step 22: t13 = x^0xd3
t13.Mul(t4, t9)
// Step 23: t4 = x^0xd5
t4.Mul(t4, t13)
// Step 24: t8 = x^0xe5
t8.Mul(t2, t4)
// Step 25: t3 = x^0xed
t3.Mul(t3, t8)
// Step 26: t16 = x^0x12a
t16.Mul(t0, t11)
// Step 33: t16 = x^0x9500
for s := 0; s < 7; s++ {
t16.Square(t16)
}
// Step 34: t15 = x^0x955b
t15.Mul(t15, t16)
// Step 44: t15 = x^0x2556c00
for s := 0; s < 10; s++ {
t15.Square(t15)
}
// Step 45: t14 = x^0x2556cab
t14.Mul(t14, t15)
// Step 53: t14 = x^0x2556cab00
for s := 0; s < 8; s++ {
t14.Square(t14)
}
// Step 54: t13 = x^0x2556cabd3
t13.Mul(t13, t14)
// Step 63: t13 = x^0x4aad957a600
for s := 0; s < 9; s++ {
t13.Square(t13)
}
// Step 64: t12 = x^0x4aad957a68b
t12.Mul(t12, t13)
// Step 74: t12 = x^0x12ab655e9a2c00
for s := 0; s < 10; s++ {
t12.Square(t12)
}
// Step 75: t11 = x^0x12ab655e9a2ca5
t11.Mul(t11, t12)
// Step 82: t11 = x^0x955b2af4d165280
for s := 0; s < 7; s++ {
t11.Square(t11)
}
// Step 83: t11 = x^0x955b2af4d1652ab
t11.Mul(t5, t11)
// Step 93: t11 = x^0x2556cabd34594aac00
for s := 0; s < 10; s++ {
t11.Square(t11)
}
// Step 94: t10 = x^0x2556cabd34594aacc1
t10.Mul(t10, t11)
// Step 103: t10 = x^0x4aad957a68b295598200
for s := 0; s < 9; s++ {
t10.Square(t10)
}
// Step 104: t10 = x^0x4aad957a68b2955982d1
t10.Mul(t9, t10)
// Step 114: t10 = x^0x12ab655e9a2ca55660b4400
for s := 0; s < 10; s++ {
t10.Square(t10)
}
// Step 115: t9 = x^0x12ab655e9a2ca55660b44d1
t9.Mul(t9, t10)
// Step 123: t9 = x^0x12ab655e9a2ca55660b44d100
for s := 0; s < 8; s++ {
t9.Square(t9)
}
// Step 124: t8 = x^0x12ab655e9a2ca55660b44d1e5
t8.Mul(t8, t9)
// Step 132: t8 = x^0x12ab655e9a2ca55660b44d1e500
for s := 0; s < 8; s++ {
t8.Square(t8)
}
// Step 133: t7 = x^0x12ab655e9a2ca55660b44d1e5c3
t7.Mul(t7, t8)
// Step 141: t7 = x^0x12ab655e9a2ca55660b44d1e5c300
for s := 0; s < 8; s++ {
t7.Square(t7)
}
// Step 142: t6 = x^0x12ab655e9a2ca55660b44d1e5c37b
t6.Mul(t6, t7)
// Step 159: t6 = x^0x2556cabd34594aacc1689a3cb86f60000
for s := 0; s < 17; s++ {
t6.Square(t6)
}
// Step 160: t5 = x^0x2556cabd34594aacc1689a3cb86f6002b
t5.Mul(t5, t6)
// Step 170: t5 = x^0x955b2af4d1652ab305a268f2e1bd800ac00
for s := 0; s < 10; s++ {
t5.Square(t5)
}
// Step 171: t4 = x^0x955b2af4d1652ab305a268f2e1bd800acd5
t4.Mul(t4, t5)
// Step 181: t4 = x^0x2556cabd34594aacc1689a3cb86f6002b35400
for s := 0; s < 10; s++ {
t4.Square(t4)
}
// Step 182: t4 = x^0x2556cabd34594aacc1689a3cb86f6002b354ed
t4.Mul(t3, t4)
// Step 190: t4 = x^0x2556cabd34594aacc1689a3cb86f6002b354ed00
for s := 0; s < 8; s++ {
t4.Square(t4)
}
// Step 191: t3 = x^0x2556cabd34594aacc1689a3cb86f6002b354eded
t3.Mul(t3, t4)
// Step 192: t2 = x^0x2556cabd34594aacc1689a3cb86f6002b354edfd
t2.Mul(t2, t3)
// Step 195: t2 = x^0x12ab655e9a2ca55660b44d1e5c37b00159aa76fe8
for s := 0; s < 3; s++ {
t2.Square(t2)
}
// Step 196: t1 = x^0x12ab655e9a2ca55660b44d1e5c37b00159aa76fed
t1.Mul(t1, t2)
// Step 231: t1 = x^0x955b2af4d1652ab305a268f2e1bd800acd53b7f6800000000
for s := 0; s < 35; s++ {
t1.Square(t1)
}
// Step 232: t0 = x^0x955b2af4d1652ab305a268f2e1bd800acd53b7f6800000085
t0.Mul(t0, t1)
// Step 242: t0 = x^0x2556cabd34594aacc1689a3cb86f6002b354edfda00000021400
for s := 0; s < 10; s++ {
t0.Square(t0)
}
// Step 243: z = x^0x2556cabd34594aacc1689a3cb86f6002b354edfda00000021423
z.Mul(z, t0)
// Step 289: z = x^0x955b2af4d1652ab305a268f2e1bd800acd53b7f680000008508c00000000000
for s := 0; s < 46; s++ {
z.Square(z)
}
return z
}