From 8923b843b3d69e60c6157e0712546fe527120676 Mon Sep 17 00:00:00 2001 From: Jian Xiao Date: Mon, 5 Feb 2024 18:22:19 +0000 Subject: [PATCH] cleanup --- pkg/encoding/utils/pointsIO.go | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/pkg/encoding/utils/pointsIO.go b/pkg/encoding/utils/pointsIO.go index f7353dd3c4..412c563770 100644 --- a/pkg/encoding/utils/pointsIO.go +++ b/pkg/encoding/utils/pointsIO.go @@ -2,6 +2,7 @@ package utils import ( "bufio" + "fmt" "io" "log" "os" @@ -100,6 +101,9 @@ func ReadG1Points(filepath string, n uint64, numWorker uint64) ([]bls.G1Point, e // from is inclusive, to is exclusive func ReadG1PointSection(filepath string, from, to uint64, numWorker uint64) ([]bls.G1Point, error) { + if to <= from { + return nil, fmt.Errorf("The range to read is invalid, from: %v, to: %v", from, to) + } g1f, err := os.Open(filepath) if err != nil { log.Println("ReadG1PointSection.ERR.0", err) @@ -265,7 +269,11 @@ func ReadG2Points(filepath string, n uint64, numWorker uint64) ([]bls.G2Point, e return s2Outs, nil } +// from is inclusive, to is exclusive func ReadG2PointSection(filepath string, from, to uint64, numWorker uint64) ([]bls.G2Point, error) { + if to <= from { + return nil, fmt.Errorf("The range to read is invalid, from: %v, to: %v", from, to) + } g2f, err := os.Open(filepath) if err != nil { log.Println("ReadG2PointSection.ERR.0", err) @@ -298,13 +306,6 @@ func ReadG2PointSection(filepath string, from, to uint64, numWorker uint64) ([]b return nil, err } - if uint64(len(buf)) < G2PointBytes*n { - log.Printf("Error. Insufficient G2 points. Only contains %v. Requesting %v\n", len(buf)/G2PointBytes, n) - log.Println() - log.Println("ReadG2PointSection.ERR.1", err) - return nil, err - } - // measure reading time t := time.Now() elapsed := t.Sub(startTimer)