You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

36 lines
1.5 KiB

2 years ago
  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. Doing 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 .
  3. Thanks 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.
  4. ### Usage
  5. ```go
  6. // p(x) = x^3 + x + 5
  7. p := []*big.Int{
  8. big.NewInt(5),
  9. big.NewInt(1), // x^1
  10. big.NewInt(0), // x^2
  11. big.NewInt(1), // x^3
  12. }
  13. assert.Equal(t, "1x³ + 1x¹ + 5", PolynomialToString(p))
  14. // TrustedSetup
  15. ts, err := NewTrustedSetup(p)
  16. assert.Nil(t, err)
  17. // Commit
  18. c := Commit(ts, p)
  19. // p(z)=y --> p(3)=35
  20. z := big.NewInt(3)
  21. y := big.NewInt(35)
  22. // z & y: to prove an evaluation p(z)=y
  23. proof, err := EvaluationProof(ts, p, z, y)
  24. assert.Nil(t, err)
  25. // verification
  26. v := Verify(ts, c, proof, z, y)
  27. assert.True(t, v)
  28. ```