Skip to content

Commit

Permalink
mandate to read power of 2 file at the beginning (Layr-Labs#472)
Browse files Browse the repository at this point in the history
Co-authored-by: Bowen Xue <[email protected]>
  • Loading branch information
bxue-l2 and Bowen Xue authored Apr 11, 2024
1 parent cd0155f commit 3170b6c
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 6 deletions.
10 changes: 5 additions & 5 deletions encoding/kzg/pointsIO.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand All @@ -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
Expand All @@ -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
}
Expand Down Expand Up @@ -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
}
Expand All @@ -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() {
Expand Down
11 changes: 10 additions & 1 deletion encoding/kzg/verifier/verifier.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 3170b6c

Please sign in to comment.