Skip to content

Bulletproofs: decode a proof from a redeemer - #26

Merged
SamDelaney merged 3 commits into
mainfrom
sam/bulletproof-proof-data
Nov 19, 2026
Merged

SamDelaney merged 3 commits into
mainfrom
sam/bulletproof-proof-data

Conversation

@SamDelaney

Copy link
Copy Markdown
Collaborator

A validator couldn't take a Bulletproofs proof from its redeemer. BulletproofProof has State<Scalar> fields, and State is opaque in stdlib 3.0.0, so expect proof: BulletproofProof = redeemer is a compile error and the type can't be a redeemer type. A validator had to build the proof by hand from plain integers and compressed points.

What changes

  • New CompressedBulletproofProof: the same fields as plain data, with each point a 48-byte compressed G1 encoding and each scalar an Int.
  • New uncompress_proof, which turns it into a BulletproofProof. It fails unless every scalar lies in [0, r) and every point gets through g1.decompress, which rejects points off the curve or outside the prime-order subgroup.
    • Scalars are used mod r, so without the range check x + r and x - r would decode to the same proof as x, and one proof would have many encodings that all verify. The Groth16 and PLONK public inputs are checked the same way (common/inputs.ak).
    • It fails rather than returning None, like commit_value and the Groth16 and PLONK proof decoders. A bad point can't be reported any other way, since g1.decompress is a builtin that fails on one.
    • Vector lengths are left to verify, which already returns False unless l_vec and r_vec each have n entries.
  • New compress_proof, the reverse, for building a redeemer from a proof made with generate_proof.

A validator now looks like this:

validator range_check {
  spend(
    datum: Option<ByteArray>,
    redeemer: CompressedBulletproofProof,
    _own_ref: OutputReference,
    _self: Transaction,
  ) {
    expect Some(v_commit) = datum
    bullet.verify(
      bullet.setup(8),
      g1.decompress(v_commit),
      bullet.uncompress_proof(redeemer),
    )
  }

  else(_) {
    fail
  }
}

Tests

  • Unit tests in bullet.ak: a compressed proof round-trips and still verifies; tau_x + r is rejected; an l_vec entry given as x - r (negative) is rejected; a point whose x is not on the curve is rejected.
  • Properties in tests/bullet_props.ak: the round trip for any value, blinding and seed; tau_x, mu, or the first entry of l_vec or r_vec given as x + k·r (k from -1000 to 1000, not zero) is rejected; a point on the curve but outside the subgroup is rejected in each of a, s, t1 and t2.
  • Removing either half of the range check (x < 0, x >= r) makes a unit test and the scalar property fail. The point tests were checked by putting a valid point in place of the bad one, which makes both fail.

89 tests pass with aiken check -D (82 before). aiken fmt and aiken build are clean.

Cost

Measured at n = 8 with the validator above, which was built only to measure and isn't part of the package: 2,888 bytes when it calls setup(8), and 22,647 bytes with const vk = bullet.setup(8). One call to its spend handler, with the redeemer decoded from Data first, costs 3.40M memory and 8.09B CPU, about 0.23M and 0.28B more than verify on a proof that's already decoded. The implementation report's key table now uses this validator.

Docs

The Bulletproofs report covers the new type and functions in §3, the new tests in §7, and the re-measured key table in §4. In §8, the "No on-chain entry point yet" limitation is replaced by what's still left to a validator: deciding why to trust V. All three report headers now count 89 tests, and the PLONK header's tests/point_props count is corrected from 5 to 4.

SamDelaney and others added 3 commits November 18, 2026 13:10
BulletproofProof can't come from a redeemer, because its scalars are
State<Scalar>, which is opaque in stdlib 3.0.0, so expect on Data is a
compile error. Add CompressedBulletproofProof, with compressed G1 points as
ByteArray and scalars as Int, plus uncompress_proof and compress_proof.

uncompress_proof fails unless every scalar is in [0, r), since scalars are
used mod r and x + r or x - r would otherwise decode to the same proof.
Points go through g1.decompress, which fails off the curve or outside the
subgroup. It fails rather than returning None, like commit_value and the
Groth16 and PLONK decoders.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A compressed proof decodes to one that verifies and re-encodes to the same
data; tau_x, mu, or an l_vec or r_vec entry given as x + k * r (negative for
k < 0) is rejected; and a point outside the subgroup in any of the four
point fields is rejected.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Bulletproofs report: CompressedBulletproofProof, uncompress_proof and
compress_proof in section 3, the new tests in section 7, and the
"No on-chain entry point yet" limitation replaced by what is still left to
a validator (trusting V). The key table in section 4 is re-measured with a
spend validator that takes V from its datum and the proof from its
redeemer: 2,888 bytes calling setup(8), 22,647 bytes with a constant key.

Test counts go from 82 to 89 in all three report headers. The PLONK
header also said 5/5 for tests/point_props, which has 4 tests.

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 are recorded for the compressed Bulletproof proof representation and conversion changes.

No open issues 🎉

What changed in this PR

This PR lets validators receive Bulletproofs proofs through redeemers or datums, avoiding the opaque scalar types in BulletproofProof.

Changes:

  • Adds CompressedBulletproofProof and conversion functions with scalar-range and point validation.
  • Adds unit and property tests for round trips and rejection of invalid encodings.
  • Documents validator integration, updated cost measurements, and reported test totals.
File Description
zkp/​lib/​tests/​bullet_props.ak Adds round-trip, scalar-range, and subgroup-rejection properties.
zkp/​lib/​bullet/​bullet.ak Adds the plain-data proof type, encoding/decoding functions, and unit tests.
zkp/​docs/​plonk-implementation-report.md Updates the package test total and corrects the point-property count.
zkp/​docs/​groth16-implementation-report.md Updates the package test total.
zkp/​docs/​bulletproofs-implementation-report.md Documents the new API, validator example, tests, costs, and remaining integration responsibilities.

Review effort: Balanced

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 change to support compressed Bulletproof proof decoding.

No open issues 🎉

Review effort: Balanced

@SamDelaney
SamDelaney merged commit a52b5ba into main Nov 19, 2026
3 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

Development

Successfully merging this pull request may close these issues.

2 participants