@@ -154,6 +154,7 @@ func (p *ipaProver) Prove() (*IPA, error) {
154154 }
155155 // compute first challenge
156156 x := p .Curve .HashToZr (raw )
157+
157158 // compute a commitment to inner product value and the vectors
158159 C := p .Q .Mul (p .Curve .ModMul (x , p .InnerProduct , p .Curve .GroupOrder ))
159160 C .Add (p .Commitment )
@@ -172,14 +173,13 @@ func (p *ipaProver) Prove() (*IPA, error) {
172173// of the left vector and right is a function of right vector.
173174// Both vectors are committed in com which is passed as a parameter to reduce
174175func (p * ipaProver ) reduce (X , com * mathlib.G1 ) (* mathlib.Zr , * mathlib.Zr , []* mathlib.G1 , []* mathlib.G1 , error ) {
175- var leftGen , rightGen []* mathlib.G1
176- var left , right []* mathlib.Zr
177-
178- leftGen = p .LeftGenerators
179- rightGen = p .RightGenerators
176+ leftGen := make ([]* mathlib.G1 , len (p .LeftGenerators ))
177+ copy (leftGen , p .LeftGenerators )
178+ rightGen := make ([]* mathlib.G1 , len (p .RightGenerators ))
179+ copy (rightGen , p .RightGenerators )
180180
181- left = p .leftVector
182- right = p .rightVector
181+ left : = p .leftVector
182+ right : = p .rightVector
183183
184184 LArray := make ([]* mathlib.G1 , p .NumberOfRounds )
185185 RArray := make ([]* mathlib.G1 , p .NumberOfRounds )
@@ -324,8 +324,7 @@ func (v *ipaVerifier) Verify(proof *IPA) error {
324324 xSquareInv := xSquare .Copy ()
325325 xSquareInv .InvModP (v .Curve .GroupOrder )
326326 // compute a commitment to the reduced vectors and their inner product
327- CPrime := proof .L [i ].Mul (xSquare )
328- CPrime .Add (proof .R [i ].Mul (xSquareInv ))
327+ CPrime := proof .L [i ].Mul2 (xSquare , proof .R [i ], xSquareInv )
329328 CPrime .Add (C )
330329 C = CPrime .Copy ()
331330 // reduce the generators by 1/2, as a function of the old generators and x and 1/x
@@ -360,15 +359,14 @@ func reduceVectors(left, right []*mathlib.Zr, x, xInv *mathlib.Zr, c *mathlib.Cu
360359// reduceGenerators reduces the number of generators passed in the parameters by 1/2,
361360// as a function of the old generators, x and 1/x
362361func reduceGenerators (leftGen , rightGen []* mathlib.G1 , x , xInv * mathlib.Zr ) ([]* mathlib.G1 , []* mathlib.G1 ) {
363- leftGenPrime := make ([]* mathlib.G1 , len (leftGen )/ 2 )
364- rightGenPrime := make ([]* mathlib.G1 , len (rightGen )/ 2 )
365- for i := 0 ; i < len (leftGenPrime ); i ++ {
362+ l := len (leftGen ) / 2
363+ for i := 0 ; i < l ; i ++ {
366364 // G_i = G_i^x*G_{i+len(left)/2}^{1/x}
367- leftGenPrime [i ] = leftGen [i ].Mul2 (xInv , leftGen [i + len ( leftGenPrime ) ], x )
365+ leftGen [i ] = leftGen [i ].Mul2 (xInv , leftGen [i + l ], x )
368366 // H_i = H_i^{1/x}*H_{i+len(right)/2}^{x}
369- rightGenPrime [i ] = rightGen [i ].Mul2 (x , rightGen [i + len ( rightGenPrime ) ], xInv )
367+ rightGen [i ] = rightGen [i ].Mul2 (x , rightGen [i + l ], xInv )
370368 }
371- return leftGenPrime , rightGenPrime
369+ return leftGen [: l ], rightGen [: l ]
372370}
373371
374372func innerProduct (left []* mathlib.Zr , right []* mathlib.Zr , c * mathlib.Curve ) * mathlib.Zr {
0 commit comments