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