Skip to content

Hide a number (Pedersen commitments)

View Markdown

Use this when a number has to live on a public ledger but stay private: a balance, a salary, a customer’s deposit. People can still check facts about it (“at least 1,000”, “inputs equal outputs”) and add many of them up, without ever seeing one.

A Pedersen commitment is a sealed envelope: a 32-byte curve point made from the value and a random blinding. It hides the value completely, it can’t be reopened as a different value, and commitments add up. A Groth16 proof can show facts about the hidden value.

Commitment · step 1 / 5
Alicecommits to an amount
amount vSECRETHIDDEN4,200 ADA████████
blinding r (random, 252 bits)SECRETHIDDEN0x209b…0cf4████████
Proves, without openingthe amount in C is at least 1,000 ADA
Public ledgeranyone can read it
C = v·G + r·HPUBLIC0x1d4a…86b2
Same amount, new blinding
C′ (also 4,200 ADA)PUBLIC0x283b…52a7
C and C′ look unrelated: nobody can tell they hide the same amount
Bob commits too
D (Bob)PUBLIC0x50b5…29db
C + DPUBLIC0x3fe7…5ca4
Anyone can add the points. Only someone who knows both openings can open the sum.
Verifieran auditor, a validator, a counterparty

Sees only C. Learns nothing about the amount.

Alice opens C to the verifiercommit(4,200 ADA, r) = C: acceptedTry another number. Some blinding would make it match C, but Alice can't feasibly find it: that would mean finding a second opening.
Opening the totalC + D opens to 6,700 ADA with blinding r + sThe verifier learns the total, not who put in what.
Checks π against Cproof valid: at least 1,000 ADA, amount still hidden

1. Seal

Alice picks an amount and a fresh random blinding and publishes one curve point, C = v·G + r·H. Think of a sealed envelope: everyone can see it, nobody can read it. Drag the amount or roll a new blinding and watch C change.

2. Hiding

Commit to the same amount again with a new blinding, and you get a completely different point. Because the blinding is random, C reveals nothing about the amount, not even whether two commitments hide the same one.

3. Open (binding)

Later, Alice can hand the opening (v, r) to someone she chooses. They recompute the point and compare it with C. A second opening for a different amount exists, but she can't feasibly find one, so C locks her in. Type another amount to see it fail.

4. Add

Commitments add up: C + D is the commitment to the sum of the amounts, with the sum of the blindings. A ledger can total balances, or check that inputs equal outputs, without seeing any single amount.

5. Prove without opening

A zero-knowledge proof can show a fact about the hidden amount, such as "at least 1,000 ADA", while C stays sealed. Drag Alice's amount below 1,000 ADA and no valid proof exists.

SECRET only Alice knows itPUBLIC anyone can see itPoint values are illustrative.
PartyLearns
The committerThe value and its blinding (the opening)
A verifier given a proofOnly the proven fact, such as “at least 1,000”
Someone given the openingThe value; they can check it matches the commitment
Everyone elseA 32-byte commitment that reveals nothing

Commit, publish 32 bytes, and open later:

CommitAndOpen.java (core)
import org.zeroj.circuit.lib.jubjub.JubjubPoint;
import org.zeroj.circuit.lib.jubjub.PedersenCommitment;
// Committer (offline): a fresh random blinding for every commitment
BigInteger value = BigInteger.valueOf(1_000);
BigInteger blinding = PedersenCommitment.randomBlinding(new SecureRandom());
byte[] published = PedersenCommitment.commit(value, blinding).toBytes(); // 32 bytes
// Verifier, later, given the opening (value, blinding)
JubjubPoint received = PedersenCommitment.decode(published); // checks the point
boolean opens = PedersenCommitment.verify(received, value, blinding); // true
boolean lies = PedersenCommitment.verify(received, BigInteger.valueOf(1_001), blinding); // false

Prove a fact without opening. This circuit proves “the committed value is at least the threshold”:

CommittedThreshold.java
import org.zeroj.circuit.annotation.*;
import org.zeroj.circuit.lib.zk.ZkPedersen;
@ZKCircuit(name = "committed-threshold", version = 1)
public class CommittedThreshold {
@Prove
ZkBool prove(ZkContext zk,
@Public ZkField commitmentU, // the commitment, as affine (u, v)
@Public ZkField commitmentV,
@Public @UInt(bits = 64) ZkUInt threshold,
@Secret @UInt(bits = 64) ZkUInt value, // never revealed
@Secret @UInt(bits = 252) ZkUInt blinding) { // must be exactly 252 bits
ZkPedersen.commit(zk, value, blinding).assertAffineEquals(zk, commitmentU, commitmentV);
return value.gte(threshold);
}
}

The Pedersen guide has both as complete, runnable programs, plus adding commitments and proving that amounts balance.

  • Proof of solvency. An exchange commits to every customer balance, proves the hidden total is covered by locked reserves, and each customer checks their own entry. (use case)
  • Confidential balances and transfers. Loyalty points or tokens move between holders, and a proof shows inputs equal outputs, with no amounts on the ledger. (use case)
  • Commit now, reveal later. Lock in a prediction, a price quote or a design hash today; open it after the deadline, and nobody can claim you changed it.
  • Committed credentials. A bureau commits to a credit profile; the holder proves “income ≥ 50,000” from it. (Prove a rule)
  • Product passports. An auditor commits to each measurement; the manufacturer proves “carbon ≤ 50 kg” without revealing it. (use case)
  • Someone else has to read the value without the owner’s help. A commitment opens only with the opening. Add chosen readers or encrypt for an auditor.
  • The value is a one-off answer. If nothing is stored on-chain, a plain predicate is simpler.
  • Sums wrap around. Commitment arithmetic is modulo a 252-bit number, so an unchecked sum can hide a “negative” amount. Prove every value’s range, and use ZkPedersen.assertBalanced, which refuses layouts that could wrap.
  • The blinding must be fresh, random and 252 bits. ZeroJ refuses circuits whose blinding is narrower, public or constant, but it can’t check that yours is random.
  • Create commitments offline. commit and randomBlinding run variable-time arithmetic on secrets; keep them on the user’s device or in an isolated process.
  • Decode received commitments with PedersenCommitment.decode, which checks the point is in the right subgroup.
  • Maturity. In-circuit commitments are ready, pending external review; sums and vector commitments are experimental.