github.com/consensys/gnark-crypto@v0.14.0/internal/generator/permutation/template/permutation.test.go.tmpl (about) 1 import ( 2 "math/big" 3 "testing" 4 5 "github.com/stretchr/testify/assert" 6 7 "github.com/consensys/gnark-crypto/ecc/{{ .Name }}/fr" 8 "github.com/consensys/gnark-crypto/ecc/{{ .Name }}/kzg" 9 ) 10 11 func TestProof(t *testing.T) { 12 13 kzgSrs, err := kzg.NewSRS(64, big.NewInt(13)) 14 assert.NoError(t, err) 15 16 a := make([]fr.Element, 8) 17 b := make([]fr.Element, 8) 18 19 for i := 0; i < 8; i++ { 20 a[i].SetUint64(uint64(4*i + 1)) 21 } 22 for i := 0; i < 8; i++ { 23 b[i].Set(&a[(5*i)%8]) 24 } 25 26 // correct proof 27 { 28 proof, err := Prove(kzgSrs.Pk, a, b) 29 if err != nil { 30 t.Fatal(err) 31 } 32 33 err = Verify(kzgSrs.Vk, proof) 34 if err != nil { 35 t.Fatal(err) 36 } 37 } 38 39 // wrong proof 40 { 41 a[0].SetRandom() 42 proof, err := Prove(kzgSrs.Pk, a, b) 43 if err != nil { 44 t.Fatal(err) 45 } 46 47 err = Verify(kzgSrs.Vk, proof) 48 if err == nil { 49 t.Fatal(err) 50 } 51 } 52 53 } 54 55 func BenchmarkProver(b *testing.B) { 56 57 srsSize := 1 << 15 58 polySize := 1 << 14 59 60 kzgSrs, _ := kzg.NewSRS(uint64(srsSize), big.NewInt(13)) 61 a := make([]fr.Element, polySize) 62 c := make([]fr.Element, polySize) 63 64 for i := 0; i < polySize; i++ { 65 a[i].SetUint64(uint64(i)) 66 } 67 for i := 0; i < polySize; i++ { 68 c[i].Set(&a[(5*i)%(polySize)]) 69 } 70 71 b.ResetTimer() 72 for i := 0; i < b.N; i++ { 73 Prove(kzgSrs.Pk, a, c) 74 } 75 76 }