@@ -6,11 +6,9 @@ use ark_ec::bn::g2::G2Prepared as ark_G2Prepared;
66use ark_ec:: bn:: { BnConfig , TwistType } ;
77use ark_ec:: pairing:: { MillerLoopOutput , Pairing , PairingOutput } ;
88use ark_ec:: short_weierstrass:: Affine ;
9- use ark_ec:: short_weierstrass:: SWCurveConfig ;
109use ark_ec:: { AffineRepr , CurveGroup } ;
1110use ark_ff:: Field ;
1211use ark_ff:: { AdditiveGroup , CyclotomicMultSubgroup } ;
13- use ark_std:: cfg_chunks_mut;
1412use itertools:: Itertools ;
1513use num_traits:: One ;
1614
@@ -27,63 +25,6 @@ pub struct G2Prepared {
2725// aka. line in miller loop.
2826pub type EllCoeff = ( ark_bn254:: Fq2 , ark_bn254:: Fq2 , ark_bn254:: Fq2 ) ;
2927
30- #[ derive( Clone , Copy , Debug ) ]
31- struct G2HomProjective {
32- x : ark_bn254:: Fq2 ,
33- y : ark_bn254:: Fq2 ,
34- z : ark_bn254:: Fq2 ,
35- }
36-
37- impl G2HomProjective {
38- fn double_in_place ( & mut self , two_inv : & ark_bn254:: Fq ) -> EllCoeff {
39- // Formula for line function when working with
40- // homogeneous projective coordinates.
41-
42- let mut a = self . x * self . y ;
43- a. mul_assign_by_fp ( two_inv) ;
44- let b = self . y . square ( ) ;
45- let c = self . z . square ( ) ;
46- let e = ark_bn254:: g2:: Config :: COEFF_B * ( c. double ( ) + c) ;
47- let f = e. double ( ) + e;
48- let mut g = b + f;
49- g. mul_assign_by_fp ( two_inv) ;
50- let h = ( self . y + self . z ) . square ( ) - ( b + c) ;
51- let i = e - b;
52- let j = self . x . square ( ) ;
53- let e_square = e. square ( ) ;
54-
55- self . x = a * ( b - f) ;
56- self . y = g. square ( ) - ( e_square. double ( ) + e_square) ;
57- self . z = b * h;
58- match ark_bn254:: Config :: TWIST_TYPE {
59- TwistType :: M => ( i, j. double ( ) + j, -h) ,
60- TwistType :: D => ( -h, j. double ( ) + j, i) ,
61- }
62- }
63-
64- fn add_in_place ( & mut self , q : & ark_bn254:: G2Affine ) -> EllCoeff {
65- // Formula for line function when working with
66- // homogeneous projective coordinates.
67- let theta = self . y - ( q. y * self . z ) ;
68- let lambda = self . x - ( q. x * self . z ) ;
69- let c = theta. square ( ) ;
70- let d = lambda. square ( ) ;
71- let e = lambda * d;
72- let f = self . z * c;
73- let g = self . x * d;
74- let h = e + f - g. double ( ) ;
75- self . x = lambda * h;
76- self . y = theta * ( g - h) - ( e * self . y ) ;
77- self . z *= e;
78- let j = theta * q. x - ( lambda * q. y ) ;
79-
80- match ark_bn254:: Config :: TWIST_TYPE {
81- TwistType :: M => ( j, -theta, lambda) ,
82- TwistType :: D => ( lambda, -theta, j) ,
83- }
84- }
85- }
86-
8728impl Default for G2Prepared {
8829 fn default ( ) -> Self {
8930 Self :: from ( ark_bn254:: G2Affine :: generator ( ) )
@@ -323,7 +264,8 @@ impl AffinePairing for BnAffinePairing {
323264 } )
324265 . collect :: < Vec < _ > > ( ) ;
325266
326- let mut f = cfg_chunks_mut ! ( pairs, 4 )
267+ let mut f = pairs
268+ . chunks_mut ( 4 )
327269 . map ( |pairs| {
328270 let mut f = ark_bn254:: Fq12 :: one ( ) ;
329271 for i in ( 1 ..Config :: ATE_LOOP_COUNT . len ( ) ) . rev ( ) {
@@ -381,43 +323,8 @@ impl AffinePairing for BnAffinePairing {
381323#[ cfg( test) ]
382324mod tests {
383325 use super :: * ;
384- use ark_bn254:: { Fq , Fq2 } ;
385-
386- use ark_ec:: short_weierstrass:: SWCurveConfig ;
387- use ark_ff:: { Field , UniformRand } ;
326+ use ark_ff:: UniformRand ;
388327 use ark_std:: test_rng;
389- use num_traits:: One ;
390-
391- use super :: G2HomProjective ;
392- use ark_ff:: AdditiveGroup ;
393-
394- #[ test]
395- fn test_double_in_place ( ) {
396- let mut rng = test_rng ( ) ;
397- let two_inv = Fq :: one ( ) . double ( ) . inverse ( ) . unwrap ( ) ;
398- let mut r = G2HomProjective {
399- x : Fq2 :: rand ( & mut rng) ,
400- y : Fq2 :: rand ( & mut rng) ,
401- z : Fq2 :: rand ( & mut rng) ,
402- } ;
403-
404- println ! ( "1/2 = {:?}\n \n " , two_inv. to_string( ) ) ;
405- println ! ( "COEFF_B = {}\n \n " , ark_bn254:: g2:: Config :: COEFF_B ) ;
406- println ! ( "before double line:" ) ;
407- println ! ( "r.x = {:?}" , r. x. to_string( ) ) ;
408- println ! ( "r.y = {:?}" , r. y. to_string( ) ) ;
409- println ! ( "r.z = {:?}\n \n " , r. z. to_string( ) ) ;
410-
411- let s = r. double_in_place ( & two_inv) ;
412-
413- println ! ( "after double line:" ) ;
414- println ! ( "r.x = {:?}" , r. x. to_string( ) ) ;
415- println ! ( "r.y = {:?}" , r. y. to_string( ) ) ;
416- println ! ( "r.z = {:?}" , r. z. to_string( ) ) ;
417- println ! ( "s.0 = {:?}" , s. 0 . to_string( ) ) ;
418- println ! ( "s.1 = {:?}" , s. 1 . to_string( ) ) ;
419- println ! ( "s.2 = {:?}" , s. 2 . to_string( ) ) ;
420- }
421328
422329 #[ test]
423330 fn test_affine_vs_projective ( ) {
0 commit comments