Implementation of Kate-Zaverucha-Goldberg commitments (aka KZG commitments) over BN254.
import { commitVec, proveVec, verifyVec, Fr } from '@kevincharm/kate'
const vector = Array.from({ length: 5 }, () => Fr.rand())
// Commitment: C, ω
const commitment = await commitVec(vector)
// Proof: π
const { pi } = await proveVec(vector[0], 0n, commitment)
// Verify(C, ω, π, value, index)
await verifyVec(commitment.C, commitment.root, pi, vector[0], 0n) // === trueVector commitments are implemented as described here.
Let
Now to commit to a vector
Once we have computed the interpolated polynomial
where
To prove an element
Then, our proof is given by
and so
To verify
The verifier compares the following pairings and verifies that they are equivalent.
where
Note also that
The pairing check is equivalent to checking that the quotient polynomial
For each coefficient of any polynomial that we want to commit, we need an unrelated generator for which we don't know the discrete logarithm. To achieve this, we use the
Also see weijiekoh/libkzg which was very helpful as a reference in writing this implementation.