Repository navigation
Check the count and range of public inputs in Groth16 and PLONK - #23
Open
SamDelaney wants to merge 7 commits into
Open
SamDelaney wants to merge 7 commits into
SamDelaney wants to merge 7 commits into
Conversation
verify now returns False unless there is exactly one public input per vkIC entry after the first, using a new check_public_inputs helper in common/inputs.ak. derive also fails when inputs remain after vkIC runs out, so a caller using it directly can't have an input dropped either. Too few inputs now return False instead of trapping, so every wrong input count is handled the same way. known_issue_11 becomes prop_groth_rejects_extra_inputs, alongside a unit test for derive and property tests for the helper. verify_compressed now costs ~83.7K mem / 2.80B CPU (from 66.9K / 2.79B). Fixes #11 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
PreparedPlonkPreInputs gains an n_public field, set by plonk_prepare_preinputs, and verify_plonk returns False unless there are exactly n_public inputs, using the check Groth16 already uses. Code that builds PreparedPlonkPreInputs by hand now has to set n_public. An honest proof already fails with the wrong number of inputs, because the transcript changes, so the new tests guard the check but can't show the forgery the issue describes; that needs a modified prover. Fixes #13 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
check_public_inputs now also requires every input to lie in [0, r). Both verifiers reduce inputs mod r, so x and x + r verified with the same proof while a validator reading the input as an Int saw different values. Negative inputs are now rejected explicitly as well. Both known_issue_12 tests become properties covering shifts by k * r in either direction, with a boundary test (r - 1 passes the range check, r and -1 don't). verify_compressed now costs ~89.6K mem / 2.80B CPU. Fixes #12 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
verify_plonk paired the inverse hints with the generators using map2, which stops at the shorter list, so a missing or surplus inverse went unchecked. It now returns False unless the two lists are the same length. known_issue_14 becomes prop_plonk_rejects_wrong_inverse_count, which appends or drops one inverse; appending one used to verify. Fixes #14 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
list.range is inclusive, so plonk_prepare_preinputs built n_public + 1 generators, and every proof paid for an extra Lagrange term and an extra field inversion. It now builds max(1, n_public): one per public input, and still one when there are none, because the permutation check always uses L_1. The fixture's prepare-and-verify run goes from 6.63M mem / 8.63B CPU to 4.80M / 8.04B. Fixes #19 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
verify_plonk counted the inverses and the generators with two list.length calls before verifying. The Lagrange check now walks both lists together and returns False when one runs out before the other, which does the same job in the pass it already makes. An empty inverse list is still caught up front, so it returns False rather than failing when the verifier takes the first Lagrange term. New test plonk_rejects_empty_inverse_list. Mutation-checked: dropping the empty-list guard fails that test, and letting surplus inverses through fails prop_plonk_rejects_wrong_inverse_count. The fixture's prepare-and-verify run goes from 4.80M mem / 8.04B CPU to 4.78M / 8.03B. Refs #14 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The #19 commit rewrote test_generator_list_creation without list, which left the import unused. aiken check -D treats that warning as an error, so CI failed although every test passed. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
There was a problem hiding this comment.
🟡 Changes recommended
The public-input count guard lacks an effective regression test because existing extra/missing-input cases still fail from transcript changes even when the guard is removed.
1 open issue
What changed in this PR
This PR strengthens public-input validation in the library’s Groth16 and PLONK verifiers, addressing count and scalar-range issues while reducing PLONK preparation cost.
Changes:
- Adds shared count and range checks, plus strict input matching in Groth16’s
derive. - Records PLONK’s expected input count, validates inverse-list lengths, and removes the surplus generator.
- Expands unit and property tests and updates documentation and reported costs.
| File | Description |
|---|---|
zkp/lib/tests/plonk_tests.ak |
Checks prepared generator values and removes an unused import. |
zkp/lib/tests/plonk_props.ak |
Adds input, inverse-count, and generator-count checks. |
zkp/lib/tests/inputs_tests.ak |
Tests shared count, range, and empty-input validation. |
zkp/lib/tests/groth_props.ak |
Adds rejection properties and boundary checks. |
zkp/lib/plonk/verifier.ak |
Validates public inputs and inverse-list lengths. |
zkp/lib/plonk/preinputs.ak |
Stores n_public and corrects generator counts. |
zkp/lib/groth/groth.ak |
Validates inputs and rejects mismatched lists in derive. |
zkp/lib/common/inputs.ak |
Introduces the shared public-input validator. |
zkp/docs/plonk-implementation-report.md |
Documents validation, costs, tests, and remaining limitations. |
zkp/docs/groth16-implementation-report.md |
Documents stricter validation, tests, and updated costs. |
zkp/docs/bulletproofs-implementation-report.md |
Updates the package-wide test count only. |
README.md |
Summarizes input validation and updates test totals. |
Review effort: Balanced
| proof: PreparedPlonkProof, | ||
| ) -> Bool { | ||
| and { | ||
| check_public_inputs(pub_inputs, preinputs.n_public), |
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.

Catalyst completion roadmap task 1.1: fixes the five public-input issues from the review, one commit per issue, plus a sixth that makes the #14 check cheaper. Each commit's tests pass on its own. The #19 commit also left an unused import, which fails CI's warnings check (
-D);3c01e4cremoves it.Fixes #11, fixes #12, fixes #13, fixes #14, fixes #19.
Changes
b9f37e5verifyreturnsFalseunless there is exactly one input pervkICentry after the first, using a newcheck_public_inputsincommon/inputs.ak.derivenow fails if either list runs out before the other.704c7a0PreparedPlonkPreInputsgains ann_publicfield, andverify_plonkchecks the input count against it with the same helper.a6a045ccheck_public_inputsalso requires every input to lie in[0, r), in both verifiers.696f97dverify_plonkrequires exactly one Lagrange inverse per generator.b76d87cplonk_prepare_preinputsbuildsmax(1, n_public)generators instead ofn_public + 1. It keeps at least one because the permutation check always usesL_1.bb85252list.lengthcalls up front. An empty inverse list is still caught up front, so it returnsFalserather than an error.Behaviour changes
Falserather than trapping, so a caller can branch on the result. Too few Groth16 inputs used to trap.PreparedPlonkPreInputshas a newn_publicfield. Code that builds it directly, rather than throughplonk_prepare_preinputs, has to set it.Tests
known_issue_*tests for Groth16: verify ignores public inputs beyond the verification key #11, Groth16 and PLONK: public inputs are not range-checked, so x and x + r verify with the same proof #12 (both verifiers) and PLONK: lagrange_inverses length is not checked, so a public input can be left unconstrained #14 are replaced by the properties their comments named: extra inputs are rejected, an input shifted byk · rin either direction is rejected, and an inverse list one too long or one too short is rejected.tests/inputs_tests.akfor the helper itself; the Groth16 range boundaries (r - 1passes the range check,rand-1don't);derivefailing on an extra input; PLONK with too few inputs; PLONK with an empty inverse list; and the generator count forn_publicof 0, 1, 2 and 5.Cost
verify_compressedThe PLONK drop comes from #19: one fewer generator means one fewer Lagrange term and one fewer field inversion. Counting the inverses in the existing walk (
bb85252) makes the #14 check close to free; done as two separatelist.lengthcalls it cost about 22K memory and 7.6M CPU.Documentation
The README and the three implementation reports give the new test count, describe the checks and their costs, and drop the limitation bullets for the fixed issues.
Checks
aiken check -D: 73 tests, all pass, no warningsaiken fmt --checkandaiken buildpass;plutus.jsonis unchangedNot covered: the
n_public = 0path has no real proof to test against, only the generator-count test.🤖 Generated with Claude Code