From 2315f4fae9dcda25d0699aa95d61c5861541abca Mon Sep 17 00:00:00 2001 From: Ubuntu Date: Sat, 24 Feb 2024 05:50:19 +0000 Subject: [PATCH] convert bool return to error return --- .../kzg/prover/parametrized_prover_test.go | 2 +- encoding/kzg/verifier/frame_test.go | 2 +- encoding/kzg/verifier/verifier.go | 20 ++++++++++++------- encoding/test/main.go | 4 ++-- 4 files changed, 17 insertions(+), 11 deletions(-) diff --git a/encoding/kzg/prover/parametrized_prover_test.go b/encoding/kzg/prover/parametrized_prover_test.go index 3d298afc5b..b56f8ad8aa 100644 --- a/encoding/kzg/prover/parametrized_prover_test.go +++ b/encoding/kzg/prover/parametrized_prover_test.go @@ -42,6 +42,6 @@ func TestProveAllCosetThreads(t *testing.T) { g2Atn, err := kzg.ReadG2Point(uint64(len(f.Coeffs)), kzgConfig) require.Nil(t, err) - assert.True(t, verifier.VerifyFrame(&f, enc.Ks, commit, &lc, &g2Atn), "Proof %v failed\n", i) + assert.Nil(t, verifier.VerifyFrame(&f, enc.Ks, commit, &lc, &g2Atn), "Proof %v failed\n", i) } } diff --git a/encoding/kzg/verifier/frame_test.go b/encoding/kzg/verifier/frame_test.go index 109cb9337b..d3353733de 100644 --- a/encoding/kzg/verifier/frame_test.go +++ b/encoding/kzg/verifier/frame_test.go @@ -41,5 +41,5 @@ func TestVerify(t *testing.T) { g2Atn, err := kzg.ReadG2Point(uint64(len(frames[0].Coeffs)), kzgConfig) require.Nil(t, err) - assert.True(t, verifier.VerifyFrame(&frames[0], enc.Ks, commit, &lc, &g2Atn)) + assert.Nil(t, verifier.VerifyFrame(&frames[0], enc.Ks, commit, &lc, &g2Atn)) } diff --git a/encoding/kzg/verifier/verifier.go b/encoding/kzg/verifier/verifier.go index f2065cb165..d1b312cab6 100644 --- a/encoding/kzg/verifier/verifier.go +++ b/encoding/kzg/verifier/verifier.go @@ -176,11 +176,12 @@ func (v *Verifier) VerifyCommit(lengthCommit *bn254.G2Affine, lowDegreeProof *bn return err } - if !VerifyLowDegreeProof(lengthCommit, lowDegreeProof, &g1Challenge) { - return errors.New("low degree proof fails") + err = VerifyLowDegreeProof(lengthCommit, lowDegreeProof, &g1Challenge) + if err != nil { + return fmt.Errorf("%v . %v ", "low degree proof fails", err) + } else { + return nil } - return nil - } // The function verify low degree proof against a poly commitment @@ -189,8 +190,8 @@ func (v *Verifier) VerifyCommit(lengthCommit *bn254.G2Affine, lowDegreeProof *bn // proof = commit(shiftedPoly) on G1 // so we can verify by checking // e( commit_1, [x^shift]_2) = e( proof_1, G_2 ) -func VerifyLowDegreeProof(lengthCommit *bn254.G2Affine, proof *bn254.G2Affine, g1Challenge *bn254.G1Affine) bool { - return PairingsVerify(g1Challenge, lengthCommit, &kzg.GenG1, proof) == nil +func VerifyLowDegreeProof(lengthCommit *bn254.G2Affine, proof *bn254.G2Affine, g1Challenge *bn254.G1Affine) error { + return PairingsVerify(g1Challenge, lengthCommit, &kzg.GenG1, proof) } func (v *Verifier) VerifyFrames(frames []*encoding.Frame, indices []encoding.ChunkNumber, commitments encoding.BlobCommitments, params encoding.EncodingParams) error { @@ -231,8 +232,13 @@ func (v *ParametrizedVerifier) VerifyFrame(commit *bn254.G1Affine, f *encoding.F return err } - return VerifyFrame(f, v.Ks, commit, &v.Ks.ExpandedRootsOfUnity[j], &g2Atn) + err = VerifyFrame(f, v.Ks, commit, &v.Ks.ExpandedRootsOfUnity[j], &g2Atn) + if err != nil { + return fmt.Errorf("%v . %v ", "VerifyFrame Error", err) + } else { + return nil + } } // Verify function assumes the Data stored is coefficients of coset's interpolating poly diff --git a/encoding/test/main.go b/encoding/test/main.go index df9e35fba5..cea8266a8a 100644 --- a/encoding/test/main.go +++ b/encoding/test/main.go @@ -117,8 +117,8 @@ func TestKzgRs() { if err != nil { log.Fatalf("Load g2 %v failed\n", err) } - ok := verifier.VerifyFrame(&f, enc.Ks, commit, &lc, &g2Atn) - if !ok { + err = verifier.VerifyFrame(&f, enc.Ks, commit, &lc, &g2Atn) + if err != nil { log.Fatalf("Proof %v failed\n", i) } }