2023-04-10 13:03:36 +00:00
|
|
|
package ckzg4844
|
2023-01-26 17:04:24 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"math/rand"
|
|
|
|
"os"
|
2023-02-20 16:01:31 +00:00
|
|
|
"path/filepath"
|
2023-01-26 17:04:24 +00:00
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/stretchr/testify/require"
|
2023-03-06 10:04:29 +00:00
|
|
|
"gopkg.in/yaml.v3"
|
2023-01-26 17:04:24 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestMain(m *testing.M) {
|
2023-03-30 00:33:15 +00:00
|
|
|
err := LoadTrustedSetupFile("../../src/trusted_setup.txt")
|
|
|
|
if err != nil {
|
2023-01-26 17:04:24 +00:00
|
|
|
panic("failed to load trusted setup")
|
|
|
|
}
|
|
|
|
defer FreeTrustedSetup()
|
|
|
|
code := m.Run()
|
|
|
|
os.Exit(code)
|
|
|
|
}
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Helper Functions
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2023-04-10 13:03:36 +00:00
|
|
|
func getRandFieldElement(seed int64) Bytes32 {
|
2023-01-26 17:04:24 +00:00
|
|
|
rand.Seed(seed)
|
|
|
|
bytes := make([]byte, 31)
|
|
|
|
_, err := rand.Read(bytes)
|
|
|
|
if err != nil {
|
|
|
|
panic("failed to get random field element")
|
|
|
|
}
|
|
|
|
|
2023-05-24 13:44:05 +00:00
|
|
|
// This leaves the first byte in fieldElementBytes as
|
2023-01-26 17:04:24 +00:00
|
|
|
// zero, which guarantees it's a canonical field element.
|
|
|
|
var fieldElementBytes Bytes32
|
2023-05-24 13:44:05 +00:00
|
|
|
copy(fieldElementBytes[1:], bytes)
|
2023-01-26 17:04:24 +00:00
|
|
|
return fieldElementBytes
|
|
|
|
}
|
|
|
|
|
2023-04-10 13:03:36 +00:00
|
|
|
func getRandBlob(seed int64) Blob {
|
2023-01-26 17:04:24 +00:00
|
|
|
var blob Blob
|
|
|
|
for i := 0; i < BytesPerBlob; i += BytesPerFieldElement {
|
2023-04-10 13:03:36 +00:00
|
|
|
fieldElementBytes := getRandFieldElement(seed + int64(i))
|
2023-01-26 17:04:24 +00:00
|
|
|
copy(blob[i:i+BytesPerFieldElement], fieldElementBytes[:])
|
|
|
|
}
|
|
|
|
return blob
|
|
|
|
}
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
2023-04-10 13:03:36 +00:00
|
|
|
// Reference Tests
|
2023-01-26 17:04:24 +00:00
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2023-02-20 16:01:31 +00:00
|
|
|
var (
|
|
|
|
testDir = "../../tests"
|
2023-03-06 10:04:29 +00:00
|
|
|
blobToKZGCommitmentTests = filepath.Join(testDir, "blob_to_kzg_commitment/*/*/*")
|
|
|
|
computeKZGProofTests = filepath.Join(testDir, "compute_kzg_proof/*/*/*")
|
|
|
|
computeBlobKZGProofTests = filepath.Join(testDir, "compute_blob_kzg_proof/*/*/*")
|
|
|
|
verifyKZGProofTests = filepath.Join(testDir, "verify_kzg_proof/*/*/*")
|
|
|
|
verifyBlobKZGProofTests = filepath.Join(testDir, "verify_blob_kzg_proof/*/*/*")
|
|
|
|
verifyBlobKZGProofBatchTests = filepath.Join(testDir, "verify_blob_kzg_proof_batch/*/*/*")
|
2023-02-20 16:01:31 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestBlobToKZGCommitment(t *testing.T) {
|
2023-03-06 10:04:29 +00:00
|
|
|
type Test struct {
|
|
|
|
Input struct {
|
2023-03-08 13:30:09 +00:00
|
|
|
Blob string `yaml:"blob"`
|
2023-03-06 10:04:29 +00:00
|
|
|
}
|
|
|
|
Output *Bytes48 `yaml:"output"`
|
|
|
|
}
|
|
|
|
|
2023-02-20 16:01:31 +00:00
|
|
|
tests, err := filepath.Glob(blobToKZGCommitmentTests)
|
|
|
|
require.NoError(t, err)
|
2023-03-15 14:39:19 +00:00
|
|
|
require.True(t, len(tests) > 0)
|
|
|
|
|
2023-03-06 10:04:29 +00:00
|
|
|
for _, testPath := range tests {
|
2023-03-08 14:14:39 +00:00
|
|
|
t.Run(testPath, func(t *testing.T) {
|
|
|
|
testFile, err := os.Open(testPath)
|
|
|
|
require.NoError(t, err)
|
|
|
|
test := Test{}
|
|
|
|
err = yaml.NewDecoder(testFile).Decode(&test)
|
|
|
|
require.NoError(t, testFile.Close())
|
|
|
|
require.NoError(t, err)
|
2023-03-08 13:30:09 +00:00
|
|
|
|
2023-03-08 14:14:39 +00:00
|
|
|
var blob Blob
|
|
|
|
err = blob.UnmarshalText([]byte(test.Input.Blob))
|
|
|
|
if err != nil {
|
|
|
|
require.Nil(t, test.Output)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2023-03-30 00:33:15 +00:00
|
|
|
commitment, err := BlobToKZGCommitment(blob)
|
|
|
|
if err == nil {
|
2023-03-08 14:14:39 +00:00
|
|
|
require.NotNil(t, test.Output)
|
|
|
|
require.Equal(t, test.Output[:], commitment[:])
|
|
|
|
} else {
|
|
|
|
require.Nil(t, test.Output)
|
|
|
|
}
|
|
|
|
})
|
2023-01-26 17:04:24 +00:00
|
|
|
}
|
2023-02-20 16:01:31 +00:00
|
|
|
}
|
2023-01-26 17:04:24 +00:00
|
|
|
|
2023-02-20 16:01:31 +00:00
|
|
|
func TestComputeKZGProof(t *testing.T) {
|
2023-03-06 10:04:29 +00:00
|
|
|
type Test struct {
|
|
|
|
Input struct {
|
2023-03-08 13:30:09 +00:00
|
|
|
Blob string `yaml:"blob"`
|
|
|
|
Z string `yaml:"z"`
|
2023-03-06 10:04:29 +00:00
|
|
|
}
|
2023-03-08 11:45:54 +00:00
|
|
|
Output *[]string `yaml:"output"`
|
2023-03-06 10:04:29 +00:00
|
|
|
}
|
|
|
|
|
2023-02-20 16:01:31 +00:00
|
|
|
tests, err := filepath.Glob(computeKZGProofTests)
|
2023-01-26 17:04:24 +00:00
|
|
|
require.NoError(t, err)
|
2023-03-15 14:39:19 +00:00
|
|
|
require.True(t, len(tests) > 0)
|
|
|
|
|
2023-03-06 10:04:29 +00:00
|
|
|
for _, testPath := range tests {
|
2023-03-08 14:14:39 +00:00
|
|
|
t.Run(testPath, func(t *testing.T) {
|
|
|
|
testFile, err := os.Open(testPath)
|
2023-03-08 11:45:54 +00:00
|
|
|
require.NoError(t, err)
|
2023-03-08 14:14:39 +00:00
|
|
|
test := Test{}
|
|
|
|
err = yaml.NewDecoder(testFile).Decode(&test)
|
|
|
|
require.NoError(t, testFile.Close())
|
2023-03-08 11:45:54 +00:00
|
|
|
require.NoError(t, err)
|
2023-03-08 14:14:39 +00:00
|
|
|
|
|
|
|
var blob Blob
|
|
|
|
err = blob.UnmarshalText([]byte(test.Input.Blob))
|
|
|
|
if err != nil {
|
|
|
|
require.Nil(t, test.Output)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
var z Bytes32
|
|
|
|
err = z.UnmarshalText([]byte(test.Input.Z))
|
|
|
|
if err != nil {
|
|
|
|
require.Nil(t, test.Output)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2023-03-30 00:33:15 +00:00
|
|
|
proof, y, err := ComputeKZGProof(blob, z)
|
|
|
|
if err == nil {
|
2023-03-08 14:14:39 +00:00
|
|
|
require.NotNil(t, test.Output)
|
|
|
|
var expectedProof Bytes48
|
|
|
|
err = expectedProof.UnmarshalText([]byte((*test.Output)[0]))
|
|
|
|
require.NoError(t, err)
|
|
|
|
require.Equal(t, expectedProof[:], proof[:])
|
|
|
|
var expectedY Bytes32
|
|
|
|
err = expectedY.UnmarshalText([]byte((*test.Output)[1]))
|
|
|
|
require.NoError(t, err)
|
|
|
|
require.Equal(t, expectedY[:], y[:])
|
|
|
|
} else {
|
|
|
|
require.Nil(t, test.Output)
|
|
|
|
}
|
|
|
|
})
|
2023-02-20 16:01:31 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestComputeBlobKZGProof(t *testing.T) {
|
2023-03-06 10:04:29 +00:00
|
|
|
type Test struct {
|
|
|
|
Input struct {
|
2023-03-08 13:30:09 +00:00
|
|
|
Blob string `yaml:"blob"`
|
|
|
|
Commitment string `yaml:"commitment"`
|
2023-03-06 10:04:29 +00:00
|
|
|
}
|
|
|
|
Output *Bytes48 `yaml:"output"`
|
|
|
|
}
|
|
|
|
|
2023-02-20 16:01:31 +00:00
|
|
|
tests, err := filepath.Glob(computeBlobKZGProofTests)
|
2023-01-26 17:04:24 +00:00
|
|
|
require.NoError(t, err)
|
2023-03-15 14:39:19 +00:00
|
|
|
require.True(t, len(tests) > 0)
|
|
|
|
|
2023-03-06 10:04:29 +00:00
|
|
|
for _, testPath := range tests {
|
2023-03-08 14:14:39 +00:00
|
|
|
t.Run(testPath, func(t *testing.T) {
|
|
|
|
testFile, err := os.Open(testPath)
|
|
|
|
require.NoError(t, err)
|
|
|
|
test := Test{}
|
|
|
|
err = yaml.NewDecoder(testFile).Decode(&test)
|
|
|
|
require.NoError(t, testFile.Close())
|
|
|
|
require.NoError(t, err)
|
2023-03-08 13:30:09 +00:00
|
|
|
|
2023-03-08 14:14:39 +00:00
|
|
|
var blob Blob
|
|
|
|
err = blob.UnmarshalText([]byte(test.Input.Blob))
|
|
|
|
if err != nil {
|
|
|
|
require.Nil(t, test.Output)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
var commitment Bytes48
|
|
|
|
err = commitment.UnmarshalText([]byte(test.Input.Commitment))
|
|
|
|
if err != nil {
|
|
|
|
require.Nil(t, test.Output)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2023-03-30 00:33:15 +00:00
|
|
|
proof, err := ComputeBlobKZGProof(blob, commitment)
|
|
|
|
if err == nil {
|
2023-03-08 14:14:39 +00:00
|
|
|
require.NotNil(t, test.Output)
|
|
|
|
require.Equal(t, test.Output[:], proof[:])
|
|
|
|
} else {
|
|
|
|
require.Nil(t, test.Output)
|
|
|
|
}
|
|
|
|
})
|
2023-01-26 17:04:24 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestVerifyKZGProof(t *testing.T) {
|
2023-03-06 10:04:29 +00:00
|
|
|
type Test struct {
|
|
|
|
Input struct {
|
2023-03-08 13:30:09 +00:00
|
|
|
Commitment string `yaml:"commitment"`
|
|
|
|
Z string `yaml:"z"`
|
|
|
|
Y string `yaml:"y"`
|
|
|
|
Proof string `yaml:"proof"`
|
2023-03-06 10:04:29 +00:00
|
|
|
}
|
|
|
|
Output *bool `yaml:"output"`
|
|
|
|
}
|
|
|
|
|
2023-02-20 16:01:31 +00:00
|
|
|
tests, err := filepath.Glob(verifyKZGProofTests)
|
|
|
|
require.NoError(t, err)
|
2023-03-15 14:39:19 +00:00
|
|
|
require.True(t, len(tests) > 0)
|
|
|
|
|
2023-03-06 10:04:29 +00:00
|
|
|
for _, testPath := range tests {
|
2023-03-08 14:14:39 +00:00
|
|
|
t.Run(testPath, func(t *testing.T) {
|
|
|
|
testFile, err := os.Open(testPath)
|
|
|
|
require.NoError(t, err)
|
|
|
|
test := Test{}
|
|
|
|
err = yaml.NewDecoder(testFile).Decode(&test)
|
|
|
|
require.NoError(t, testFile.Close())
|
|
|
|
require.NoError(t, err)
|
2023-03-08 13:30:09 +00:00
|
|
|
|
2023-03-08 14:14:39 +00:00
|
|
|
var commitment Bytes48
|
|
|
|
err = commitment.UnmarshalText([]byte(test.Input.Commitment))
|
|
|
|
if err != nil {
|
|
|
|
require.Nil(t, test.Output)
|
|
|
|
return
|
|
|
|
}
|
2023-03-08 13:30:09 +00:00
|
|
|
|
2023-03-08 14:14:39 +00:00
|
|
|
var z Bytes32
|
|
|
|
err = z.UnmarshalText([]byte(test.Input.Z))
|
|
|
|
if err != nil {
|
|
|
|
require.Nil(t, test.Output)
|
|
|
|
return
|
|
|
|
}
|
2023-03-08 13:30:09 +00:00
|
|
|
|
2023-03-08 14:14:39 +00:00
|
|
|
var y Bytes32
|
|
|
|
err = y.UnmarshalText([]byte(test.Input.Y))
|
|
|
|
if err != nil {
|
|
|
|
require.Nil(t, test.Output)
|
|
|
|
return
|
|
|
|
}
|
2023-03-08 13:30:09 +00:00
|
|
|
|
2023-03-08 14:14:39 +00:00
|
|
|
var proof Bytes48
|
|
|
|
err = proof.UnmarshalText([]byte(test.Input.Proof))
|
|
|
|
if err != nil {
|
|
|
|
require.Nil(t, test.Output)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2023-03-30 00:33:15 +00:00
|
|
|
valid, err := VerifyKZGProof(commitment, z, y, proof)
|
|
|
|
if err == nil {
|
2023-03-08 14:14:39 +00:00
|
|
|
require.NotNil(t, test.Output)
|
|
|
|
require.Equal(t, *test.Output, valid)
|
|
|
|
} else {
|
|
|
|
require.Nil(t, test.Output)
|
|
|
|
}
|
|
|
|
})
|
2023-01-26 17:04:24 +00:00
|
|
|
}
|
2023-02-20 16:01:31 +00:00
|
|
|
}
|
2023-01-26 17:04:24 +00:00
|
|
|
|
2023-02-20 16:01:31 +00:00
|
|
|
func TestVerifyBlobKZGProof(t *testing.T) {
|
2023-03-06 10:04:29 +00:00
|
|
|
type Test struct {
|
|
|
|
Input struct {
|
2023-03-08 13:30:09 +00:00
|
|
|
Blob string `yaml:"blob"`
|
|
|
|
Commitment string `yaml:"commitment"`
|
|
|
|
Proof string `yaml:"proof"`
|
2023-03-06 10:04:29 +00:00
|
|
|
}
|
|
|
|
Output *bool `yaml:"output"`
|
|
|
|
}
|
|
|
|
|
2023-02-20 16:01:31 +00:00
|
|
|
tests, err := filepath.Glob(verifyBlobKZGProofTests)
|
2023-01-26 17:04:24 +00:00
|
|
|
require.NoError(t, err)
|
2023-03-15 14:39:19 +00:00
|
|
|
require.True(t, len(tests) > 0)
|
|
|
|
|
2023-03-06 10:04:29 +00:00
|
|
|
for _, testPath := range tests {
|
2023-03-08 14:14:39 +00:00
|
|
|
t.Run(testPath, func(t *testing.T) {
|
|
|
|
testFile, err := os.Open(testPath)
|
|
|
|
require.NoError(t, err)
|
|
|
|
test := Test{}
|
|
|
|
err = yaml.NewDecoder(testFile).Decode(&test)
|
|
|
|
require.NoError(t, testFile.Close())
|
|
|
|
require.NoError(t, err)
|
2023-03-08 13:30:09 +00:00
|
|
|
|
2023-03-08 14:14:39 +00:00
|
|
|
var blob Blob
|
|
|
|
err = blob.UnmarshalText([]byte(test.Input.Blob))
|
|
|
|
if err != nil {
|
|
|
|
require.Nil(t, test.Output)
|
|
|
|
return
|
|
|
|
}
|
2023-03-08 13:30:09 +00:00
|
|
|
|
2023-03-08 14:14:39 +00:00
|
|
|
var commitment Bytes48
|
|
|
|
err = commitment.UnmarshalText([]byte(test.Input.Commitment))
|
|
|
|
if err != nil {
|
|
|
|
require.Nil(t, test.Output)
|
|
|
|
return
|
|
|
|
}
|
2023-03-08 13:30:09 +00:00
|
|
|
|
2023-03-08 14:14:39 +00:00
|
|
|
var proof Bytes48
|
|
|
|
err = proof.UnmarshalText([]byte(test.Input.Proof))
|
|
|
|
if err != nil {
|
|
|
|
require.Nil(t, test.Output)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2023-03-30 00:33:15 +00:00
|
|
|
valid, err := VerifyBlobKZGProof(blob, commitment, proof)
|
|
|
|
if err == nil {
|
2023-03-08 14:14:39 +00:00
|
|
|
require.NotNil(t, test.Output)
|
|
|
|
require.Equal(t, *test.Output, valid)
|
|
|
|
} else {
|
|
|
|
require.Nil(t, test.Output)
|
|
|
|
}
|
|
|
|
})
|
2023-02-20 16:01:31 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestVerifyBlobKZGProofBatch(t *testing.T) {
|
2023-03-06 10:04:29 +00:00
|
|
|
type Test struct {
|
|
|
|
Input struct {
|
2023-03-08 13:30:09 +00:00
|
|
|
Blobs []string `yaml:"blobs"`
|
|
|
|
Commitments []string `yaml:"commitments"`
|
|
|
|
Proofs []string `yaml:"proofs"`
|
2023-03-06 10:04:29 +00:00
|
|
|
}
|
|
|
|
Output *bool `yaml:"output"`
|
|
|
|
}
|
|
|
|
|
2023-02-20 16:01:31 +00:00
|
|
|
tests, err := filepath.Glob(verifyBlobKZGProofBatchTests)
|
2023-01-26 17:04:24 +00:00
|
|
|
require.NoError(t, err)
|
2023-03-15 14:39:19 +00:00
|
|
|
require.True(t, len(tests) > 0)
|
|
|
|
|
2023-03-06 10:04:29 +00:00
|
|
|
for _, testPath := range tests {
|
2023-03-08 14:14:39 +00:00
|
|
|
t.Run(testPath, func(t *testing.T) {
|
|
|
|
testFile, err := os.Open(testPath)
|
|
|
|
require.NoError(t, err)
|
|
|
|
test := Test{}
|
|
|
|
err = yaml.NewDecoder(testFile).Decode(&test)
|
|
|
|
require.NoError(t, testFile.Close())
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
var blobs []Blob
|
|
|
|
for _, b := range test.Input.Blobs {
|
|
|
|
var blob Blob
|
|
|
|
err = blob.UnmarshalText([]byte(b))
|
|
|
|
if err != nil {
|
|
|
|
require.Nil(t, test.Output)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
blobs = append(blobs, blob)
|
2023-03-08 13:30:09 +00:00
|
|
|
}
|
|
|
|
|
2023-03-08 14:14:39 +00:00
|
|
|
var commitments []Bytes48
|
|
|
|
for _, c := range test.Input.Commitments {
|
|
|
|
var commitment Bytes48
|
|
|
|
err = commitment.UnmarshalText([]byte(c))
|
|
|
|
if err != nil {
|
|
|
|
require.Nil(t, test.Output)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
commitments = append(commitments, commitment)
|
2023-03-08 13:30:09 +00:00
|
|
|
}
|
|
|
|
|
2023-03-08 14:14:39 +00:00
|
|
|
var proofs []Bytes48
|
|
|
|
for _, p := range test.Input.Proofs {
|
|
|
|
var proof Bytes48
|
|
|
|
err = proof.UnmarshalText([]byte(p))
|
|
|
|
if err != nil {
|
|
|
|
require.Nil(t, test.Output)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
proofs = append(proofs, proof)
|
2023-03-08 13:30:09 +00:00
|
|
|
}
|
|
|
|
|
2023-03-30 00:33:15 +00:00
|
|
|
valid, err := VerifyBlobKZGProofBatch(blobs, commitments, proofs)
|
|
|
|
if err == nil {
|
2023-03-08 14:14:39 +00:00
|
|
|
require.NotNil(t, test.Output)
|
|
|
|
require.Equal(t, *test.Output, valid)
|
|
|
|
} else {
|
|
|
|
require.Nil(t, test.Output)
|
|
|
|
}
|
|
|
|
})
|
2023-01-26 17:04:24 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Benchmarks
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
func Benchmark(b *testing.B) {
|
|
|
|
const length = 64
|
|
|
|
blobs := [length]Blob{}
|
|
|
|
commitments := [length]Bytes48{}
|
2023-02-20 16:01:31 +00:00
|
|
|
proofs := [length]Bytes48{}
|
|
|
|
fields := [length]Bytes32{}
|
2023-01-26 17:04:24 +00:00
|
|
|
for i := 0; i < length; i++ {
|
2023-04-10 13:03:36 +00:00
|
|
|
blob := getRandBlob(int64(i))
|
2023-03-30 00:33:15 +00:00
|
|
|
commitment, err := BlobToKZGCommitment(blob)
|
|
|
|
require.NoError(b, err)
|
|
|
|
proof, err := ComputeBlobKZGProof(blob, Bytes48(commitment))
|
|
|
|
require.NoError(b, err)
|
2023-02-20 16:01:31 +00:00
|
|
|
|
|
|
|
blobs[i] = blob
|
2023-01-26 17:04:24 +00:00
|
|
|
commitments[i] = Bytes48(commitment)
|
2023-02-20 16:01:31 +00:00
|
|
|
proofs[i] = Bytes48(proof)
|
2023-04-10 13:03:36 +00:00
|
|
|
fields[i] = getRandFieldElement(int64(i))
|
2023-01-26 17:04:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
b.Run("BlobToKZGCommitment", func(b *testing.B) {
|
|
|
|
for n := 0; n < b.N; n++ {
|
2023-02-20 16:01:31 +00:00
|
|
|
BlobToKZGCommitment(blobs[0])
|
2023-01-26 17:04:24 +00:00
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
b.Run("ComputeKZGProof", func(b *testing.B) {
|
|
|
|
for n := 0; n < b.N; n++ {
|
2023-02-20 16:01:31 +00:00
|
|
|
ComputeKZGProof(blobs[0], fields[0])
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
b.Run("ComputeBlobKZGProof", func(b *testing.B) {
|
|
|
|
for n := 0; n < b.N; n++ {
|
2023-03-08 11:45:54 +00:00
|
|
|
ComputeBlobKZGProof(blobs[0], commitments[0])
|
2023-01-26 17:04:24 +00:00
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
b.Run("VerifyKZGProof", func(b *testing.B) {
|
|
|
|
for n := 0; n < b.N; n++ {
|
2023-02-20 16:01:31 +00:00
|
|
|
VerifyKZGProof(commitments[0], fields[0], fields[1], proofs[0])
|
2023-01-26 17:04:24 +00:00
|
|
|
}
|
|
|
|
})
|
|
|
|
|
2023-02-20 16:01:31 +00:00
|
|
|
b.Run("VerifyBlobKZGProof", func(b *testing.B) {
|
|
|
|
for n := 0; n < b.N; n++ {
|
|
|
|
VerifyBlobKZGProof(blobs[0], commitments[0], proofs[0])
|
|
|
|
}
|
|
|
|
})
|
2023-01-26 17:04:24 +00:00
|
|
|
|
|
|
|
for i := 1; i <= len(blobs); i *= 2 {
|
2023-02-20 16:01:31 +00:00
|
|
|
b.Run(fmt.Sprintf("VerifyBlobKZGProofBatch(count=%v)", i), func(b *testing.B) {
|
2023-01-26 17:04:24 +00:00
|
|
|
for n := 0; n < b.N; n++ {
|
2023-02-20 16:01:31 +00:00
|
|
|
VerifyBlobKZGProofBatch(blobs[:i], commitments[:i], proofs[:i])
|
2023-01-26 17:04:24 +00:00
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|