Path: blob/main/frontier/09-commitments-sigma-protocols/sage/09b-pedersen-commitments.ipynb
483 views
Pedersen Commitments
Module 09b | Commitments and Sigma Protocols
Can you commit to a secret so that even an all-powerful adversary learns nothing about it?
Motivating Question: In 09a we saw hash-based commitments: . They are computationally hiding, an efficient adversary can't determine from . But an adversary with unlimited computing power could brute-force every possible and find which message was committed. Can we do better?
Pedersen commitments can. They achieve perfect hiding: even with infinite computational power, the commitment reveals absolutely zero information about . The price? Binding becomes computational rather than perfect, it relies on the hardness of the discrete logarithm problem (Module 05).
Objectives
By the end of this notebook you will be able to:
Set up Pedersen commitment parameters and explain why must be unknown
Commit to a message with randomness and verify the opening
Prove that Pedersen commitments are perfectly hiding by finding alternative openings
Explain why breaking binding requires solving the DLP
Use the homomorphic property to add commitments without opening them
Extend to vector Pedersen commitments for committing to multiple values at once
Prerequisites
Completion of 09a: Commitment Schemes (hiding and binding properties)
Familiarity with the discrete logarithm problem (05a)
Modular exponentiation in prime-order groups (01d)
The Pedersen Setup
The Pedersen commitment scheme works in a prime-order subgroup of . The setup requires:
A large prime such that for another prime (a safe prime)
Two generators and of the subgroup of order
Crucially: nobody knows , the discrete log of with respect to
Why must be unknown? We'll see shortly that knowing it would let you break binding.
For pedagogical clarity, we'll start with small primes. In practice, would be at least 256 bits.
Checkpoint: Why do we compute
g = a^2to get a generator of the order- subgroup? Think about it: has order . Squaring any element sends it into the unique subgroup of order (the quadratic residues). As long as , it generates this entire subgroup because is prime.
Commit and Reveal
The Pedersen commitment to message with randomness is:
Commit phase: Choose random , compute , send to verifier
Reveal phase: Send to verifier, who checks
Perfect Hiding
Here is the key insight that makes Pedersen commitments special.
Claim: For any commitment and any target message , there exists exactly one such that .
Why? If , then we need , which gives . Setting ... but wait, we don't know ! The point is that such an exists mathematically.
This means the commitment is consistent with every possible message. An adversary looking at gains literally zero information about . This is information-theoretic hiding, it holds even against computationally unbounded adversaries.
Let's verify this concretely. Since we're in a teaching setting, we can compute for our small parameters and demonstrate the alternative opening.
Checkpoint: We just showed that commitment can be "opened" to (and any other value). Convince yourself: why does this prove that seeing gives an adversary no information about ? The key is that the distribution of is identical regardless of which was committed, because was chosen uniformly at random.
Computational Binding
If Pedersen commitments are perfectly hiding, how can they be binding at all?
Common mistake: "If the commitment is perfectly hiding, how can it be binding at all?" The resolution: binding is computational, not information-theoretic. An adversary with unlimited computation could break binding. But an efficient adversary cannot, because doing so requires solving the DLP.
Why breaking binding implies solving the DLP:
Suppose a cheating committer finds two openings and with for the same commitment :
Then , which gives:
So breaking binding directly reveals , it solves the DLP!
The Hiding-Binding Duality
In 09a we learned that commitments have two security properties: hiding and binding. Here is a fundamental result:
| Scheme | Hiding | Binding |
|---|---|---|
| Hash commitment | Computational | Perfectly binding (collision-free) |
| Pedersen | Perfect | Computational (DLP-hard) |
A deep theorem states: no commitment scheme can be both perfectly hiding AND perfectly binding. Intuitively:
Perfect hiding means every is consistent with every , so alternative openings exist
Perfect binding means only one valid opening exists, so leaks some information
You must choose one to be perfect and the other computational. Pedersen chooses perfect hiding because in many cryptographic protocols (zero-knowledge proofs, confidential transactions), the prover needs the strongest possible privacy guarantee.
The Homomorphic Property
This is the feature that makes Pedersen commitments a cornerstone of modern cryptography.
Given two commitments:
Their product is:
Commitments can be added without opening them! Nobody needs to know or individually, the product of the commitments is a valid commitment to the sum of the messages.
Checkpoint: What happens if you raise a commitment to a scalar ? We get . Pedersen commitments are homomorphic under scalar multiplication too! Together with addition, this makes them linearly homomorphic.
Visualizing the Commitment Distribution
Let's verify perfect hiding visually. We commit to two different messages and many times (with fresh random each time) and plot the distribution of the resulting commitments. If hiding is perfect, the two distributions should be indistinguishable.
Both histograms should look uniformly distributed across the group, identical distributions regardless of the committed message. This is perfect hiding in action: the commitment value carries zero information about .
Vector Pedersen Commitments
What if you want to commit to multiple values at once? The vector Pedersen commitment generalizes the scheme:
where are independent generators (nobody knows any discrete log relation between them).
This is much more efficient than making separate commitments: a single group element commits to an entire vector.
Exercises
Exercise 1 (Worked)
Task: Set up Pedersen parameters with the safe prime (so ). Find generators and of the order-11 subgroup. Commit to with . Then find an alternative opening with that produces the same commitment.
This exercise reinforces the perfect hiding property by working through a small concrete example where we can compute by hand.
Exercise 2 (Guided)
Task: Demonstrate the homomorphic property with a concrete application. Alice commits to her age and Bob commits to his age . Without either revealing their age, compute a commitment to the sum of their ages and verify it.
Use the parameters from the main setup above.
Hints:
Create two commitments and with different messages and randomness
Compute
Verify that opens with message and randomness
Exercise 3 (Independent)
Task: Implement a "balance proof" system. A bank commits to each customer's balance using Pedersen commitments. Given customer balances, show that the bank can prove the total deposits equal a claimed amount by:
Computing individual commitments for each balance
Computing the product (homomorphic sum)
Opening with and to prove the total
Choose your own balances and verify the entire flow. Bonus: what happens if the bank tries to lie about the total? Show that the verification fails.
Summary
| Concept | Key idea |
|---|---|
| Pedersen setup | Prime-order group with generators and where is unknown |
| Commitment | , opened by revealing |
| Perfectly hiding | For any and any , there exists with , so the commitment leaks zero information, even to an unbounded adversary |
| Computationally binding | Finding two valid openings implies solving the DLP |
| Hiding-binding duality | You cannot have both perfect hiding and perfect binding. Pedersen trades perfect binding for perfect hiding (opposite of hash commitments) |
| Homomorphic | , so commitments can be added without opening |
| Vector commitments | commits to an entire vector in one group element |
Crypto foreshadowing: The homomorphic property of Pedersen commitments is the foundation of Bulletproofs range proofs and confidential transactions in Monero and Mimblewimble. When you send cryptocurrency in these systems, the transaction amounts are hidden inside Pedersen commitments, and miners can verify that inputs equal outputs without seeing any amounts, using exactly the homomorphic addition we demonstrated above. In 09c, we'll see how Pedersen commitments combine with sigma protocols to build zero-knowledge proofs.