Skip to content

Commit

Permalink
convert bool return to error return
Browse files Browse the repository at this point in the history
  • Loading branch information
Ubuntu committed Feb 24, 2024
1 parent acc3855 commit 2315f4f
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 11 deletions.
2 changes: 1 addition & 1 deletion encoding/kzg/prover/parametrized_prover_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
2 changes: 1 addition & 1 deletion encoding/kzg/verifier/frame_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}
20 changes: 13 additions & 7 deletions encoding/kzg/verifier/verifier.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 {
Expand Down Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions encoding/test/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
Expand Down

0 comments on commit 2315f4f

Please sign in to comment.