arnaucube
arnaucube/kzg-commitments-studyPublic Self-hosted repository
kzg-commitments-study/README.md
README.mdRaw
 1# kzg-commitments-study [![GoDoc](https://godoc.org/github.com/arnaucube/kzg-commitments-study?status.svg)](https://godoc.org/github.com/arnaucube/kzg-commitments-study) [![Go Report Card](https://goreportcard.com/badge/github.com/arnaucube/kzg-commitments-study)](https://goreportcard.com/report/github.com/arnaucube/kzg-commitments-study) [![Test](https://github.com/arnaucube/kzg-commitments-study/workflows/Test/badge.svg)](https://github.com/arnaucube/kzg-commitments-study/actions?query=workflow%3ATest)
 2
 3Doing this to study and learn [KZG commitments](http://cacr.uwaterloo.ca/techreports/2010/cacr2010-10.pdf), do not use in production. More details at https://arnaucube.com/blog/kzg-commitments.html .
 4
 5Thanks to [Dankrad Feist](https://dankradfeist.de/ethereum/2020/06/16/kate-polynomial-commitments.html), [Alin Tomescu](https://alinush.github.io/2020/05/06/kzg-polynomial-commitments.html), [Tom Walton-Pocock](https://hackmd.io/@tompocock/Hk2A7BD6U) for their articles, which helped me understand a bit the KZG Commitments.
 6
 7### Usage
 8```go
 9// p(x) = x^3 + x + 5
10p := []*big.Int{
11	big.NewInt(5),
12	big.NewInt(1), // x^1
13	big.NewInt(0), // x^2
14	big.NewInt(1), // x^3
15}
16assert.Equal(t, "1x³ + 1x¹ + 5", PolynomialToString(p))
17
18// TrustedSetup
19ts, err := NewTrustedSetup(p)
20assert.Nil(t, err)
21
22// Commit
23c := Commit(ts, p)
24
25// p(z)=y --> p(3)=35
26z := big.NewInt(3)
27y := big.NewInt(35)
28
29// z & y: to prove an evaluation p(z)=y
30proof, err := EvaluationProof(ts, p, z, y)
31assert.Nil(t, err)
32
33// verification
34v := Verify(ts, c, proof, z, y)
35assert.True(t, v)
36```