@@ -386,14 +386,15 @@ func PairingCheckFixedQ(P []G1Affine, lines [][2][len(LoopCounter) - 1]LineEvalu
386
386
func PrecomputeLines (Q G2Affine ) (PrecomputedLines [2 ][len (LoopCounter ) - 1 ]LineEvaluationAff ) {
387
387
var accQ G2Affine
388
388
accQ .Set (& Q )
389
-
390
389
n := len (LoopCounter )
391
- for i := n - 2 ; i >= 0 ; i -- {
392
- accQ .doubleStep (& PrecomputedLines [0 ][i ])
390
+ // i = n - 2
391
+ accQ .doubleStep (& PrecomputedLines [0 ][n - 2 ])
392
+ accQ .addStep (& PrecomputedLines [1 ][n - 2 ], & Q )
393
+ for i := n - 3 ; i >= 0 ; i -- {
393
394
if LoopCounter [i ] == 0 {
394
- continue
395
+ accQ . doubleStep ( & PrecomputedLines [ 0 ][ i ])
395
396
} else {
396
- accQ .addStep ( & PrecomputedLines [1 ][i ], & Q )
397
+ accQ .doubleAndAddStep ( & PrecomputedLines [ 0 ][ i ], & PrecomputedLines [1 ][i ], & Q )
397
398
}
398
399
}
399
400
return PrecomputedLines
@@ -541,3 +542,49 @@ func (p *G2Affine) addStep(evaluations *LineEvaluationAff, a *G2Affine) {
541
542
p .X .Set (& xr )
542
543
p .Y .Set (& yr )
543
544
}
545
+
546
+ func (p * G2Affine ) doubleAndAddStep (evaluations1 , evaluations2 * LineEvaluationAff , a * G2Affine ) {
547
+ var n , d , l1 , x3 , l2 , x4 , y4 fptower.E2
548
+
549
+ // compute λ1 = (y2-y1)/(x2-x1)
550
+ n .Sub (& p .Y , & a .Y )
551
+ d .Sub (& p .X , & a .X )
552
+ l1 .Div (& n , & d )
553
+
554
+ // compute x3 =λ1²-x1-x2
555
+ x3 .Square (& l1 )
556
+ x3 .Sub (& x3 , & p .X )
557
+ x3 .Sub (& x3 , & a .X )
558
+
559
+ // omit y3 computation
560
+
561
+ // compute line1
562
+ evaluations1 .R0 .Set (& l1 )
563
+ evaluations1 .R1 .Mul (& l1 , & p .X )
564
+ evaluations1 .R1 .Sub (& evaluations1 .R1 , & p .Y )
565
+
566
+ // compute λ2 = -λ1-2y1/(x3-x1)
567
+ n .Double (& p .Y )
568
+ d .Sub (& x3 , & p .X )
569
+ l2 .Div (& n , & d )
570
+ l2 .Add (& l2 , & l1 )
571
+ l2 .Neg (& l2 )
572
+
573
+ // compute x4 = λ2²-x1-x3
574
+ x4 .Square (& l2 )
575
+ x4 .Sub (& x4 , & p .X )
576
+ x4 .Sub (& x4 , & x3 )
577
+
578
+ // compute y4 = λ2(x1 - x4)-y1
579
+ y4 .Sub (& p .X , & x4 )
580
+ y4 .Mul (& l2 , & y4 )
581
+ y4 .Sub (& y4 , & p .Y )
582
+
583
+ // compute line2
584
+ evaluations2 .R0 .Set (& l2 )
585
+ evaluations2 .R1 .Mul (& l2 , & p .X )
586
+ evaluations2 .R1 .Sub (& evaluations2 .R1 , & p .Y )
587
+
588
+ p .X .Set (& x4 )
589
+ p .Y .Set (& y4 )
590
+ }
0 commit comments