From db574a4e4758c210600f8cef960f82440dc3e98a Mon Sep 17 00:00:00 2001 From: Arya Tabaie <15056835+Tabaie@users.noreply.github.com> Date: Mon, 16 Dec 2024 12:47:51 -0600 Subject: [PATCH] fix mergeIterator --- backend/groth16/bn254/mpcsetup/phase2.go | 2 +- backend/groth16/internal/utils.go | 5 ++++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/backend/groth16/bn254/mpcsetup/phase2.go b/backend/groth16/bn254/mpcsetup/phase2.go index dbd4260e4f..644a8bac22 100644 --- a/backend/groth16/bn254/mpcsetup/phase2.go +++ b/backend/groth16/bn254/mpcsetup/phase2.go @@ -277,7 +277,7 @@ func (p *Phase2) Initialize(r1cs *cs.R1CS, commons *SrsCommons) Phase2Evaluation p.Parameters.G2.Sigma = make([]curve.G2Affine, len(commitments)) for j := range commitments { - evals.G1.CKK[i] = make([]curve.G1Affine, 0, len(commitments[j].PrivateCommitted)) + evals.G1.CKK[j] = make([]curve.G1Affine, 0, len(commitments[j].PrivateCommitted)) p.Parameters.G2.Sigma[j] = g2 } diff --git a/backend/groth16/internal/utils.go b/backend/groth16/internal/utils.go index 67648b2104..be4bcf34fa 100644 --- a/backend/groth16/internal/utils.go +++ b/backend/groth16/internal/utils.go @@ -57,6 +57,9 @@ func (i *MergeIterator) findLeast() { // Peek returns the next smallest value and the index of the slice it came from // If the iterator is empty, Peek returns (math.MaxInt, -1) func (i *MergeIterator) Peek() (value, index int) { + if i.leastIndex == -1 { + return math.MaxInt, -1 + } return i.slices[i.leastIndex][0], i.leastIndex } @@ -64,8 +67,8 @@ func (i *MergeIterator) Peek() (value, index int) { // If the iterator is empty, Next returns (math.MaxInt, -1) func (i *MergeIterator) Next() (value, index int) { value, index = i.Peek() - i.findLeast() i.slices[i.leastIndex] = i.slices[i.leastIndex][1:] + i.findLeast() return }