Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cleanup kzg tests #313

Merged
merged 1 commit into from
Mar 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions encoding/kzg/prover/decode_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ import (
)

func TestEncodeDecodeFrame_AreInverses(t *testing.T) {
teardownSuite := setupSuite(t)
defer teardownSuite(t)

group, _ := prover.NewProver(kzgConfig, true)

Expand Down
2 changes: 0 additions & 2 deletions encoding/kzg/prover/parametrized_prover_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@ import (
)

func TestProveAllCosetThreads(t *testing.T) {
teardownSuite := setupSuite(t)
defer teardownSuite(t)

group, _ := prover.NewProver(kzgConfig, true)

Expand Down
2 changes: 0 additions & 2 deletions encoding/kzg/prover/precompute_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@ import (
)

func TestNewSRSTable_PreComputeWorks(t *testing.T) {
teardownSuite := setupSuite(t)
defer teardownSuite(t)

kzgConfig.CacheDir = "./data/SRSTable"
params := encoding.ParamsFromSysPar(numSys, numPar, uint64(len(gettysburgAddressBytes)))
Expand Down
24 changes: 14 additions & 10 deletions encoding/kzg/prover/prover_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,6 @@ import (
"github.com/stretchr/testify/assert"
)

const (
BYTES_PER_COEFFICIENT = 31
)

var (
gettysburgAddressBytes = []byte("Fourscore and seven years ago our fathers brought forth, on this continent, a new nation, conceived in liberty, and dedicated to the proposition that all men are created equal. Now we are engaged in a great civil war, testing whether that nation, or any nation so conceived, and so dedicated, can long endure. We are met on a great battle-field of that war. We have come to dedicate a portion of that field, as a final resting-place for those who here gave their lives, that that nation might live. It is altogether fitting and proper that we should do this. But, in a larger sense, we cannot dedicate, we cannot consecrate—we cannot hallow—this ground. The brave men, living and dead, who struggled here, have consecrated it far above our poor power to add or detract. The world will little note, nor long remember what we say here, but it can never forget what they did here. It is for us the living, rather, to be dedicated here to the unfinished work which they who fought here have thus far so nobly advanced. It is rather for us to be here dedicated to the great task remaining before us—that from these honored dead we take increased devotion to that cause for which they here gave the last full measure of devotion—that we here highly resolve that these dead shall not have died in vain—that this nation, under God, shall have a new birth of freedom, and that government of the people, by the people, for the people, shall not perish from the earth.")
kzgConfig *kzg.KzgConfig
Expand All @@ -28,7 +24,14 @@ var (
numPar uint64
)

func setupSuite(t *testing.T) func(t *testing.T) {
func TestMain(m *testing.M) {
setup()
result := m.Run()
teardown()
os.Exit(result)
}

func setup() {
log.Println("Setting up suite")

kzgConfig = &kzg.KzgConfig{
Expand All @@ -45,12 +48,13 @@ func setupSuite(t *testing.T) func(t *testing.T) {
numSys = uint64(3)
numPar = numNode - numSys

return func(t *testing.T) {
log.Println("Tearing down suite")
}

// Some test may want to create a new SRS table so this should clean it up.
os.RemoveAll("./data")
}
func teardown() {
log.Println("Tearing down suite")

// Some test may want to create a new SRS table so this should clean it up.
os.RemoveAll("./data")
}

func sampleFrames(frames []encoding.Frame, num uint64) ([]encoding.Frame, []uint64) {
Expand Down
6 changes: 2 additions & 4 deletions encoding/kzg/verifier/batch_commit_equivalence_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,14 @@ import (
)

func TestBatchEquivalence(t *testing.T) {
teardownSuite := setupSuite(t)
defer teardownSuite(t)

group, _ := prover.NewProver(kzgConfig, true)
v, _ := verifier.NewVerifier(kzgConfig, true)
params := encoding.ParamsFromSysPar(numSys, numPar, uint64(len(GETTYSBURG_ADDRESS_BYTES)))
params := encoding.ParamsFromSysPar(numSys, numPar, uint64(len(gettysburgAddressBytes)))
enc, err := group.GetKzgEncoder(params)
require.Nil(t, err)

inputFr := rs.ToFrArray(GETTYSBURG_ADDRESS_BYTES)
inputFr := rs.ToFrArray(gettysburgAddressBytes)
commit, g2commit, _, _, _, err := enc.Encode(inputFr)
require.Nil(t, err)

Expand Down
6 changes: 2 additions & 4 deletions encoding/kzg/verifier/degree_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,17 @@ import (
)

func TestLengthProof(t *testing.T) {
teardownSuite := setupSuite(t)
defer teardownSuite(t)

group, _ := prover.NewProver(kzgConfig, true)
v, _ := verifier.NewVerifier(kzgConfig, true)
params := encoding.ParamsFromSysPar(numSys, numPar, uint64(len(GETTYSBURG_ADDRESS_BYTES)))
params := encoding.ParamsFromSysPar(numSys, numPar, uint64(len(gettysburgAddressBytes)))
enc, err := group.GetKzgEncoder(params)
require.Nil(t, err)

numBlob := 5
for z := 0; z < numBlob; z++ {
extra := make([]byte, z*31*2)
inputBytes := append(GETTYSBURG_ADDRESS_BYTES, extra...)
inputBytes := append(gettysburgAddressBytes, extra...)
inputFr := rs.ToFrArray(inputBytes)

_, lowDegreeCommitment, lowDegreeProof, _, _, err := enc.Encode(inputFr)
Expand Down
6 changes: 2 additions & 4 deletions encoding/kzg/verifier/frame_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,16 @@ import (
)

func TestVerify(t *testing.T) {
teardownSuite := setupSuite(t)
defer teardownSuite(t)

group, _ := prover.NewProver(kzgConfig, true)

params := encoding.ParamsFromSysPar(numSys, numPar, uint64(len(GETTYSBURG_ADDRESS_BYTES)))
params := encoding.ParamsFromSysPar(numSys, numPar, uint64(len(gettysburgAddressBytes)))

enc, err := group.GetKzgEncoder(params)
require.Nil(t, err)
require.NotNil(t, enc)

commit, _, _, frames, _, err := enc.EncodeBytes(GETTYSBURG_ADDRESS_BYTES)
commit, _, _, frames, _, err := enc.EncodeBytes(gettysburgAddressBytes)
require.Nil(t, err)
require.NotNil(t, commit)
require.NotNil(t, frames)
Expand Down
12 changes: 4 additions & 8 deletions encoding/kzg/verifier/multiframe_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,18 @@ import (
)

func TestUniversalVerify(t *testing.T) {
teardownSuite := setupSuite(t)
defer teardownSuite(t)

group, _ := prover.NewProver(kzgConfig, true)
v, _ := verifier.NewVerifier(kzgConfig, true)

params := encoding.ParamsFromSysPar(numSys, numPar, uint64(len(GETTYSBURG_ADDRESS_BYTES)))
params := encoding.ParamsFromSysPar(numSys, numPar, uint64(len(gettysburgAddressBytes)))
enc, err := group.GetKzgEncoder(params)
require.Nil(t, err)

numBlob := 5
samples := make([]verifier.Sample, 0)
for z := 0; z < numBlob; z++ {
inputFr := rs.ToFrArray(GETTYSBURG_ADDRESS_BYTES)
inputFr := rs.ToFrArray(gettysburgAddressBytes)

commit, _, _, frames, fIndices, err := enc.Encode(inputFr)
require.Nil(t, err)
Expand Down Expand Up @@ -55,8 +53,6 @@ func TestUniversalVerify(t *testing.T) {
}

func TestUniversalVerifyWithPowerOf2G2(t *testing.T) {
teardownSuite := setupSuite(t)
defer teardownSuite(t)

kzgConfigCopy := *kzgConfig
group, err := prover.NewProver(&kzgConfigCopy, true)
Expand All @@ -66,14 +62,14 @@ func TestUniversalVerifyWithPowerOf2G2(t *testing.T) {
v, err := verifier.NewVerifier(kzgConfig, true)
assert.NoError(t, err)

params := encoding.ParamsFromSysPar(numSys, numPar, uint64(len(GETTYSBURG_ADDRESS_BYTES)))
params := encoding.ParamsFromSysPar(numSys, numPar, uint64(len(gettysburgAddressBytes)))
enc, err := group.GetKzgEncoder(params)
assert.NoError(t, err)

numBlob := 5
samples := make([]verifier.Sample, 0)
for z := 0; z < numBlob; z++ {
inputFr := rs.ToFrArray(GETTYSBURG_ADDRESS_BYTES)
inputFr := rs.ToFrArray(gettysburgAddressBytes)

commit, _, _, frames, fIndices, err := enc.Encode(inputFr)
require.Nil(t, err)
Expand Down
32 changes: 17 additions & 15 deletions encoding/kzg/verifier/verifier_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,22 @@ import (
"github.com/stretchr/testify/assert"
)

const (
BYTES_PER_COEFFICIENT = 31
)

var (
GETTYSBURG_ADDRESS_BYTES = []byte("Fourscore and seven years ago our fathers brought forth, on this continent, a new nation, conceived in liberty, and dedicated to the proposition that all men are created equal. Now we are engaged in a great civil war, testing whether that nation, or any nation so conceived, and so dedicated, can long endure. We are met on a great battle-field of that war. We have come to dedicate a portion of that field, as a final resting-place for those who here gave their lives, that that nation might live. It is altogether fitting and proper that we should do this. But, in a larger sense, we cannot dedicate, we cannot consecrate—we cannot hallow—this ground. The brave men, living and dead, who struggled here, have consecrated it far above our poor power to add or detract. The world will little note, nor long remember what we say here, but it can never forget what they did here. It is for us the living, rather, to be dedicated here to the unfinished work which they who fought here have thus far so nobly advanced. It is rather for us to be here dedicated to the great task remaining before us—that from these honored dead we take increased devotion to that cause for which they here gave the last full measure of devotion—that we here highly resolve that these dead shall not have died in vain—that this nation, under God, shall have a new birth of freedom, and that government of the people, by the people, for the people, shall not perish from the earth.")
kzgConfig *kzg.KzgConfig
numNode uint64
numSys uint64
numPar uint64
gettysburgAddressBytes = []byte("Fourscore and seven years ago our fathers brought forth, on this continent, a new nation, conceived in liberty, and dedicated to the proposition that all men are created equal. Now we are engaged in a great civil war, testing whether that nation, or any nation so conceived, and so dedicated, can long endure. We are met on a great battle-field of that war. We have come to dedicate a portion of that field, as a final resting-place for those who here gave their lives, that that nation might live. It is altogether fitting and proper that we should do this. But, in a larger sense, we cannot dedicate, we cannot consecrate—we cannot hallow—this ground. The brave men, living and dead, who struggled here, have consecrated it far above our poor power to add or detract. The world will little note, nor long remember what we say here, but it can never forget what they did here. It is for us the living, rather, to be dedicated here to the unfinished work which they who fought here have thus far so nobly advanced. It is rather for us to be here dedicated to the great task remaining before us—that from these honored dead we take increased devotion to that cause for which they here gave the last full measure of devotion—that we here highly resolve that these dead shall not have died in vain—that this nation, under God, shall have a new birth of freedom, and that government of the people, by the people, for the people, shall not perish from the earth.")
kzgConfig *kzg.KzgConfig
numNode uint64
numSys uint64
numPar uint64
)

func setupSuite(t *testing.T) func(t *testing.T) {
func TestMain(m *testing.M) {
setup()
result := m.Run()
teardown()
os.Exit(result)
}

func setup() {
log.Println("Setting up suite")

kzgConfig = &kzg.KzgConfig{
Expand All @@ -44,12 +47,11 @@ func setupSuite(t *testing.T) func(t *testing.T) {
numSys = uint64(3)
numPar = numNode - numSys

return func(t *testing.T) {
log.Println("Tearing down suite")
}

// Some test may want to create a new SRS table so this should clean it up.
os.RemoveAll("./data")
}
func teardown() {
log.Println("Tearing down")
os.RemoveAll("./data")
}

// var control interface{ Stop() }
Expand Down
Loading