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

mandate to read power of 2 file at the beginning #472

Merged
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
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
Loading