-
Notifications
You must be signed in to change notification settings - Fork 23
/
Copy pathexamples_test.go
53 lines (45 loc) · 1.61 KB
/
examples_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
package goethkzg_test
import (
"testing"
goethkzg "github.com/crate-crypto/go-eth-kzg"
"github.com/stretchr/testify/require"
)
// Globally initialize a ctx for tests.
var ctx, _ = goethkzg.NewContext4096Secure()
func TestBlobProveVerifyRandomPointIntegration(t *testing.T) {
blob := GetRandBlob(123)
commitment, err := ctx.BlobToKZGCommitment(blob, NumGoRoutines)
require.NoError(t, err)
proof, err := ctx.ComputeBlobKZGProof(blob, commitment, NumGoRoutines)
require.NoError(t, err)
err = ctx.VerifyBlobKZGProof(blob, commitment, proof)
require.NoError(t, err)
}
func TestBlobProveVerifySpecifiedPointIntegration(t *testing.T) {
blob := GetRandBlob(123)
commitment, err := ctx.BlobToKZGCommitment(blob, NumGoRoutines)
require.NoError(t, err)
inputPoint := GetRandFieldElement(123)
proof, claimedValue, err := ctx.ComputeKZGProof(blob, inputPoint, NumGoRoutines)
require.NoError(t, err)
err = ctx.VerifyKZGProof(commitment, inputPoint, claimedValue, proof)
require.NoError(t, err)
}
func TestBlobProveVerifyBatchIntegration(t *testing.T) {
batchSize := 5
blobs := make([]goethkzg.Blob, batchSize)
commitments := make([]goethkzg.KZGCommitment, batchSize)
proofs := make([]goethkzg.KZGProof, batchSize)
for i := 0; i < batchSize; i++ {
blob := GetRandBlob(int64(i))
commitment, err := ctx.BlobToKZGCommitment(blob, NumGoRoutines)
require.NoError(t, err)
proof, err := ctx.ComputeBlobKZGProof(blob, commitment, NumGoRoutines)
require.NoError(t, err)
blobs[i] = *blob
commitments[i] = commitment
proofs[i] = proof
}
err := ctx.VerifyBlobKZGProofBatch(blobs, commitments, proofs)
require.NoError(t, err)
}