fix: validate Plonk proof structure according to verifying key - #1787
Merged
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR hardens Plonk verification by validating proof structure (and a related verifying key invariant) up front, preventing panics when malformed proofs are provided. It also adds a regression test reproducing the claimed-values length mismatch scenario described in the PR.
Changes:
- Add verifying-time structural checks for
Bsb22CommitmentsandBatchedProof.ClaimedValueslengths againstvk.Qcp. - Add a verifying key consistency check for
CommitmentConstraintIndexesvsQcp. - Add a regression test ensuring malformed claimed-values lengths never panic and always return an error.
Reviewed changes
Copilot reviewed 2 out of 6 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
internal/regression_tests/issue1787/issue1787_test.go |
Adds regression coverage for malformed Plonk proof claimed-values lengths (including roundtrip encode/decode). |
internal/generator/backend/template/zkpschemes/plonk/plonk.verify.go.tmpl |
Updates the Plonk verifier template to validate proof/VK structure before indexing into slices. |
backend/plonk/bw6-761/verify.go |
Generated verifier updated to include new proof/VK length checks. |
backend/plonk/bn254/verify.go |
Generated verifier updated to include new proof/VK length checks. |
backend/plonk/bls12-381/verify.go |
Generated verifier updated to include new proof/VK length checks. |
backend/plonk/bls12-377/verify.go |
Generated verifier updated to include new proof/VK length checks. |
Files not reviewed (4)
- backend/plonk/bls12-377/verify.go: Generated file
- backend/plonk/bls12-381/verify.go: Generated file
- backend/plonk/bn254/verify.go: Generated file
- backend/plonk/bw6-761/verify.go: Generated file
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
ThomasPiellard
approved these changes
Jun 24, 2026
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
Check ClaimedValues length according to verifing key.
Type of change
How has this been tested?
Checklist:
golangci-lintdoes not output errors locallyNote
Medium Risk
Touches the PLONK verifier entry path on all curves; changes are defensive length checks only, but incorrect bounds could reject valid proofs or miss invalid ones.
Overview
Hardens PLONK
Verifyacross curves by checking proof and verifying-key shape againstlen(vk.Qcp)before the verifier indexes batched openings.Early checks now reject mismatched
CommitmentConstraintIndexesvsQcp(errInvalidVerifyingKey),Bsb22Commitmentscount (replacing the ad-hoc BSB22 error witherrInvalidProof), andBatchedProof.ClaimedValueslength must be6 + len(vk.Qcp)(errInvalidProof) so malformed proofs fail with an error instead of panicking when readingClaimedValues[6:].The same logic is wired through
plonk.verify.go.tmpl; regression testissue1787covers too-short, too-long, and commitment-missingClaimedValuescases (in-memory and after encode/decode).Reviewed by Cursor Bugbot for commit 2a0afd8. Bugbot is set up for automated code reviews on this repo. Configure here.