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.

41 lines
755 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. // fmt.Println("p(x):", polynomialToString(p))
  16. assert.Equal(t, "1x³ + 1x¹ + 5", polynomialToString(p))
  17. // TrustedSetup
  18. ts, err := NewTrustedSetup(p)
  19. assert.Nil(t, err)
  20. // Commit
  21. c := Commit(ts, p)
  22. // p(z)=y --> p(3)=35
  23. z := big.NewInt(3)
  24. y := big.NewInt(35)
  25. // z & y: to prove an evaluation p(z)=y
  26. proof, err := EvaluationProof(ts, p, z, y)
  27. assert.Nil(t, err)
  28. v := Verify(ts, c, proof, z, y)
  29. assert.True(t, v)
  30. v = Verify(ts, c, proof, big.NewInt(4), y)
  31. assert.False(t, v)
  32. }