fix: multiround commits with shared vals - #1814
Open
shramee wants to merge 3 commits into
Open
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
TLDR;
privateCommittedSeeker.Seekreturns index from original commitment indexes, but code tries to find it in the sliced-in-loop commitment indexes.builder.Commit(Groth16 R1CS builder) panics with a slice-index-out-of-range error when a circuit commits to a variable, and then later commits again to a variable that is already covered by an earlier commitment (i.e. the "re-commit-to-a-commitment" path).The bug is in
frontend/cs/r1cs/api.go, in(*builder[E]).Commit. The function computesexistingCommitmentIndexes := commitments.CommitmentIndexes()and then, over the course of the sort/merge loop, progressively slices this same variable down (existingCommitmentIndexes = existingCommitmentIndexes[1:]) as it consumes committed wires in VID order:https://github.com/Consensys/gnark/blob/master/frontend/cs/r1cs/api.go#L881
privateCommittedSeeker.Seek(t.VID)returnscommitter, an index into the original, unsliced list of commitments (it indexescommitments.GetPrivateCommitted(), which has one entry per commitment, in original commitment order). But by the time the loop reaches a givent.VID,existingCommitmentIndexeshas already been sliced down (its front elements dropped) by theexistingCommitmentIndexes[0] < t.VIDloop above. Indexing the sliced slice with an index meant for the original slice reads the wrong element, or — as soon as the slice has been shortened pastcommitter's original position — panics with an out-of-range index.Fixes #1813
Type of change
How has this been tested?
TestCommitToAlreadyCommittedVariableHow has this been benchmarked?
Not applicable
Checklist:
golangci-lintdoes not output errors locallyNote
Medium Risk
Touches multi-round commitment compilation logic used by Groth16 circuits; the change is narrow but incorrect indexing could still affect proof soundness if wrong.
Overview
Fixes a panic / wrong-wire bug in Groth16 R1CS
Commitwhen a later commitment includes a private wire that was already covered by an earlier commitment.Commitstill advances a slicedexistingCommitmentIndexeswhile merging wires in VID order, but the “already privately committed” path now resolves the commitment wire viaallCommitmentIndexes[committer], becauseprivateCommittedSeeker.Seekreturns an index into the full commitment list—not the shortened slice.Adds
TestCommitToAlreadyCommittedVariable: two commits that privately coverv1, then a thirdCommit(v1)that should redirect to the existing commitment wire; compile and solve must succeed.Reviewed by Cursor Bugbot for commit 76aca44. Bugbot is set up for automated code reviews on this repo. Configure here.