From 7eeb48adc07d6ef14a2147c43218246c314514ae Mon Sep 17 00:00:00 2001 From: Arya Tabaie <15056835+Tabaie@users.noreply.github.com> Date: Wed, 18 Dec 2024 18:32:29 -0600 Subject: [PATCH] refactor linearCombCoeffs -> randomMonomials --- backend/groth16/bn254/mpcsetup/phase1.go | 2 +- backend/groth16/bn254/mpcsetup/phase2.go | 2 +- backend/groth16/bn254/mpcsetup/utils.go | 15 ++++++++------- 3 files changed, 10 insertions(+), 9 deletions(-) diff --git a/backend/groth16/bn254/mpcsetup/phase1.go b/backend/groth16/bn254/mpcsetup/phase1.go index 381749980..571043051 100644 --- a/backend/groth16/bn254/mpcsetup/phase1.go +++ b/backend/groth16/bn254/mpcsetup/phase1.go @@ -244,7 +244,7 @@ func multiValueUpdateCheck(a []curve.G1Affine, b []curve.G2Affine, c, d []curve. g1s = append(g1s, d...) g1Num, g1Denom := linearCombinationsG1(g1s, bivariateRandomMonomials(ends...), ends) - g2Num, g2Denom := linearCombinationsG2(b, linearCombCoeffs(len(b))) + g2Num, g2Denom := linearCombinationsG2(b, randomMonomials(len(b))) if !sameRatio(g1Num, g1Denom, g2Num, g2Denom) { return errors.New("multi-value update check failed") diff --git a/backend/groth16/bn254/mpcsetup/phase2.go b/backend/groth16/bn254/mpcsetup/phase2.go index 3d50ef818..b5007e073 100644 --- a/backend/groth16/bn254/mpcsetup/phase2.go +++ b/backend/groth16/bn254/mpcsetup/phase2.go @@ -72,7 +72,7 @@ func (p *Phase2) Verify(next *Phase2) error { return errors.New("contribution size mismatch") } - r := linearCombCoeffs(len(next.Parameters.G1.Z) + len(next.Parameters.G1.PKK) + 1) + r := randomMonomials(len(next.Parameters.G1.Z) + len(next.Parameters.G1.PKK) + 1) verifyContribution := func(update *valueUpdate, g1Denominator, g1Numerator []curve.G1Affine, g2Denominator, g2Numerator *curve.G2Affine, dst byte) error { g1Num := linearCombination(g1Numerator, r) diff --git a/backend/groth16/bn254/mpcsetup/utils.go b/backend/groth16/bn254/mpcsetup/utils.go index 05bb3cf89..14384c7bf 100644 --- a/backend/groth16/bn254/mpcsetup/utils.go +++ b/backend/groth16/bn254/mpcsetup/utils.go @@ -29,21 +29,22 @@ func bitReverse[T any](a []T) { } } -func linearCombCoeffs(n int) []fr.Element { - return bivariateRandomMonomials(n) +// Returns [1, a, a², ..., aᴺ⁻¹ ] for random a +func randomMonomials(N int) []fr.Element { + return bivariateRandomMonomials(N) } // Returns [1, a, a², ..., aᴺ⁻¹ ] -func powers(a *fr.Element, n int) []fr.Element { +func powers(a *fr.Element, N int) []fr.Element { - result := make([]fr.Element, n) - if n >= 1 { + result := make([]fr.Element, N) + if N >= 1 { result[0].SetOne() } - if n >= 2 { + if N >= 2 { result[1].Set(a) } - for i := 2; i < n; i++ { + for i := 2; i < N; i++ { result[i].Mul(&result[i-1], a) } return result