Skip to content

Check the count and range of public inputs in Groth16 and PLONK - #23

Open
SamDelaney wants to merge 7 commits into
mainfrom
sam/input-checks
Open

SamDelaney wants to merge 7 commits into
mainfrom
sam/input-checks

Conversation

@SamDelaney

@SamDelaney SamDelaney commented Nov 18, 2026 •

Copy link
Copy Markdown
Collaborator

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); 3c01e4c removes it.

Fixes #11, fixes #12, fixes #13, fixes #14, fixes #19.

Changes

Commit Issue Change
b9f37e5 #11 Groth16 verify returns False unless there is exactly one input per vkIC entry after the first, using a new check_public_inputs in common/inputs.ak. derive now fails if either list runs out before the other.
704c7a0 #13 PreparedPlonkPreInputs gains an n_public field, and verify_plonk checks the input count against it with the same helper.
a6a045c #12 check_public_inputs also requires every input to lie in [0, r), in both verifiers.
696f97d #14 verify_plonk requires exactly one Lagrange inverse per generator.
b76d87c #19 plonk_prepare_preinputs builds max(1, n_public) generators instead of n_public + 1. It keeps at least one because the permutation check always uses L_1.
bb85252 #14 The inverse count is checked in the same walk that checks each inverse, instead of by two list.length calls up front. An empty inverse list is still caught up front, so it returns False rather than an error.

Behaviour changes

  • Malformed inputs return False rather than trapping, so a caller can branch on the result. Too few Groth16 inputs used to trap.
  • PreparedPlonkPreInputs has a new n_public field. Code that builds it directly, rather than through plonk_prepare_preinputs, has to set it.

Tests

Cost

Before After
Groth16 verify_compressed 66.9K mem / 2.79B CPU 89.6K mem / 2.80B CPU
PLONK fixture (prepare and verify) 6.68M mem / 8.63B CPU 4.78M mem / 8.03B CPU

The 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 separate list.length calls 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 warnings
  • aiken fmt --check and aiken build pass; plutus.json is unchanged

Not covered: the n_public = 0 path has no real proof to test against, only the generator-count test.

🤖 Generated with Claude Code

SamDelaney and others added 7 commits November 17, 2026 16:02
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>

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 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

Comment thread zkp/lib/plonk/verifier.ak
proof: PreparedPlonkProof,
) -> Bool {
and {
check_public_inputs(pub_inputs, preinputs.n_public),
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

2 participants