arnaucube
arnaucube/kzg-commitments-studyPublic Self-hosted repository
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	assert.Equal(t, "1x³ + 1x¹ + 5", PolynomialToString(p))
19
20	// TrustedSetup
21	ts, err := NewTrustedSetup(p)
22	assert.Nil(t, err)
23
24	// Commit
25	c := Commit(ts, p)
26
27	// p(z)=y --> p(3)=35
28	z := big.NewInt(3)
29	y := big.NewInt(35)
30
31	// z & y: to prove an evaluation p(z)=y
32	proof, err := EvaluationProof(ts, p, z, y)
33	assert.Nil(t, err)
34
35	v := Verify(ts, c, proof, z, y)
36	assert.True(t, v)
37
38	v = Verify(ts, c, proof, big.NewInt(4), y)
39	assert.False(t, v)
40}