Introduction
Torben Pryds Pedersen introduced his non-interactive and information-theoretically secure verifiable secret sharing scheme at CRYPTO 1991. The construction's central innovation was a perfectly-hiding commitment primitive built on two generators of a prime-order group, now called the Pedersen commitment. Pedersen commitments underpin zero-knowledge proofs, multi-party computation, and verifiable random functions.
For Java learners, the Pedersen commitment is the simplest primitive that combines the discrete-logarithm assumption with information-theoretic hiding. The whole scheme fits in roughly 30 lines of BigInteger code while illustrating the binding-vs-hiding tradeoff that defines every commitment scheme.
What is a Pedersen Commitment?
A Pedersen commitment is a cryptographic commitment scheme in the discrete-logarithm family. Like every commitment scheme, it has two phases: commit, where the sender locks a value m into an opaque blob C, and open, where the sender reveals m and the randomizer r, and anyone can verify that C was generated from that pair. Pedersen commitments are perfectly hiding (the commitment reveals zero information about m, even to an attacker with infinite compute) and computationally binding (the sender cannot open the same commitment to two different values unless they solve a discrete-log problem).
Contrast Pedersen with the simpler hash-based commitment scheme C = H(m || r), which is computationally hiding under a random oracle but only computationally binding. The perfectly-hiding property of Pedersen makes it the right tool when information-theoretic privacy of the committed value matters, such as in coin-flipping protocols, sealed-bid auctions, and verifiable secret sharing where multiple commitments must be proved equal without revealing their common value.
How Pedersen Commitment Works - Step by Step
Step 1: Setup. Pick a prime p and a prime q dividing p-1 (so a prime-order subgroup of Z_p^* exists). Pick a generator g of the order-q subgroup. Pick a second generator h such that log_g(h) is unknown to the committer; in production this is done by hashing a random seed to a group element, while in our demo we use the small prime p=23, q=11, g=2, and h=4=g^2 (whose discrete log 2 is small enough to find by brute force).
Step 2: Commit. To commit to a message m in Z_q, sample a uniform random r in Z_q using a cryptographically secure random number generator. Compute C = g^m * h^r mod p. Send C to the verifier. The verifier learns nothing about m from C because for any candidate m' there is a unique r' that would produce the same C.
Step 3: Open. Reveal (m, r). The verifier recomputes g^m * h^r mod p and accepts if and only if the recomputed value equals C. Because of the randomizer r, even committing to the same m twice produces two different commitments C, defeating dictionary attacks.
Step 4: Binding argument. To open C to two different pairs (m, r) and (m', r') requires g^m * h^r = g^m' * h^r', which rearranges to g^(m - m') = h^(r' - r) and hence log_g(h) = (m - m') / (r' - r) mod q. Computing this fraction requires either knowing log_g(h) (which the setup hides) or solving a discrete-log problem in the prime-order subgroup.
Java Program for Pedersen Commitment with Hidden Value
import java.math.BigInteger;
import java.security.SecureRandom;
public class PedersenCommitmentDemo {
// Small prime p = 23, subgroup order q = 11 (11 | 22 = p - 1).
// g = 2 generates the order-11 subgroup of Z_23*.
// h = 4 = g^2 (in production log_g(h) is destroyed by setup).
private static final BigInteger P = BigInteger.valueOf(23);
private static final BigInteger Q = BigInteger.valueOf(11);
private static final BigInteger G = BigInteger.valueOf(2);
private static final BigInteger H = BigInteger.valueOf(4);
// C = g^m * h^r mod p
public static BigInteger commit(BigInteger m, BigInteger r) {
return G.modPow(m, P).multiply(H.modPow(r, P)).mod(P);
}
// Recompute and compare
public static boolean verify(BigInteger m, BigInteger r, BigInteger c) {
return commit(m, r).equals(c);
}
// Sample a fresh randomizer in Z_q
public static BigInteger sampleR() {
SecureRandom rng = new SecureRandom();
BigInteger r;
do {
r = new BigInteger(Q.bitLength(), rng);
} while (r.compareTo(Q) >= 0 || r.signum() <= 0);
return r;
}
public static void main(String[] args) {
BigInteger m = BigInteger.valueOf(3);
BigInteger r = sampleR();
// For reproducible output we override r here
r = BigInteger.valueOf(5);
BigInteger c = commit(m, r);
System.out.println("Committed to m = " + m + " with r = " + r);
System.out.println("Commitment C = " + c);
System.out.println("Verify (correct opening): " + verify(m, r, c));
// Breaking binding using the known discrete log log_g(h) = 2.
// For any m' the matching r' = r + (m - m') * log_g(h)^-1 mod q.
BigInteger logGH = BigInteger.valueOf(2);
BigInteger m2 = BigInteger.valueOf(7);
BigInteger diff = m.subtract(m2).multiply(logGH.modInverse(Q)).mod(Q);
BigInteger r2 = r.add(diff).mod(Q);
System.out.println("Alt opening m' = " + m2 + ", r' = " + r2);
System.out.println("Verify (alt opening): " + verify(m2, r2, c));
System.out.println("Binding broken because log_g(h) = " + logGH
+ " is known to the committer.");
}
}
Code Explanation - Line by Line
The constants P, Q, G, H encode the group parameters. P = 23 is a small prime, Q = 11 divides 22 = P-1, and G = 2 generates the order-11 subgroup of Z_23^* (you can verify that 2^11 mod 23 = 1). H = 4 is G squared, so the discrete log of H with respect to G is 2; in production this value would be sampled uniformly and destroyed so the committer never learns it.
The commit method performs two modular exponentiations and one multiplication mod p. The cost is dominated by the exponentiations, which for a 2048-bit prime group is a few milliseconds on a modern CPU. Because we work in the order-q subgroup of Z_p^*, all exponents are reduced mod q internally by BigInteger.modPow, ensuring the result lies in the subgroup.
The verify method is simply a recomputation of commit followed by an equality check via BigInteger.equals. It accepts the original (m, r) pair and rejects any pair (m', r') that does not produce the same commitment. In production you should use a constant-time comparison via MessageDigest.isEqual to avoid timing leaks.
The sampleR helper loops until SecureRandom produces a value in the range [1, q-1]. The main method overrides r to 5 for reproducible output, commits to m=3, and verifies the correct opening. Then it deliberately breaks binding using the known discrete log log_g(h) = 2. For any alternate message m' we compute the matching randomizer r' = r + (m - m') * log_g(h)^(-1) mod q, which is the unique value that makes g^m' * h^r' equal the original C. The verifier accepts the alternate opening, demonstrating that binding is only as strong as the secrecy of log_g(h).
Sample Input and Output
Committed to m = 3 with r = 5 Commitment C = 4 Verify (correct opening): true Alt opening m' = 7, r' = 3 Verify (alt opening): true Binding broken because log_g(h) = 2 is known to the committer.
The output shows that the commitment C = 4 verifies for both the original (m=3, r=5) and the alternate (m=7, r=3). The alternate opening is computable only because the demo knows log_g(h) = 2; in a real setup that value is hidden.
Common Mistakes to Avoid
1. Hardcoding a known discrete log of h with respect to g in production. If the committer knows log_g(h), they can compute alternate openings on demand and binding collapses. Always generate h by hashing a public, agreed-upon seed to a group element so that no one ever knows the discrete log.
2. Letting the randomizer r be 0 or reused across commitments to the same m. If r is fixed or repeated, the commitments become deterministic and an attacker can compare commitments to test message equality. Always sample r freshly per commitment using SecureRandom.
3. Working in the full Z_p^* group instead of the prime-order subgroup. The Legendre symbol leaks one bit of m if you use a generator of the full multiplicative group. Restrict exponents and group operations to the order-q subgroup.
4. Forgetting to reduce exponents mod q. BigInteger.modPow accepts any exponent, but if your exponents are larger than q you are wasting compute and might leak side-channel information through timing. Always reduce exponents mod q before calling modPow.
Real-World Applications
Pedersen commitments are the backbone of confidential transactions in blockchain protocols. Greg Maxwell's Confidential Transactions design, used in Liquid, Elements, and several privacy coins, commits to transaction amounts using Pedersen commitments and proves range and conservation via Bulletproofs. The perfectly-hiding property means an adversary examining the chain cannot learn any transaction amount, even with infinite compute.
In verifiable secret sharing, Pedersen commitments let shareholders verify that the shares they received are consistent with a single polynomial without revealing the polynomial itself. Feldman's VSS uses a single generator (computationally hiding), while Pedersen's VSS uses two generators (perfectly hiding). Threshold signature schemes like FROST for Schnorr signatures use Pedersen commitments in the preprocessing phase to defend against rogue-key attacks.
Voter-verifiable election schemes such as Civitas and Belenios use Pedersen commitments to encrypt ballot choices. The commitment is published on a public bulletin board so that anyone can verify the tally, but the perfectly-hiding property protects the secrecy of each individual ballot until the decryption phase.
In zero-knowledge proof systems like Bulletproofs and Plonk, Pedersen commitments are used as polynomial commitments. The prover commits to a polynomial f(x) by sending C = g^f * h^r, then proves properties of f such as range, evaluation, or membership without revealing the coefficients themselves.
Conclusion
Pedersen commitments combine perfectly-hiding and computationally-binding properties in a single discrete-logarithm primitive, occupying a unique niche in the commitment-scheme landscape. Our Java program demonstrates commit, verify, and a deliberate binding break using a known discrete log. Next study Feldman VSS (the computationally hiding variant), polynomial commitments (KZG and Bulletproofs), and zero-knowledge range proofs built on Pedersen commitments.
Comments
Comments
Post a Comment