diff --git a/encoding/kzg/pointsIO.go b/encoding/kzg/pointsIO.go index 174f3e0c35..a7f8a1b608 100644 --- a/encoding/kzg/pointsIO.go +++ b/encoding/kzg/pointsIO.go @@ -33,7 +33,7 @@ func ReadDesiredBytes(reader *bufio.Reader, numBytesToRead uint64) ([]byte, erro // Note that ReadFull() guarantees the bytes read is len(buf) IFF err is nil. // See https://pkg.go.dev/io#ReadFull. if err != nil { - return nil, err + return nil, fmt.Errorf("cannot read file %w", err) } return buf, nil } @@ -46,7 +46,7 @@ func ReadG1Point(n uint64, g *KzgConfig) (bn254.G1Affine, error) { g1point, err := ReadG1PointSection(g.G1Path, n, n+1, 1) if err != nil { - return bn254.G1Affine{}, err + return bn254.G1Affine{}, fmt.Errorf("error read g1 point section %w", err) } return g1point[0], nil @@ -60,7 +60,7 @@ func ReadG2Point(n uint64, g *KzgConfig) (bn254.G2Affine, error) { g2point, err := ReadG2PointSection(g.G2Path, n, n+1, 1) if err != nil { - return bn254.G2Affine{}, err + return bn254.G2Affine{}, fmt.Errorf("error read g2 point section %w", err) } return g2point[0], nil } @@ -92,7 +92,7 @@ func ReadG2PointOnPowerOf2(exponent uint64, g *KzgConfig) (bn254.G2Affine, error g2point, err := ReadG2PointSection(g.G2PowerOf2Path, exponent, exponent+1, 1) if err != nil { - return bn254.G2Affine{}, err + return bn254.G2Affine{}, fmt.Errorf("error read g2 point on power of 2 %w", err) } return g2point[0], nil } @@ -101,7 +101,7 @@ func ReadG1Points(filepath string, n uint64, numWorker uint64) ([]bn254.G1Affine g1f, err := os.Open(filepath) if err != nil { log.Println("Cannot ReadG1Points", filepath, err) - return nil, err + return nil, fmt.Errorf("error cannot open g1 points file %w", err) } defer func() { diff --git a/encoding/kzg/verifier/verifier.go b/encoding/kzg/verifier/verifier.go index 8f91812809..db8a71cd30 100644 --- a/encoding/kzg/verifier/verifier.go +++ b/encoding/kzg/verifier/verifier.go @@ -70,10 +70,19 @@ func NewVerifier(config *kzg.KzgConfig, loadG2Points bool) (*Verifier, error) { return nil, err } } else { - // todo, there are better ways to handle it if len(config.G2PowerOf2Path) == 0 { return nil, errors.New("G2PowerOf2Path is empty. However, object needs to load G2Points") } + + if config.SRSOrder == 0 { + return nil, errors.New("SRS order cannot be 0") + } + + maxPower := uint64(math.Log2(float64(config.SRSOrder))) + _, err := kzg.ReadG2PointSection(config.G2PowerOf2Path, 0, maxPower, 1) + if err != nil { + return nil, fmt.Errorf("file located at %v is invalid", config.G2PowerOf2Path) + } } srs, err := kzg.NewSrs(s1, s2)