diff --git a/ecc/bls12-377/fr/gkr/gkr.go b/ecc/bls12-377/fr/gkr/gkr.go index 283a47b280..2d579924a6 100644 --- a/ecc/bls12-377/fr/gkr/gkr.go +++ b/ecc/bls12-377/fr/gkr/gkr.go @@ -178,7 +178,7 @@ func (c *eqTimesGateEvalSumcheckClaims) Combine(combinationCoeff fr.Element) pol // define eq_k = aᵏ eq(x_k1, ..., x_kn, *, ..., *) where x_ki are the evaluation points newEq[0].Set(&aI) - c.innerWork(c.eq, newEq, c.evaluationPoints[k]) + c.eqAcc(c.eq, newEq, c.evaluationPoints[k]) // newEq.Eq(c.evaluationPoints[k]) // eqAsPoly := polynomial.Polynomial(c.eq) //just semantics @@ -196,13 +196,11 @@ func (c *eqTimesGateEvalSumcheckClaims) Combine(combinationCoeff fr.Element) pol return c.computeGJ() } -// innerWork sets m to an eq table at q and then adds it to e -// TODO @Tabaie find a better home for this / cleanup -func (c *eqTimesGateEvalSumcheckClaims) innerWork(e, m polynomial.MultiLin, q []fr.Element) { +// eqAcc sets m to an eq table at q and then adds it to e +func (c *eqTimesGateEvalSumcheckClaims) eqAcc(e, m polynomial.MultiLin, q []fr.Element) { n := len(q) //At the end of each iteration, m(h₁, ..., hₙ) = Eq(q₁, ..., qᵢ₊₁, h₁, ..., hᵢ₊₁) - var wgs []*sync.WaitGroup for i := range q { // In the comments we use a 1-based index so q[i] = qᵢ₊₁ // go through all assignments of (b₁, ..., bᵢ) ∈ {0,1}ⁱ const threshold = 1 << 6 @@ -216,7 +214,7 @@ func (c *eqTimesGateEvalSumcheckClaims) innerWork(e, m polynomial.MultiLin, q [] m[j0].Sub(&m[j0], &m[j1]) // Eq(q₁, ..., qᵢ₊₁, b₁, ..., bᵢ, 0) = Eq(q₁, ..., qᵢ, b₁, ..., bᵢ) Eq(qᵢ₊₁, 0) = Eq(q₁, ..., qᵢ, b₁, ..., bᵢ) (1-qᵢ₊₁) } } else { - wgs = append(wgs, c.manager.workers.Submit(k, func(start, end int) { + c.manager.workers.Submit(k, func(start, end int) { for j := start; j < end; j++ { j0 := j << (n - i) // bᵢ₊₁ = 0 j1 := j0 + 1<<(n-1-i) // bᵢ₊₁ = 1 @@ -224,13 +222,10 @@ func (c *eqTimesGateEvalSumcheckClaims) innerWork(e, m polynomial.MultiLin, q [] m[j1].Mul(&q[i], &m[j0]) // Eq(q₁, ..., qᵢ₊₁, b₁, ..., bᵢ, 1) = Eq(q₁, ..., qᵢ, b₁, ..., bᵢ) Eq(qᵢ₊₁, 1) = Eq(q₁, ..., qᵢ, b₁, ..., bᵢ) qᵢ₊₁ m[j0].Sub(&m[j0], &m[j1]) // Eq(q₁, ..., qᵢ₊₁, b₁, ..., bᵢ, 0) = Eq(q₁, ..., qᵢ, b₁, ..., bᵢ) Eq(qᵢ₊₁, 0) = Eq(q₁, ..., qᵢ, b₁, ..., bᵢ) (1-qᵢ₊₁) } - }, 1024)) + }, 1024).Wait() } } - for _, wg := range wgs { - wg.Wait() - } c.manager.workers.Submit(len(e), func(start, end int) { for i := start; i < end; i++ { e[i].Add(&e[i], &m[i]) diff --git a/ecc/bls12-378/fr/gkr/gkr.go b/ecc/bls12-378/fr/gkr/gkr.go index 878ccb5798..1c6c967747 100644 --- a/ecc/bls12-378/fr/gkr/gkr.go +++ b/ecc/bls12-378/fr/gkr/gkr.go @@ -178,7 +178,7 @@ func (c *eqTimesGateEvalSumcheckClaims) Combine(combinationCoeff fr.Element) pol // define eq_k = aᵏ eq(x_k1, ..., x_kn, *, ..., *) where x_ki are the evaluation points newEq[0].Set(&aI) - c.innerWork(c.eq, newEq, c.evaluationPoints[k]) + c.eqAcc(c.eq, newEq, c.evaluationPoints[k]) // newEq.Eq(c.evaluationPoints[k]) // eqAsPoly := polynomial.Polynomial(c.eq) //just semantics @@ -196,13 +196,11 @@ func (c *eqTimesGateEvalSumcheckClaims) Combine(combinationCoeff fr.Element) pol return c.computeGJ() } -// innerWork sets m to an eq table at q and then adds it to e -// TODO @Tabaie find a better home for this / cleanup -func (c *eqTimesGateEvalSumcheckClaims) innerWork(e, m polynomial.MultiLin, q []fr.Element) { +// eqAcc sets m to an eq table at q and then adds it to e +func (c *eqTimesGateEvalSumcheckClaims) eqAcc(e, m polynomial.MultiLin, q []fr.Element) { n := len(q) //At the end of each iteration, m(h₁, ..., hₙ) = Eq(q₁, ..., qᵢ₊₁, h₁, ..., hᵢ₊₁) - var wgs []*sync.WaitGroup for i := range q { // In the comments we use a 1-based index so q[i] = qᵢ₊₁ // go through all assignments of (b₁, ..., bᵢ) ∈ {0,1}ⁱ const threshold = 1 << 6 @@ -216,7 +214,7 @@ func (c *eqTimesGateEvalSumcheckClaims) innerWork(e, m polynomial.MultiLin, q [] m[j0].Sub(&m[j0], &m[j1]) // Eq(q₁, ..., qᵢ₊₁, b₁, ..., bᵢ, 0) = Eq(q₁, ..., qᵢ, b₁, ..., bᵢ) Eq(qᵢ₊₁, 0) = Eq(q₁, ..., qᵢ, b₁, ..., bᵢ) (1-qᵢ₊₁) } } else { - wgs = append(wgs, c.manager.workers.Submit(k, func(start, end int) { + c.manager.workers.Submit(k, func(start, end int) { for j := start; j < end; j++ { j0 := j << (n - i) // bᵢ₊₁ = 0 j1 := j0 + 1<<(n-1-i) // bᵢ₊₁ = 1 @@ -224,13 +222,10 @@ func (c *eqTimesGateEvalSumcheckClaims) innerWork(e, m polynomial.MultiLin, q [] m[j1].Mul(&q[i], &m[j0]) // Eq(q₁, ..., qᵢ₊₁, b₁, ..., bᵢ, 1) = Eq(q₁, ..., qᵢ, b₁, ..., bᵢ) Eq(qᵢ₊₁, 1) = Eq(q₁, ..., qᵢ, b₁, ..., bᵢ) qᵢ₊₁ m[j0].Sub(&m[j0], &m[j1]) // Eq(q₁, ..., qᵢ₊₁, b₁, ..., bᵢ, 0) = Eq(q₁, ..., qᵢ, b₁, ..., bᵢ) Eq(qᵢ₊₁, 0) = Eq(q₁, ..., qᵢ, b₁, ..., bᵢ) (1-qᵢ₊₁) } - }, 1024)) + }, 1024).Wait() } } - for _, wg := range wgs { - wg.Wait() - } c.manager.workers.Submit(len(e), func(start, end int) { for i := start; i < end; i++ { e[i].Add(&e[i], &m[i]) diff --git a/ecc/bls12-381/fr/gkr/gkr.go b/ecc/bls12-381/fr/gkr/gkr.go index 5a042f103d..7de6aa7df7 100644 --- a/ecc/bls12-381/fr/gkr/gkr.go +++ b/ecc/bls12-381/fr/gkr/gkr.go @@ -178,7 +178,7 @@ func (c *eqTimesGateEvalSumcheckClaims) Combine(combinationCoeff fr.Element) pol // define eq_k = aᵏ eq(x_k1, ..., x_kn, *, ..., *) where x_ki are the evaluation points newEq[0].Set(&aI) - c.innerWork(c.eq, newEq, c.evaluationPoints[k]) + c.eqAcc(c.eq, newEq, c.evaluationPoints[k]) // newEq.Eq(c.evaluationPoints[k]) // eqAsPoly := polynomial.Polynomial(c.eq) //just semantics @@ -196,13 +196,11 @@ func (c *eqTimesGateEvalSumcheckClaims) Combine(combinationCoeff fr.Element) pol return c.computeGJ() } -// innerWork sets m to an eq table at q and then adds it to e -// TODO @Tabaie find a better home for this / cleanup -func (c *eqTimesGateEvalSumcheckClaims) innerWork(e, m polynomial.MultiLin, q []fr.Element) { +// eqAcc sets m to an eq table at q and then adds it to e +func (c *eqTimesGateEvalSumcheckClaims) eqAcc(e, m polynomial.MultiLin, q []fr.Element) { n := len(q) //At the end of each iteration, m(h₁, ..., hₙ) = Eq(q₁, ..., qᵢ₊₁, h₁, ..., hᵢ₊₁) - var wgs []*sync.WaitGroup for i := range q { // In the comments we use a 1-based index so q[i] = qᵢ₊₁ // go through all assignments of (b₁, ..., bᵢ) ∈ {0,1}ⁱ const threshold = 1 << 6 @@ -216,7 +214,7 @@ func (c *eqTimesGateEvalSumcheckClaims) innerWork(e, m polynomial.MultiLin, q [] m[j0].Sub(&m[j0], &m[j1]) // Eq(q₁, ..., qᵢ₊₁, b₁, ..., bᵢ, 0) = Eq(q₁, ..., qᵢ, b₁, ..., bᵢ) Eq(qᵢ₊₁, 0) = Eq(q₁, ..., qᵢ, b₁, ..., bᵢ) (1-qᵢ₊₁) } } else { - wgs = append(wgs, c.manager.workers.Submit(k, func(start, end int) { + c.manager.workers.Submit(k, func(start, end int) { for j := start; j < end; j++ { j0 := j << (n - i) // bᵢ₊₁ = 0 j1 := j0 + 1<<(n-1-i) // bᵢ₊₁ = 1 @@ -224,13 +222,10 @@ func (c *eqTimesGateEvalSumcheckClaims) innerWork(e, m polynomial.MultiLin, q [] m[j1].Mul(&q[i], &m[j0]) // Eq(q₁, ..., qᵢ₊₁, b₁, ..., bᵢ, 1) = Eq(q₁, ..., qᵢ, b₁, ..., bᵢ) Eq(qᵢ₊₁, 1) = Eq(q₁, ..., qᵢ, b₁, ..., bᵢ) qᵢ₊₁ m[j0].Sub(&m[j0], &m[j1]) // Eq(q₁, ..., qᵢ₊₁, b₁, ..., bᵢ, 0) = Eq(q₁, ..., qᵢ, b₁, ..., bᵢ) Eq(qᵢ₊₁, 0) = Eq(q₁, ..., qᵢ, b₁, ..., bᵢ) (1-qᵢ₊₁) } - }, 1024)) + }, 1024).Wait() } } - for _, wg := range wgs { - wg.Wait() - } c.manager.workers.Submit(len(e), func(start, end int) { for i := start; i < end; i++ { e[i].Add(&e[i], &m[i]) diff --git a/ecc/bls24-315/fr/gkr/gkr.go b/ecc/bls24-315/fr/gkr/gkr.go index c51b3c302d..968acb37d9 100644 --- a/ecc/bls24-315/fr/gkr/gkr.go +++ b/ecc/bls24-315/fr/gkr/gkr.go @@ -178,7 +178,7 @@ func (c *eqTimesGateEvalSumcheckClaims) Combine(combinationCoeff fr.Element) pol // define eq_k = aᵏ eq(x_k1, ..., x_kn, *, ..., *) where x_ki are the evaluation points newEq[0].Set(&aI) - c.innerWork(c.eq, newEq, c.evaluationPoints[k]) + c.eqAcc(c.eq, newEq, c.evaluationPoints[k]) // newEq.Eq(c.evaluationPoints[k]) // eqAsPoly := polynomial.Polynomial(c.eq) //just semantics @@ -196,13 +196,11 @@ func (c *eqTimesGateEvalSumcheckClaims) Combine(combinationCoeff fr.Element) pol return c.computeGJ() } -// innerWork sets m to an eq table at q and then adds it to e -// TODO @Tabaie find a better home for this / cleanup -func (c *eqTimesGateEvalSumcheckClaims) innerWork(e, m polynomial.MultiLin, q []fr.Element) { +// eqAcc sets m to an eq table at q and then adds it to e +func (c *eqTimesGateEvalSumcheckClaims) eqAcc(e, m polynomial.MultiLin, q []fr.Element) { n := len(q) //At the end of each iteration, m(h₁, ..., hₙ) = Eq(q₁, ..., qᵢ₊₁, h₁, ..., hᵢ₊₁) - var wgs []*sync.WaitGroup for i := range q { // In the comments we use a 1-based index so q[i] = qᵢ₊₁ // go through all assignments of (b₁, ..., bᵢ) ∈ {0,1}ⁱ const threshold = 1 << 6 @@ -216,7 +214,7 @@ func (c *eqTimesGateEvalSumcheckClaims) innerWork(e, m polynomial.MultiLin, q [] m[j0].Sub(&m[j0], &m[j1]) // Eq(q₁, ..., qᵢ₊₁, b₁, ..., bᵢ, 0) = Eq(q₁, ..., qᵢ, b₁, ..., bᵢ) Eq(qᵢ₊₁, 0) = Eq(q₁, ..., qᵢ, b₁, ..., bᵢ) (1-qᵢ₊₁) } } else { - wgs = append(wgs, c.manager.workers.Submit(k, func(start, end int) { + c.manager.workers.Submit(k, func(start, end int) { for j := start; j < end; j++ { j0 := j << (n - i) // bᵢ₊₁ = 0 j1 := j0 + 1<<(n-1-i) // bᵢ₊₁ = 1 @@ -224,13 +222,10 @@ func (c *eqTimesGateEvalSumcheckClaims) innerWork(e, m polynomial.MultiLin, q [] m[j1].Mul(&q[i], &m[j0]) // Eq(q₁, ..., qᵢ₊₁, b₁, ..., bᵢ, 1) = Eq(q₁, ..., qᵢ, b₁, ..., bᵢ) Eq(qᵢ₊₁, 1) = Eq(q₁, ..., qᵢ, b₁, ..., bᵢ) qᵢ₊₁ m[j0].Sub(&m[j0], &m[j1]) // Eq(q₁, ..., qᵢ₊₁, b₁, ..., bᵢ, 0) = Eq(q₁, ..., qᵢ, b₁, ..., bᵢ) Eq(qᵢ₊₁, 0) = Eq(q₁, ..., qᵢ, b₁, ..., bᵢ) (1-qᵢ₊₁) } - }, 1024)) + }, 1024).Wait() } } - for _, wg := range wgs { - wg.Wait() - } c.manager.workers.Submit(len(e), func(start, end int) { for i := start; i < end; i++ { e[i].Add(&e[i], &m[i]) diff --git a/ecc/bls24-317/fr/gkr/gkr.go b/ecc/bls24-317/fr/gkr/gkr.go index fc79d93c66..a9c4f96709 100644 --- a/ecc/bls24-317/fr/gkr/gkr.go +++ b/ecc/bls24-317/fr/gkr/gkr.go @@ -178,7 +178,7 @@ func (c *eqTimesGateEvalSumcheckClaims) Combine(combinationCoeff fr.Element) pol // define eq_k = aᵏ eq(x_k1, ..., x_kn, *, ..., *) where x_ki are the evaluation points newEq[0].Set(&aI) - c.innerWork(c.eq, newEq, c.evaluationPoints[k]) + c.eqAcc(c.eq, newEq, c.evaluationPoints[k]) // newEq.Eq(c.evaluationPoints[k]) // eqAsPoly := polynomial.Polynomial(c.eq) //just semantics @@ -196,13 +196,11 @@ func (c *eqTimesGateEvalSumcheckClaims) Combine(combinationCoeff fr.Element) pol return c.computeGJ() } -// innerWork sets m to an eq table at q and then adds it to e -// TODO @Tabaie find a better home for this / cleanup -func (c *eqTimesGateEvalSumcheckClaims) innerWork(e, m polynomial.MultiLin, q []fr.Element) { +// eqAcc sets m to an eq table at q and then adds it to e +func (c *eqTimesGateEvalSumcheckClaims) eqAcc(e, m polynomial.MultiLin, q []fr.Element) { n := len(q) //At the end of each iteration, m(h₁, ..., hₙ) = Eq(q₁, ..., qᵢ₊₁, h₁, ..., hᵢ₊₁) - var wgs []*sync.WaitGroup for i := range q { // In the comments we use a 1-based index so q[i] = qᵢ₊₁ // go through all assignments of (b₁, ..., bᵢ) ∈ {0,1}ⁱ const threshold = 1 << 6 @@ -216,7 +214,7 @@ func (c *eqTimesGateEvalSumcheckClaims) innerWork(e, m polynomial.MultiLin, q [] m[j0].Sub(&m[j0], &m[j1]) // Eq(q₁, ..., qᵢ₊₁, b₁, ..., bᵢ, 0) = Eq(q₁, ..., qᵢ, b₁, ..., bᵢ) Eq(qᵢ₊₁, 0) = Eq(q₁, ..., qᵢ, b₁, ..., bᵢ) (1-qᵢ₊₁) } } else { - wgs = append(wgs, c.manager.workers.Submit(k, func(start, end int) { + c.manager.workers.Submit(k, func(start, end int) { for j := start; j < end; j++ { j0 := j << (n - i) // bᵢ₊₁ = 0 j1 := j0 + 1<<(n-1-i) // bᵢ₊₁ = 1 @@ -224,13 +222,10 @@ func (c *eqTimesGateEvalSumcheckClaims) innerWork(e, m polynomial.MultiLin, q [] m[j1].Mul(&q[i], &m[j0]) // Eq(q₁, ..., qᵢ₊₁, b₁, ..., bᵢ, 1) = Eq(q₁, ..., qᵢ, b₁, ..., bᵢ) Eq(qᵢ₊₁, 1) = Eq(q₁, ..., qᵢ, b₁, ..., bᵢ) qᵢ₊₁ m[j0].Sub(&m[j0], &m[j1]) // Eq(q₁, ..., qᵢ₊₁, b₁, ..., bᵢ, 0) = Eq(q₁, ..., qᵢ, b₁, ..., bᵢ) Eq(qᵢ₊₁, 0) = Eq(q₁, ..., qᵢ, b₁, ..., bᵢ) (1-qᵢ₊₁) } - }, 1024)) + }, 1024).Wait() } } - for _, wg := range wgs { - wg.Wait() - } c.manager.workers.Submit(len(e), func(start, end int) { for i := start; i < end; i++ { e[i].Add(&e[i], &m[i]) diff --git a/ecc/bn254/fr/gkr/gkr.go b/ecc/bn254/fr/gkr/gkr.go index 42301d4165..a96fb9110b 100644 --- a/ecc/bn254/fr/gkr/gkr.go +++ b/ecc/bn254/fr/gkr/gkr.go @@ -178,7 +178,7 @@ func (c *eqTimesGateEvalSumcheckClaims) Combine(combinationCoeff fr.Element) pol // define eq_k = aᵏ eq(x_k1, ..., x_kn, *, ..., *) where x_ki are the evaluation points newEq[0].Set(&aI) - c.innerWork(c.eq, newEq, c.evaluationPoints[k]) + c.eqAcc(c.eq, newEq, c.evaluationPoints[k]) // newEq.Eq(c.evaluationPoints[k]) // eqAsPoly := polynomial.Polynomial(c.eq) //just semantics @@ -196,13 +196,11 @@ func (c *eqTimesGateEvalSumcheckClaims) Combine(combinationCoeff fr.Element) pol return c.computeGJ() } -// innerWork sets m to an eq table at q and then adds it to e -// TODO @Tabaie find a better home for this / cleanup -func (c *eqTimesGateEvalSumcheckClaims) innerWork(e, m polynomial.MultiLin, q []fr.Element) { +// eqAcc sets m to an eq table at q and then adds it to e +func (c *eqTimesGateEvalSumcheckClaims) eqAcc(e, m polynomial.MultiLin, q []fr.Element) { n := len(q) //At the end of each iteration, m(h₁, ..., hₙ) = Eq(q₁, ..., qᵢ₊₁, h₁, ..., hᵢ₊₁) - var wgs []*sync.WaitGroup for i := range q { // In the comments we use a 1-based index so q[i] = qᵢ₊₁ // go through all assignments of (b₁, ..., bᵢ) ∈ {0,1}ⁱ const threshold = 1 << 6 @@ -216,7 +214,7 @@ func (c *eqTimesGateEvalSumcheckClaims) innerWork(e, m polynomial.MultiLin, q [] m[j0].Sub(&m[j0], &m[j1]) // Eq(q₁, ..., qᵢ₊₁, b₁, ..., bᵢ, 0) = Eq(q₁, ..., qᵢ, b₁, ..., bᵢ) Eq(qᵢ₊₁, 0) = Eq(q₁, ..., qᵢ, b₁, ..., bᵢ) (1-qᵢ₊₁) } } else { - wgs = append(wgs, c.manager.workers.Submit(k, func(start, end int) { + c.manager.workers.Submit(k, func(start, end int) { for j := start; j < end; j++ { j0 := j << (n - i) // bᵢ₊₁ = 0 j1 := j0 + 1<<(n-1-i) // bᵢ₊₁ = 1 @@ -224,13 +222,10 @@ func (c *eqTimesGateEvalSumcheckClaims) innerWork(e, m polynomial.MultiLin, q [] m[j1].Mul(&q[i], &m[j0]) // Eq(q₁, ..., qᵢ₊₁, b₁, ..., bᵢ, 1) = Eq(q₁, ..., qᵢ, b₁, ..., bᵢ) Eq(qᵢ₊₁, 1) = Eq(q₁, ..., qᵢ, b₁, ..., bᵢ) qᵢ₊₁ m[j0].Sub(&m[j0], &m[j1]) // Eq(q₁, ..., qᵢ₊₁, b₁, ..., bᵢ, 0) = Eq(q₁, ..., qᵢ, b₁, ..., bᵢ) Eq(qᵢ₊₁, 0) = Eq(q₁, ..., qᵢ, b₁, ..., bᵢ) (1-qᵢ₊₁) } - }, 1024)) + }, 1024).Wait() } } - for _, wg := range wgs { - wg.Wait() - } c.manager.workers.Submit(len(e), func(start, end int) { for i := start; i < end; i++ { e[i].Add(&e[i], &m[i]) diff --git a/ecc/bw6-633/fr/gkr/gkr.go b/ecc/bw6-633/fr/gkr/gkr.go index 4e7118cb60..b9c27df177 100644 --- a/ecc/bw6-633/fr/gkr/gkr.go +++ b/ecc/bw6-633/fr/gkr/gkr.go @@ -178,7 +178,7 @@ func (c *eqTimesGateEvalSumcheckClaims) Combine(combinationCoeff fr.Element) pol // define eq_k = aᵏ eq(x_k1, ..., x_kn, *, ..., *) where x_ki are the evaluation points newEq[0].Set(&aI) - c.innerWork(c.eq, newEq, c.evaluationPoints[k]) + c.eqAcc(c.eq, newEq, c.evaluationPoints[k]) // newEq.Eq(c.evaluationPoints[k]) // eqAsPoly := polynomial.Polynomial(c.eq) //just semantics @@ -196,13 +196,11 @@ func (c *eqTimesGateEvalSumcheckClaims) Combine(combinationCoeff fr.Element) pol return c.computeGJ() } -// innerWork sets m to an eq table at q and then adds it to e -// TODO @Tabaie find a better home for this / cleanup -func (c *eqTimesGateEvalSumcheckClaims) innerWork(e, m polynomial.MultiLin, q []fr.Element) { +// eqAcc sets m to an eq table at q and then adds it to e +func (c *eqTimesGateEvalSumcheckClaims) eqAcc(e, m polynomial.MultiLin, q []fr.Element) { n := len(q) //At the end of each iteration, m(h₁, ..., hₙ) = Eq(q₁, ..., qᵢ₊₁, h₁, ..., hᵢ₊₁) - var wgs []*sync.WaitGroup for i := range q { // In the comments we use a 1-based index so q[i] = qᵢ₊₁ // go through all assignments of (b₁, ..., bᵢ) ∈ {0,1}ⁱ const threshold = 1 << 6 @@ -216,7 +214,7 @@ func (c *eqTimesGateEvalSumcheckClaims) innerWork(e, m polynomial.MultiLin, q [] m[j0].Sub(&m[j0], &m[j1]) // Eq(q₁, ..., qᵢ₊₁, b₁, ..., bᵢ, 0) = Eq(q₁, ..., qᵢ, b₁, ..., bᵢ) Eq(qᵢ₊₁, 0) = Eq(q₁, ..., qᵢ, b₁, ..., bᵢ) (1-qᵢ₊₁) } } else { - wgs = append(wgs, c.manager.workers.Submit(k, func(start, end int) { + c.manager.workers.Submit(k, func(start, end int) { for j := start; j < end; j++ { j0 := j << (n - i) // bᵢ₊₁ = 0 j1 := j0 + 1<<(n-1-i) // bᵢ₊₁ = 1 @@ -224,13 +222,10 @@ func (c *eqTimesGateEvalSumcheckClaims) innerWork(e, m polynomial.MultiLin, q [] m[j1].Mul(&q[i], &m[j0]) // Eq(q₁, ..., qᵢ₊₁, b₁, ..., bᵢ, 1) = Eq(q₁, ..., qᵢ, b₁, ..., bᵢ) Eq(qᵢ₊₁, 1) = Eq(q₁, ..., qᵢ, b₁, ..., bᵢ) qᵢ₊₁ m[j0].Sub(&m[j0], &m[j1]) // Eq(q₁, ..., qᵢ₊₁, b₁, ..., bᵢ, 0) = Eq(q₁, ..., qᵢ, b₁, ..., bᵢ) Eq(qᵢ₊₁, 0) = Eq(q₁, ..., qᵢ, b₁, ..., bᵢ) (1-qᵢ₊₁) } - }, 1024)) + }, 1024).Wait() } } - for _, wg := range wgs { - wg.Wait() - } c.manager.workers.Submit(len(e), func(start, end int) { for i := start; i < end; i++ { e[i].Add(&e[i], &m[i]) diff --git a/ecc/bw6-756/fr/gkr/gkr.go b/ecc/bw6-756/fr/gkr/gkr.go index cc2204fa7a..650170be43 100644 --- a/ecc/bw6-756/fr/gkr/gkr.go +++ b/ecc/bw6-756/fr/gkr/gkr.go @@ -178,7 +178,7 @@ func (c *eqTimesGateEvalSumcheckClaims) Combine(combinationCoeff fr.Element) pol // define eq_k = aᵏ eq(x_k1, ..., x_kn, *, ..., *) where x_ki are the evaluation points newEq[0].Set(&aI) - c.innerWork(c.eq, newEq, c.evaluationPoints[k]) + c.eqAcc(c.eq, newEq, c.evaluationPoints[k]) // newEq.Eq(c.evaluationPoints[k]) // eqAsPoly := polynomial.Polynomial(c.eq) //just semantics @@ -196,13 +196,11 @@ func (c *eqTimesGateEvalSumcheckClaims) Combine(combinationCoeff fr.Element) pol return c.computeGJ() } -// innerWork sets m to an eq table at q and then adds it to e -// TODO @Tabaie find a better home for this / cleanup -func (c *eqTimesGateEvalSumcheckClaims) innerWork(e, m polynomial.MultiLin, q []fr.Element) { +// eqAcc sets m to an eq table at q and then adds it to e +func (c *eqTimesGateEvalSumcheckClaims) eqAcc(e, m polynomial.MultiLin, q []fr.Element) { n := len(q) //At the end of each iteration, m(h₁, ..., hₙ) = Eq(q₁, ..., qᵢ₊₁, h₁, ..., hᵢ₊₁) - var wgs []*sync.WaitGroup for i := range q { // In the comments we use a 1-based index so q[i] = qᵢ₊₁ // go through all assignments of (b₁, ..., bᵢ) ∈ {0,1}ⁱ const threshold = 1 << 6 @@ -216,7 +214,7 @@ func (c *eqTimesGateEvalSumcheckClaims) innerWork(e, m polynomial.MultiLin, q [] m[j0].Sub(&m[j0], &m[j1]) // Eq(q₁, ..., qᵢ₊₁, b₁, ..., bᵢ, 0) = Eq(q₁, ..., qᵢ, b₁, ..., bᵢ) Eq(qᵢ₊₁, 0) = Eq(q₁, ..., qᵢ, b₁, ..., bᵢ) (1-qᵢ₊₁) } } else { - wgs = append(wgs, c.manager.workers.Submit(k, func(start, end int) { + c.manager.workers.Submit(k, func(start, end int) { for j := start; j < end; j++ { j0 := j << (n - i) // bᵢ₊₁ = 0 j1 := j0 + 1<<(n-1-i) // bᵢ₊₁ = 1 @@ -224,13 +222,10 @@ func (c *eqTimesGateEvalSumcheckClaims) innerWork(e, m polynomial.MultiLin, q [] m[j1].Mul(&q[i], &m[j0]) // Eq(q₁, ..., qᵢ₊₁, b₁, ..., bᵢ, 1) = Eq(q₁, ..., qᵢ, b₁, ..., bᵢ) Eq(qᵢ₊₁, 1) = Eq(q₁, ..., qᵢ, b₁, ..., bᵢ) qᵢ₊₁ m[j0].Sub(&m[j0], &m[j1]) // Eq(q₁, ..., qᵢ₊₁, b₁, ..., bᵢ, 0) = Eq(q₁, ..., qᵢ, b₁, ..., bᵢ) Eq(qᵢ₊₁, 0) = Eq(q₁, ..., qᵢ, b₁, ..., bᵢ) (1-qᵢ₊₁) } - }, 1024)) + }, 1024).Wait() } } - for _, wg := range wgs { - wg.Wait() - } c.manager.workers.Submit(len(e), func(start, end int) { for i := start; i < end; i++ { e[i].Add(&e[i], &m[i]) diff --git a/ecc/bw6-761/fr/gkr/gkr.go b/ecc/bw6-761/fr/gkr/gkr.go index 4fd100909b..a50b7617ba 100644 --- a/ecc/bw6-761/fr/gkr/gkr.go +++ b/ecc/bw6-761/fr/gkr/gkr.go @@ -178,7 +178,7 @@ func (c *eqTimesGateEvalSumcheckClaims) Combine(combinationCoeff fr.Element) pol // define eq_k = aᵏ eq(x_k1, ..., x_kn, *, ..., *) where x_ki are the evaluation points newEq[0].Set(&aI) - c.innerWork(c.eq, newEq, c.evaluationPoints[k]) + c.eqAcc(c.eq, newEq, c.evaluationPoints[k]) // newEq.Eq(c.evaluationPoints[k]) // eqAsPoly := polynomial.Polynomial(c.eq) //just semantics @@ -196,13 +196,11 @@ func (c *eqTimesGateEvalSumcheckClaims) Combine(combinationCoeff fr.Element) pol return c.computeGJ() } -// innerWork sets m to an eq table at q and then adds it to e -// TODO @Tabaie find a better home for this / cleanup -func (c *eqTimesGateEvalSumcheckClaims) innerWork(e, m polynomial.MultiLin, q []fr.Element) { +// eqAcc sets m to an eq table at q and then adds it to e +func (c *eqTimesGateEvalSumcheckClaims) eqAcc(e, m polynomial.MultiLin, q []fr.Element) { n := len(q) //At the end of each iteration, m(h₁, ..., hₙ) = Eq(q₁, ..., qᵢ₊₁, h₁, ..., hᵢ₊₁) - var wgs []*sync.WaitGroup for i := range q { // In the comments we use a 1-based index so q[i] = qᵢ₊₁ // go through all assignments of (b₁, ..., bᵢ) ∈ {0,1}ⁱ const threshold = 1 << 6 @@ -216,7 +214,7 @@ func (c *eqTimesGateEvalSumcheckClaims) innerWork(e, m polynomial.MultiLin, q [] m[j0].Sub(&m[j0], &m[j1]) // Eq(q₁, ..., qᵢ₊₁, b₁, ..., bᵢ, 0) = Eq(q₁, ..., qᵢ, b₁, ..., bᵢ) Eq(qᵢ₊₁, 0) = Eq(q₁, ..., qᵢ, b₁, ..., bᵢ) (1-qᵢ₊₁) } } else { - wgs = append(wgs, c.manager.workers.Submit(k, func(start, end int) { + c.manager.workers.Submit(k, func(start, end int) { for j := start; j < end; j++ { j0 := j << (n - i) // bᵢ₊₁ = 0 j1 := j0 + 1<<(n-1-i) // bᵢ₊₁ = 1 @@ -224,13 +222,10 @@ func (c *eqTimesGateEvalSumcheckClaims) innerWork(e, m polynomial.MultiLin, q [] m[j1].Mul(&q[i], &m[j0]) // Eq(q₁, ..., qᵢ₊₁, b₁, ..., bᵢ, 1) = Eq(q₁, ..., qᵢ, b₁, ..., bᵢ) Eq(qᵢ₊₁, 1) = Eq(q₁, ..., qᵢ, b₁, ..., bᵢ) qᵢ₊₁ m[j0].Sub(&m[j0], &m[j1]) // Eq(q₁, ..., qᵢ₊₁, b₁, ..., bᵢ, 0) = Eq(q₁, ..., qᵢ, b₁, ..., bᵢ) Eq(qᵢ₊₁, 0) = Eq(q₁, ..., qᵢ, b₁, ..., bᵢ) (1-qᵢ₊₁) } - }, 1024)) + }, 1024).Wait() } } - for _, wg := range wgs { - wg.Wait() - } c.manager.workers.Submit(len(e), func(start, end int) { for i := start; i < end; i++ { e[i].Add(&e[i], &m[i]) diff --git a/internal/generator/gkr/template/gkr.go.tmpl b/internal/generator/gkr/template/gkr.go.tmpl index 86a5f915de..6a09ac332e 100644 --- a/internal/generator/gkr/template/gkr.go.tmpl +++ b/internal/generator/gkr/template/gkr.go.tmpl @@ -162,7 +162,7 @@ func (c *eqTimesGateEvalSumcheckClaims) Combine(combinationCoeff {{.ElementType} // define eq_k = aᵏ eq(x_k1, ..., x_kn, *, ..., *) where x_ki are the evaluation points newEq[0].Set(&aI) - c.innerWork(c.eq, newEq,c.evaluationPoints[k]) + c.eqAcc(c.eq, newEq,c.evaluationPoints[k]) // newEq.Eq(c.evaluationPoints[k]) // eqAsPoly := polynomial.Polynomial(c.eq) //just semantics @@ -180,13 +180,11 @@ func (c *eqTimesGateEvalSumcheckClaims) Combine(combinationCoeff {{.ElementType} return c.computeGJ() } -// innerWork sets m to an eq table at q and then adds it to e -// TODO @Tabaie find a better home for this / cleanup -func (c *eqTimesGateEvalSumcheckClaims) innerWork(e, m polynomial.MultiLin, q []{{.ElementType}}) { +// eqAcc sets m to an eq table at q and then adds it to e +func (c *eqTimesGateEvalSumcheckClaims) eqAcc(e, m polynomial.MultiLin, q []{{.ElementType}}) { n := len(q) //At the end of each iteration, m(h₁, ..., hₙ) = Eq(q₁, ..., qᵢ₊₁, h₁, ..., hᵢ₊₁) - var wgs []*sync.WaitGroup for i := range q { // In the comments we use a 1-based index so q[i] = qᵢ₊₁ // go through all assignments of (b₁, ..., bᵢ) ∈ {0,1}ⁱ const threshold = 1 << 6 @@ -200,7 +198,7 @@ func (c *eqTimesGateEvalSumcheckClaims) innerWork(e, m polynomial.MultiLin, q [] m[j0].Sub(&m[j0], &m[j1]) // Eq(q₁, ..., qᵢ₊₁, b₁, ..., bᵢ, 0) = Eq(q₁, ..., qᵢ, b₁, ..., bᵢ) Eq(qᵢ₊₁, 0) = Eq(q₁, ..., qᵢ, b₁, ..., bᵢ) (1-qᵢ₊₁) } } else { - wgs = append(wgs, c.manager.workers.Submit(k, func(start, end int) { + c.manager.workers.Submit(k, func(start, end int) { for j := start; j < end; j++ { j0 := j << (n - i) // bᵢ₊₁ = 0 j1 := j0 + 1<<(n-1-i) // bᵢ₊₁ = 1 @@ -208,13 +206,10 @@ func (c *eqTimesGateEvalSumcheckClaims) innerWork(e, m polynomial.MultiLin, q [] m[j1].Mul(&q[i], &m[j0]) // Eq(q₁, ..., qᵢ₊₁, b₁, ..., bᵢ, 1) = Eq(q₁, ..., qᵢ, b₁, ..., bᵢ) Eq(qᵢ₊₁, 1) = Eq(q₁, ..., qᵢ, b₁, ..., bᵢ) qᵢ₊₁ m[j0].Sub(&m[j0], &m[j1]) // Eq(q₁, ..., qᵢ₊₁, b₁, ..., bᵢ, 0) = Eq(q₁, ..., qᵢ, b₁, ..., bᵢ) Eq(qᵢ₊₁, 0) = Eq(q₁, ..., qᵢ, b₁, ..., bᵢ) (1-qᵢ₊₁) } - }, 1024)) + }, 1024).Wait() } } - for _, wg := range wgs { - wg.Wait() - } c.manager.workers.Submit(len(e), func(start, end int) { for i := start; i < end; i++ { e[i].Add(&e[i], &m[i]) diff --git a/internal/generator/test_vector_utils/small_rational/gkr/gkr.go b/internal/generator/test_vector_utils/small_rational/gkr/gkr.go index 9f0ec4038a..ae7261e529 100644 --- a/internal/generator/test_vector_utils/small_rational/gkr/gkr.go +++ b/internal/generator/test_vector_utils/small_rational/gkr/gkr.go @@ -178,7 +178,7 @@ func (c *eqTimesGateEvalSumcheckClaims) Combine(combinationCoeff small_rational. // define eq_k = aᵏ eq(x_k1, ..., x_kn, *, ..., *) where x_ki are the evaluation points newEq[0].Set(&aI) - c.innerWork(c.eq, newEq, c.evaluationPoints[k]) + c.eqAcc(c.eq, newEq, c.evaluationPoints[k]) // newEq.Eq(c.evaluationPoints[k]) // eqAsPoly := polynomial.Polynomial(c.eq) //just semantics @@ -196,13 +196,11 @@ func (c *eqTimesGateEvalSumcheckClaims) Combine(combinationCoeff small_rational. return c.computeGJ() } -// innerWork sets m to an eq table at q and then adds it to e -// TODO @Tabaie find a better home for this / cleanup -func (c *eqTimesGateEvalSumcheckClaims) innerWork(e, m polynomial.MultiLin, q []small_rational.SmallRational) { +// eqAcc sets m to an eq table at q and then adds it to e +func (c *eqTimesGateEvalSumcheckClaims) eqAcc(e, m polynomial.MultiLin, q []small_rational.SmallRational) { n := len(q) //At the end of each iteration, m(h₁, ..., hₙ) = Eq(q₁, ..., qᵢ₊₁, h₁, ..., hᵢ₊₁) - var wgs []*sync.WaitGroup for i := range q { // In the comments we use a 1-based index so q[i] = qᵢ₊₁ // go through all assignments of (b₁, ..., bᵢ) ∈ {0,1}ⁱ const threshold = 1 << 6 @@ -216,7 +214,7 @@ func (c *eqTimesGateEvalSumcheckClaims) innerWork(e, m polynomial.MultiLin, q [] m[j0].Sub(&m[j0], &m[j1]) // Eq(q₁, ..., qᵢ₊₁, b₁, ..., bᵢ, 0) = Eq(q₁, ..., qᵢ, b₁, ..., bᵢ) Eq(qᵢ₊₁, 0) = Eq(q₁, ..., qᵢ, b₁, ..., bᵢ) (1-qᵢ₊₁) } } else { - wgs = append(wgs, c.manager.workers.Submit(k, func(start, end int) { + c.manager.workers.Submit(k, func(start, end int) { for j := start; j < end; j++ { j0 := j << (n - i) // bᵢ₊₁ = 0 j1 := j0 + 1<<(n-1-i) // bᵢ₊₁ = 1 @@ -224,13 +222,10 @@ func (c *eqTimesGateEvalSumcheckClaims) innerWork(e, m polynomial.MultiLin, q [] m[j1].Mul(&q[i], &m[j0]) // Eq(q₁, ..., qᵢ₊₁, b₁, ..., bᵢ, 1) = Eq(q₁, ..., qᵢ, b₁, ..., bᵢ) Eq(qᵢ₊₁, 1) = Eq(q₁, ..., qᵢ, b₁, ..., bᵢ) qᵢ₊₁ m[j0].Sub(&m[j0], &m[j1]) // Eq(q₁, ..., qᵢ₊₁, b₁, ..., bᵢ, 0) = Eq(q₁, ..., qᵢ, b₁, ..., bᵢ) Eq(qᵢ₊₁, 0) = Eq(q₁, ..., qᵢ, b₁, ..., bᵢ) (1-qᵢ₊₁) } - }, 1024)) + }, 1024).Wait() } } - for _, wg := range wgs { - wg.Wait() - } c.manager.workers.Submit(len(e), func(start, end int) { for i := start; i < end; i++ { e[i].Add(&e[i], &m[i])