Skip to content

Bulletproofs: range-check commit_value, make the key opaque, hide the seeded prover - #25

Merged
SamDelaney merged 4 commits into
mainfrom
sam/bulletproof-fixes
Nov 18, 2026
Merged

SamDelaney merged 4 commits into
mainfrom
sam/bulletproof-fixes

Conversation

@SamDelaney

@SamDelaney SamDelaney commented Nov 18, 2026 •

Copy link
Copy Markdown
Collaborator

Fixes the three Bulletproofs issues, one commit each, plus a correction to the report's verify cost found while measuring for #17.

Fixes #16. Fixes #17. Fixes #18.

Changes

Commit Change
cd12d66 #16: commit_value fails unless 0 <= value < r. It used to reduce the value mod r, so a commitment to 200 + r or 200 - r was the same point as one to 200, and 200's range proof verified against it.
41939a3 #17: BulletproofVerificationKey is opaque, so setup is the only way to make one. A key can no longer be decoded from a redeemer, datum or other Data, or built from chosen points.
f2b2c1f #18: generate_proof_deterministic is removed. The tests derive their own seeded blinding; the only public prover is generate_proof, which takes the blinding from the caller.
1aab9e6 Report fix: the "full verify call" cost of 5.2M memory and 14.2B CPU was the whole range_proof_valid test (setup, proving and verifying), and 14.2B is over the 10B per-transaction limit. verify on its own is given instead.

Design notes

#16, why r and not 2^n. With the bound at r, each accepted Int gives its own point, and the range proof still decides whether the value is below 2^n. A commitment to a value between 2^n and r, for homomorphic arithmetic, keeps working.

#17, why not bind the key into the transcript. The issue's first suggestion wouldn't stop the attack: a prover who chooses the generators (h = k * g, say) knows their relations before any challenge is drawn, so hashing them into the transcript changes nothing. The whole key has to come from setup. An opaque type enforces that at compile time. Checked with Aiken v1.1.21:

  • outside bullet.ak, expect from Data into the key (aiken::check::illegal::expect_on_opaque), a record update of it, and reading its fields are compile errors;
  • aiken build refuses the key in a validator's redeemer, datum or parameter, nested or not;
  • before this change, expect from Data into the key compiled and accepted a key with h = g.

Nothing outside bullet.ak built a key or read its fields, so no caller in the package changes.

#17, how a validator should hold the key. The old setup comment said to embed the key as a constant. Measured at n = 8 with a spend validator that builds the proof from plain integers and compressed points:

Key Script size Check cost (verify, plus setup where called)
bullet.setup(8) called in the validator 2,955 bytes 3.16M memory, 7.81B CPU
const vk = bullet.setup(8) 22,714 bytes 3.00M memory, 5.83B CPU

The constant is evaluated at compile time, which saves about 2B CPU, but at n = 8 the script is over the 16,384-byte transaction limit (11,257 bytes at n = 2). The comments and docs now say to fix n in the validator and call setup(n) there.

Behaviour changes

  • commit_value fails for a value outside [0, r), a negative one included, instead of reducing it.
  • BulletproofVerificationKey's fields can't be read or set outside bullet.ak.
  • generate_proof_deterministic no longer exists; callers supply a ProofBlinding to generate_proof.

Tests

Not in this PR

A validator can't expect a BulletproofProof from its redeemer either: its State<Scalar> fields are an opaque stdlib type. It has to build the proof from plain integers and compressed points, as the sample validator above does. A decoder for that is separate work.

Checks

  • aiken check -D: 82 tests, all pass, no warnings
  • aiken fmt --check and aiken build pass

SamDelaney and others added 4 commits November 18, 2026 12:41
commit_value took the value as an Int and reduced it mod r, so a
commitment to value + k * r, a negative amount included, was the same
point as one to value, and value's range proof verified against it. A
validator that builds V from an Int amount could be given 200 - r and
accept it as 200. commit_value now fails unless 0 <= value < r.

The bound is r rather than 2^n: each accepted Int then gives its own
point, and the range proof still decides whether the value is below
2^n. A commitment to a value between 2^n and r, for homomorphic
arithmetic, keeps working.

known_issue_16 becomes prop_bullet_commit_value_rejects_out_of_field
(the same call must now fail for every k). New unit tests: commit_value
fails for r and for -1, and accepts 0 and r - 1. Mutation-checked:
dropping the check, or moving either bound by one, fails a test.

Cost: two integer comparisons. verify doesn't call commit_value, so its
cost is unchanged.

Fixes #16

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
verify trusts every generator in the key it is given. A validator that
took the key from a redeemer or datum let the prover choose them, and a
prover who picks h = k * g can open a commitment to any value. The
issue's first suggestion, hashing the key into the transcript, wouldn't
stop that: such a prover knows the relations before any challenge is
drawn. So BulletproofVerificationKey is now opaque, and setup is the
only way to make one.

Checked with Aiken v1.1.21: outside bullet.ak, expect from Data into the
key, a record update of it, and reading its fields are compile errors,
and aiken build refuses it in a validator's redeemer, datum or
parameter. Before this, expect from Data into the key compiled and
accepted a key with h = g. Nothing outside bullet.ak built a key or read
its fields, so no caller changes.

The setup comment said to embed the key as a constant. A spend
validator that does so is 22,714 bytes at n = 8, over the 16,384-byte
transaction limit, against 2,955 bytes when it calls setup(8) itself,
which costs about 2B CPU more (7.81B against 5.83B for the check). The
comments and docs now say to fix n and call setup in the validator, and
the report has both sets of figures. The property tests hold the key as
a constant, so setup runs once instead of in every case.

Fixes #17

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
generate_proof_deterministic was public although its comment called it
test-only. It derives every blinding factor from a seed, so anyone with
the seed can read the committed value back from l_vec, and a proof made
with it hides nothing. Someone integrating the library could easily
take it for the prover.

It is removed. bullet.ak's own tests call generate_proof with the
private derive_blinding, whose comment now says why it mustn't be used
for real proofs, and tests/bullet_props has its own seeded_blinding
built on scalar.from_bytes. The only public prover is generate_proof,
which takes the blinding from the caller.

This is a breaking change for anyone who called
generate_proof_deterministic; they need to supply their own blinding.

Fixes #18

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The report said a full verify call at n = 8 costs about 5.2M memory and
14.2B CPU, "comfortably within" the per-transaction budget. 14.2B is
over the 10B CPU limit, and it isn't verify's cost: it matches
range_proof_valid, which also runs setup and builds the proof.

Measured on its own with Aiken v1.1.21, verify costs 3.00M memory and
5.83B CPU with a constant key, proof and commitment, or 3.16M and 7.81B
when setup(8) is called alongside it, as a validator has to (see the
previous commit). The report now gives those, the limits, and the unit
test's figure for comparison.

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.

🟢 Approval recommended

No active review issues block the Bulletproofs API hardening and documentation updates.

No open issues 🎉

What changed in this PR

This PR hardens the Bulletproofs API to address #16–#18 and corrects the documentation’s verification-cost estimates.

Changes:

  • Rejects commitment values outside [0, r) and adds boundary and property regression tests.
  • Makes verification keys opaque and removes the public deterministic prover, keeping seeded blinding in test helpers.
  • Updates validator setup guidance, execution-cost figures, and documented test totals.
File Description
zkp/​lib/​tests/​bullet_props.ak Adds local seeded blinding, a constant key, and an out-of-field rejection property.
zkp/​lib/​bullet/​bullet.ak Enforces commitment bounds, makes keys opaque, removes the seeded prover API, and adds boundary tests.
zkp/​docs/​step-by-step.md Documents commitment bounds and validator-controlled key setup.
zkp/​docs/​plonk-implementation-report.md Updates package-wide test totals to 82.
zkp/​docs/​groth16-implementation-report.md Updates the package-wide test total to 82.
zkp/​docs/​bulletproofs-implementation-report.md Documents API hardening, regression tests, and corrected verification costs and setup tradeoffs.

Review effort: Balanced

@SamDelaney
SamDelaney merged commit 04d938f into main Nov 18, 2026
2 checks passed
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