@@ -124,6 +124,11 @@ class WeierstrassCurve:
124
124
Gx : int # x-coordinate of the generator point
125
125
Gy : int # y-coordinate of the generator point
126
126
swu_params : SWUParams
127
+ eigen_value : int | None # Endomorphism eigenvalue
128
+ third_root_of_unity : int | None # Endomorphism image
129
+
130
+ def is_endomorphism_available (self ) -> bool :
131
+ return self .eigen_value is not None and self .third_root_of_unity is not None
127
132
128
133
def to_cairo_zero (self ) -> str :
129
134
code = f"namespace { self .cairo_zero_namespace_name } {{\n "
@@ -187,13 +192,17 @@ def __init__(
187
192
Gx : int ,
188
193
Gy : int ,
189
194
swu_params : SWUParams ,
195
+ eigen_value : int | None = None ,
196
+ third_root_of_unity : int | None = None ,
190
197
):
191
198
assert a_twisted != 0 and d_twisted != 0 and a_twisted != d_twisted
192
199
# Set attributes
193
200
object .__setattr__ (self , "d_twisted" , d_twisted )
194
201
object .__setattr__ (self , "a_twisted" , a_twisted )
195
202
object .__setattr__ (self , "p" , p )
196
203
object .__setattr__ (self , "swu_params" , swu_params )
204
+ object .__setattr__ (self , "eigen_value" , eigen_value )
205
+ object .__setattr__ (self , "third_root_of_unity" , third_root_of_unity )
197
206
# Calculate Weierstrass parameters
198
207
a = (
199
208
- 1
@@ -220,6 +229,8 @@ def __init__(
220
229
fp_generator ,
221
230
* (self .to_weierstrass (Gx , Gy )),
222
231
swu_params ,
232
+ eigen_value ,
233
+ third_root_of_unity ,
223
234
)
224
235
225
236
def to_weierstrass (self , x_twisted , y_twisted ):
@@ -356,6 +367,8 @@ def bit(value, index):
356
367
0x90689D0585FF075EC9E99AD690C3395BC4B313370B38EF355ACDADCD122975B ,
357
368
),
358
369
swu_params = None ,
370
+ eigen_value = 0xB3C4D79D41A917585BFC41088D8DAAA78B17EA66B99C90DD ,
371
+ third_root_of_unity = 0x59E26BCEA0D48BACD4F263F1ACDB5C4F5763473177FFFFFE ,
359
372
),
360
373
BLS12_381_ID : PairingCurve (
361
374
cairo_zero_namespace_name = "bls" ,
@@ -406,6 +419,8 @@ def bit(value, index):
406
419
B = 0x12E2908D11688030018B12E8753EEE3B2016C1F0F24F4070A0B9C14FCEF35EF55A23215A316CEAA5D1CC48E98E172BE0 ,
407
420
Z = 11 ,
408
421
),
422
+ eigen_value = 0xAC45A4010001A40200000000FFFFFFFF ,
423
+ third_root_of_unity = 0x1A0111EA397FE699EC02408663D4DE85AA0D857D89759AD4897D29650FB85F9B409427EB4F49FFFD8BFD00000000AAAC ,
409
424
),
410
425
SECP256K1_ID : WeierstrassCurve (
411
426
cairo_zero_namespace_name = "secp256k1" ,
@@ -419,6 +434,8 @@ def bit(value, index):
419
434
Gx = 0x79BE667EF9DCBBAC55A06295CE870B07029BFCDB2DCE28D959F2815B16F81798 ,
420
435
Gy = 0x483ADA7726A3C4655DA4FBFC0E1108A8FD17B448A68554199C47D08FFB10D4B8 ,
421
436
swu_params = None ,
437
+ eigen_value = 0x5363AD4CC05C30E0A5261C028812645A122E22EA20816678DF02967C1B23BD72 ,
438
+ third_root_of_unity = 0x7AE96A2B657C07106E64479EAC3434E99CF0497512F58995C1396C28719501EE ,
422
439
),
423
440
SECP256R1_ID : WeierstrassCurve (
424
441
cairo_zero_namespace_name = "secp256r1" ,
@@ -432,6 +449,8 @@ def bit(value, index):
432
449
Gx = 0x6B17D1F2E12C4247F8BCE6E563A440F277037D812DEB33A0F4A13945D898C296 ,
433
450
Gy = 0x4FE342E2FE1A7F9B8EE7EB4A7C0F9E162BCE33576B315ECECBB6406837BF51F5 ,
434
451
swu_params = None ,
452
+ eigen_value = None ,
453
+ third_root_of_unity = None ,
435
454
),
436
455
ED25519_ID : TwistedEdwardsCurve (
437
456
cairo_zero_namespace_name = "ED25519" , # See https://neuromancer.sk/std/other/Ed25519
@@ -445,6 +464,8 @@ def bit(value, index):
445
464
Gx = 0x216936D3CD6E53FEC0A4E231FDD6DC5C692CC7609525A7B2C9562D608F25D51A ,
446
465
Gy = 0x6666666666666666666666666666666666666666666666666666666666666658 ,
447
466
swu_params = None ,
467
+ eigen_value = None ,
468
+ third_root_of_unity = None ,
448
469
),
449
470
GRUMPKIN_ID : WeierstrassCurve (
450
471
cairo_zero_namespace_name = "grumpkin" ,
@@ -458,6 +479,8 @@ def bit(value, index):
458
479
Gx = 0x1 ,
459
480
Gy = 0x2CF135E7506A45D632D270D45F1181294833FC48D823F272C ,
460
481
swu_params = None ,
482
+ eigen_value = None ,
483
+ third_root_of_unity = None ,
461
484
),
462
485
}
463
486
@@ -1293,6 +1316,37 @@ def recode_naf_bits(lst):
1293
1316
if __name__ == "__main__" :
1294
1317
r = recode_naf_bits (jy00 (6 * 0x44E992B44A6909F1 + 2 )[2 :])
1295
1318
print (r , len (r ))
1319
+ from garaga .hints .io import int_to_u384
1296
1320
1297
1321
# bls = [int(x) for x in bin(0xD201000000010000)[2:]][2:]
1298
1322
# recode_naf_bits(bls)
1323
+
1324
+ def print_nbits_and_nG_glv_fake_glv ():
1325
+ for curve_id in CURVES :
1326
+ curve : WeierstrassCurve = CURVES [curve_id ]
1327
+ if curve .is_endomorphism_available ():
1328
+ nbits = curve .n .bit_length () // 4 + 9
1329
+ print (
1330
+ f"Curve { curve_id } : { nbits } , { G1Point .get_nG (CurveID (curve_id ), 2 ** (nbits - 1 )).to_cairo_1 ()} "
1331
+ )
1332
+
1333
+ print_nbits_and_nG_glv_fake_glv ()
1334
+
1335
+ def print_min_one_order ():
1336
+ for curve_id in CURVES :
1337
+ curve : WeierstrassCurve = CURVES [curve_id ]
1338
+ print (f"Curve { curve_id } : min_one_order: { int_to_u384 (- 1 % curve .n )} " )
1339
+
1340
+ print_min_one_order ()
1341
+
1342
+ print ()
1343
+
1344
+ def print_third_root_of_unity ():
1345
+ for curve_id in CURVES :
1346
+ curve : WeierstrassCurve = CURVES [curve_id ]
1347
+ if curve .is_endomorphism_available ():
1348
+ print (
1349
+ f"Curve { curve_id } : third_root_of_unity: { int_to_u384 (curve .third_root_of_unity )} "
1350
+ )
1351
+
1352
+ print_third_root_of_unity ()
0 commit comments