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.

40 lines
707 B

  1. package kzg
  2. import (
  3. "math/big"
  4. "testing"
  5. "github.com/stretchr/testify/assert"
  6. )
  7. func TestSimpleFlow(t *testing.T) {
  8. // p(x) = x^3 + x + 5
  9. p := []*big.Int{
  10. big.NewInt(5),
  11. big.NewInt(1), // x^1
  12. big.NewInt(0), // x^2
  13. big.NewInt(1), // x^3
  14. }
  15. assert.Equal(t, "1x³ + 1x¹ + 5", PolynomialToString(p))
  16. // TrustedSetup
  17. ts, err := NewTrustedSetup(p)
  18. assert.Nil(t, err)
  19. // Commit
  20. c := Commit(ts, p)
  21. // p(z)=y --> p(3)=35
  22. z := big.NewInt(3)
  23. y := big.NewInt(35)
  24. // z & y: to prove an evaluation p(z)=y
  25. proof, err := EvaluationProof(ts, p, z, y)
  26. assert.Nil(t, err)
  27. v := Verify(ts, c, proof, z, y)
  28. assert.True(t, v)
  29. v = Verify(ts, c, proof, big.NewInt(4), y)
  30. assert.False(t, v)
  31. }