@@ -122,7 +122,11 @@ pub fn gen_random_babyjub_value() -> BigUint {
122122 }
123123
124124 // Compute the private key modulo 2^253 (as per the TS implementation)
125- let modulo = BigUint :: from ( 2u32 ) . pow ( 253 ) ;
125+ // Precomputed: 2^253 = 14474011154664524427946373126085988481658748083205070504932198000989141204992
126+ const MODULO_2_253 : & str =
127+ "14474011154664524427946373126085988481658748083205070504932198000989141204992" ;
128+ let modulo =
129+ BigUint :: parse_bytes ( MODULO_2_253 . as_bytes ( ) , 10 ) . expect ( "Failed to parse modulo constant" ) ;
126130 & rand_val % & modulo
127131}
128132
@@ -346,17 +350,21 @@ mod tests {
346350
347351 let expected_base_point = EdwardsAffine :: new_unchecked ( BASE_X , BASE_Y ) ;
348352 let cofactor = EdFr :: from_be_bytes_mod_order ( & [ BabyJubjubConfig :: COFACTOR [ 0 ] as u8 ] ) ;
349- let calculated_base_point = ( g * cofactor) . into_affine ( ) ;
353+ let calculated_base_point = g * cofactor;
350354
351- assert_eq ! ( calculated_base_point, expected_base_point) ;
355+ assert_eq ! (
356+ calculated_base_point,
357+ EdwardsProjective :: from( expected_base_point)
358+ ) ;
352359 }
353360
354361 #[ test]
355362 fn test_base_point_order ( ) {
356363 let base_point = EdwardsAffine :: new_unchecked ( GENERATOR_X , GENERATOR_Y ) ;
357364
358- let result = ( base_point * SUBGROUP_ORDER ) . into_affine ( ) ;
359- let identity = EdwardsAffine :: new_unchecked ( Fq :: zero ( ) , Fq :: ONE ) ;
365+ let result = base_point * SUBGROUP_ORDER ;
366+ // Identity in projective coordinates is (0, 1, 0, 1) for twisted Edwards
367+ let identity = EdwardsProjective :: new ( Fq :: zero ( ) , Fq :: ONE , Fq :: zero ( ) , Fq :: ONE ) ;
360368
361369 assert_eq ! ( result, identity) ;
362370 }
@@ -365,7 +373,10 @@ mod tests {
365373 fn test_base8 ( ) {
366374 let base8_point = base8 ( ) ;
367375 let expected = EdwardsAffine :: new_unchecked ( BASE_X , BASE_Y ) ;
368- assert_eq ! ( base8_point, expected) ;
376+ assert_eq ! (
377+ EdwardsProjective :: from( base8_point) ,
378+ EdwardsProjective :: from( expected)
379+ ) ;
369380 assert ! ( base8_point. is_on_curve( ) ) ;
370381 }
371382
@@ -387,9 +398,9 @@ mod tests {
387398 ) ;
388399
389400 let result = add_point ( & p1, & p2) ;
390- let expected = ( p1 + p2) . into_affine ( ) ;
401+ let expected = p1 + p2;
391402
392- assert_eq ! ( result, expected) ;
403+ assert_eq ! ( EdwardsProjective :: from ( result) , expected) ;
393404 assert ! ( result. is_on_curve( ) ) ;
394405 }
395406
@@ -399,9 +410,9 @@ mod tests {
399410 let scalar = EdFr :: from ( 324u64 ) ;
400411
401412 let result = mul_point_escalar ( & base8_point, scalar) ;
402- let expected = ( EdwardsProjective :: from ( base8_point) * scalar) . into_affine ( ) ;
413+ let expected = EdwardsProjective :: from ( base8_point) * scalar;
403414
404- assert_eq ! ( result, expected) ;
415+ assert_eq ! ( EdwardsProjective :: from ( result) , expected) ;
405416 assert ! ( result. is_on_curve( ) ) ;
406417 }
407418
@@ -421,7 +432,10 @@ mod tests {
421432 let packed = pack_point ( & point) ;
422433 let unpacked = unpack_point ( & packed) . expect ( "Failed to unpack point" ) ;
423434
424- assert_eq ! ( point, unpacked) ;
435+ assert_eq ! (
436+ EdwardsProjective :: from( point) ,
437+ EdwardsProjective :: from( unpacked)
438+ ) ;
425439 assert ! ( unpacked. is_on_curve( ) ) ;
426440 }
427441
@@ -435,7 +449,10 @@ mod tests {
435449 let packed = pack_point ( & public_key) ;
436450 let unpacked = unpack_point ( & packed) . expect ( "Failed to unpack point" ) ;
437451
438- assert_eq ! ( public_key, unpacked) ;
452+ assert_eq ! (
453+ EdwardsProjective :: from( public_key) ,
454+ EdwardsProjective :: from( unpacked)
455+ ) ;
439456 assert ! ( unpacked. is_on_curve( ) ) ;
440457 }
441458
@@ -452,7 +469,12 @@ mod tests {
452469 let packed = pack_point ( & point) ;
453470 let unpacked = unpack_point ( & packed) . expect ( "Failed to unpack point" ) ;
454471
455- assert_eq ! ( point, unpacked, "Failed for scalar {}" , scalar_val) ;
472+ assert_eq ! (
473+ EdwardsProjective :: from( point) ,
474+ EdwardsProjective :: from( unpacked) ,
475+ "Failed for scalar {}" ,
476+ scalar_val
477+ ) ;
456478 assert ! ( unpacked. is_on_curve( ) ) ;
457479 }
458480 }
@@ -508,7 +530,8 @@ mod tests {
508530 // Unpack the point and verify it matches
509531 let unpacked_point = unpack_point ( & packed_point) . expect ( "Failed to unpack point" ) ;
510532 assert_eq ! (
511- public_key, unpacked_point,
533+ EdwardsProjective :: from( public_key) ,
534+ EdwardsProjective :: from( unpacked_point) ,
512535 "Unpacked point should match original"
513536 ) ;
514537
0 commit comments