arnaucube 2e62793fd6 | 3 years ago | |
---|---|---|
.github/workflows | 3 years ago | |
.golangci.yml | 3 years ago | |
LICENSE | 3 years ago | |
README.md | 3 years ago | |
arithmetic.go | 3 years ago | |
arithmetic_test.go | 3 years ago | |
go.mod | 3 years ago | |
go.sum | 3 years ago | |
kzg.go | 3 years ago | |
kzg_test.go | 3 years ago |
Doing this to study and learn KZG commitments, do not use in production. More details at https://arnaucube.com/blog/kzg-commitments.html .
Thanks to Dankrad Feist, Alin Tomescu, Tom Walton-Pocock for their articles, which helped me understand a bit the KZG Commitments.
It uses the ethereum bn256.
// p(x) = x^3 + x + 5
p := []*big.Int{
big.NewInt(5),
big.NewInt(1), // x^1
big.NewInt(0), // x^2
big.NewInt(1), // x^3
}
assert.Equal(t, "1x³ + 1x¹ + 5", PolynomialToString(p))
// TrustedSetup
ts, err := NewTrustedSetup(p)
assert.Nil(t, err)
// Commit
c := Commit(ts, p)
// p(z)=y --> p(3)=35
z := big.NewInt(3)
y := big.NewInt(35)
// z & y: to prove an evaluation p(z)=y
proof, err := EvaluationProof(ts, p, z, y)
assert.Nil(t, err)
// verification
v := Verify(ts, c, proof, z, y)
assert.True(t, v)
Batch Proofs:
// zs & ys contain the f(z_i)=y_i values that will be proved inside a batch proof
zs := []*big.Int{z0, z1, z2}
ys := []*big.Int{y0, y1, y2}
// prove an evaluation of the multiple z_i & y_i
proof, err := EvaluationBatchProof(ts, p, zs, ys)
assert.Nil(t, err)
// batch proof verification
v := VerifyBatchProof(ts, c, proof, zs, ys)
assert.True(t, v)