AI & Data
Pedersen commitments
Hiding, binding commitments over Ristretto255, with homomorphic addition.
Overview
Commit to a value m by publishing C = m·G + r·H with a random blinding factor r. H is derived by hash-to-curve from a domain-separation string, so nobody knows its discrete log relative to G. Commitments add: the sum commits to the sum of values.
The code
src/lib.rsView on GitHub ↗
impl PedersenParams {
pub fn new() -> Self {
let g = curve25519_dalek::constants::RISTRETTO_BASEPOINT_POINT;
let hash: [u8; 64] = Sha512::digest(b"pedersen-commitment-h-generator-v1").into();
let h = RistrettoPoint::from_uniform_bytes(&hash);
PedersenParams { g, h }
}
pub fn commit_with_randomness(&self, value: Scalar, randomness: Scalar) -> Commitment {
// C = m·G + r·H
let point = value * self.g + randomness * self.h;
Commitment { point }
}
pub fn verify(&self, commitment: &Commitment, opening: &Opening) -> bool {
let expected = self.commit_with_randomness(opening.value, opening.randomness);
expected.point == commitment.point
}
}
impl Commitment {
/// (m1·G + r1·H) + (m2·G + r2·H) = (m1+m2)·G + (r1+r2)·H
pub fn add(&self, other: &Commitment) -> Commitment {
Commitment { point: self.point + other.point }
}
}
How it works
- Generators G (Ristretto basepoint) and H (hash-to-curve)
- Commit with fresh 512-bit randomness reduced mod the group order
- Open and verify, plus homomorphic add