diff --git a/ecc/bls12-377/fr/kzg/kzg.go b/ecc/bls12-377/fr/kzg/kzg.go index 1e518b3664..01c2724b50 100644 --- a/ecc/bls12-377/fr/kzg/kzg.go +++ b/ecc/bls12-377/fr/kzg/kzg.go @@ -32,6 +32,7 @@ import ( var ( ErrInvalidNbDigests = errors.New("number of digests is not the same as the number of polynomials") + ErrZeroNbDigests = errors.New("number of digests is zero") ErrInvalidPolynomialSize = errors.New("invalid polynomial size (larger than SRS or == 0)") ErrVerifyOpeningProof = errors.New("can't verify opening proof") ErrVerifyBatchOpeningSinglePoint = errors.New("can't verify batch opening proof at single point") @@ -384,6 +385,11 @@ func BatchVerifyMultiPoints(digests []Digest, proofs []OpeningProof, points []fr return ErrInvalidNbDigests } + // len(digests) should be nonzero because of randomNumbers + if len(digests) == 0 { + return ErrZeroNbDigests + } + // if only one digest, call Verify if len(digests) == 1 { return Verify(&digests[0], &proofs[0], points[0], srs) diff --git a/ecc/bls12-378/fr/kzg/kzg.go b/ecc/bls12-378/fr/kzg/kzg.go index d9f58b8798..3f628bff4d 100644 --- a/ecc/bls12-378/fr/kzg/kzg.go +++ b/ecc/bls12-378/fr/kzg/kzg.go @@ -32,6 +32,7 @@ import ( var ( ErrInvalidNbDigests = errors.New("number of digests is not the same as the number of polynomials") + ErrZeroNbDigests = errors.New("number of digests is zero") ErrInvalidPolynomialSize = errors.New("invalid polynomial size (larger than SRS or == 0)") ErrVerifyOpeningProof = errors.New("can't verify opening proof") ErrVerifyBatchOpeningSinglePoint = errors.New("can't verify batch opening proof at single point") @@ -384,6 +385,11 @@ func BatchVerifyMultiPoints(digests []Digest, proofs []OpeningProof, points []fr return ErrInvalidNbDigests } + // len(digests) should be nonzero because of randomNumbers + if len(digests) == 0 { + return ErrZeroNbDigests + } + // if only one digest, call Verify if len(digests) == 1 { return Verify(&digests[0], &proofs[0], points[0], srs) diff --git a/ecc/bls12-381/fr/kzg/kzg.go b/ecc/bls12-381/fr/kzg/kzg.go index f670db852c..b1d68fbedd 100644 --- a/ecc/bls12-381/fr/kzg/kzg.go +++ b/ecc/bls12-381/fr/kzg/kzg.go @@ -32,6 +32,7 @@ import ( var ( ErrInvalidNbDigests = errors.New("number of digests is not the same as the number of polynomials") + ErrZeroNbDigests = errors.New("number of digests is zero") ErrInvalidPolynomialSize = errors.New("invalid polynomial size (larger than SRS or == 0)") ErrVerifyOpeningProof = errors.New("can't verify opening proof") ErrVerifyBatchOpeningSinglePoint = errors.New("can't verify batch opening proof at single point") @@ -384,6 +385,11 @@ func BatchVerifyMultiPoints(digests []Digest, proofs []OpeningProof, points []fr return ErrInvalidNbDigests } + // len(digests) should be nonzero because of randomNumbers + if len(digests) == 0 { + return ErrZeroNbDigests + } + // if only one digest, call Verify if len(digests) == 1 { return Verify(&digests[0], &proofs[0], points[0], srs) diff --git a/ecc/bls24-315/fr/kzg/kzg.go b/ecc/bls24-315/fr/kzg/kzg.go index 72bc17fccc..fd80162827 100644 --- a/ecc/bls24-315/fr/kzg/kzg.go +++ b/ecc/bls24-315/fr/kzg/kzg.go @@ -32,6 +32,7 @@ import ( var ( ErrInvalidNbDigests = errors.New("number of digests is not the same as the number of polynomials") + ErrZeroNbDigests = errors.New("number of digests is zero") ErrInvalidPolynomialSize = errors.New("invalid polynomial size (larger than SRS or == 0)") ErrVerifyOpeningProof = errors.New("can't verify opening proof") ErrVerifyBatchOpeningSinglePoint = errors.New("can't verify batch opening proof at single point") @@ -384,6 +385,11 @@ func BatchVerifyMultiPoints(digests []Digest, proofs []OpeningProof, points []fr return ErrInvalidNbDigests } + // len(digests) should be nonzero because of randomNumbers + if len(digests) == 0 { + return ErrZeroNbDigests + } + // if only one digest, call Verify if len(digests) == 1 { return Verify(&digests[0], &proofs[0], points[0], srs) diff --git a/ecc/bls24-317/fr/kzg/kzg.go b/ecc/bls24-317/fr/kzg/kzg.go index ba1684293a..98f874cb3c 100644 --- a/ecc/bls24-317/fr/kzg/kzg.go +++ b/ecc/bls24-317/fr/kzg/kzg.go @@ -32,6 +32,7 @@ import ( var ( ErrInvalidNbDigests = errors.New("number of digests is not the same as the number of polynomials") + ErrZeroNbDigests = errors.New("number of digests is zero") ErrInvalidPolynomialSize = errors.New("invalid polynomial size (larger than SRS or == 0)") ErrVerifyOpeningProof = errors.New("can't verify opening proof") ErrVerifyBatchOpeningSinglePoint = errors.New("can't verify batch opening proof at single point") @@ -384,6 +385,11 @@ func BatchVerifyMultiPoints(digests []Digest, proofs []OpeningProof, points []fr return ErrInvalidNbDigests } + // len(digests) should be nonzero because of randomNumbers + if len(digests) == 0 { + return ErrZeroNbDigests + } + // if only one digest, call Verify if len(digests) == 1 { return Verify(&digests[0], &proofs[0], points[0], srs) diff --git a/ecc/bn254/fr/kzg/kzg.go b/ecc/bn254/fr/kzg/kzg.go index 45737d814b..96919aa301 100644 --- a/ecc/bn254/fr/kzg/kzg.go +++ b/ecc/bn254/fr/kzg/kzg.go @@ -32,6 +32,7 @@ import ( var ( ErrInvalidNbDigests = errors.New("number of digests is not the same as the number of polynomials") + ErrZeroNbDigests = errors.New("number of digests is zero") ErrInvalidPolynomialSize = errors.New("invalid polynomial size (larger than SRS or == 0)") ErrVerifyOpeningProof = errors.New("can't verify opening proof") ErrVerifyBatchOpeningSinglePoint = errors.New("can't verify batch opening proof at single point") @@ -384,6 +385,11 @@ func BatchVerifyMultiPoints(digests []Digest, proofs []OpeningProof, points []fr return ErrInvalidNbDigests } + // len(digests) should be nonzero because of randomNumbers + if len(digests) == 0 { + return ErrZeroNbDigests + } + // if only one digest, call Verify if len(digests) == 1 { return Verify(&digests[0], &proofs[0], points[0], srs) diff --git a/ecc/bw6-633/fr/kzg/kzg.go b/ecc/bw6-633/fr/kzg/kzg.go index 9d7274336e..ffa5afde77 100644 --- a/ecc/bw6-633/fr/kzg/kzg.go +++ b/ecc/bw6-633/fr/kzg/kzg.go @@ -32,6 +32,7 @@ import ( var ( ErrInvalidNbDigests = errors.New("number of digests is not the same as the number of polynomials") + ErrZeroNbDigests = errors.New("number of digests is zero") ErrInvalidPolynomialSize = errors.New("invalid polynomial size (larger than SRS or == 0)") ErrVerifyOpeningProof = errors.New("can't verify opening proof") ErrVerifyBatchOpeningSinglePoint = errors.New("can't verify batch opening proof at single point") @@ -384,6 +385,11 @@ func BatchVerifyMultiPoints(digests []Digest, proofs []OpeningProof, points []fr return ErrInvalidNbDigests } + // len(digests) should be nonzero because of randomNumbers + if len(digests) == 0 { + return ErrZeroNbDigests + } + // if only one digest, call Verify if len(digests) == 1 { return Verify(&digests[0], &proofs[0], points[0], srs) diff --git a/ecc/bw6-756/fr/kzg/kzg.go b/ecc/bw6-756/fr/kzg/kzg.go index 7063a83299..68aa23e06f 100644 --- a/ecc/bw6-756/fr/kzg/kzg.go +++ b/ecc/bw6-756/fr/kzg/kzg.go @@ -32,6 +32,7 @@ import ( var ( ErrInvalidNbDigests = errors.New("number of digests is not the same as the number of polynomials") + ErrZeroNbDigests = errors.New("number of digests is zero") ErrInvalidPolynomialSize = errors.New("invalid polynomial size (larger than SRS or == 0)") ErrVerifyOpeningProof = errors.New("can't verify opening proof") ErrVerifyBatchOpeningSinglePoint = errors.New("can't verify batch opening proof at single point") @@ -384,6 +385,11 @@ func BatchVerifyMultiPoints(digests []Digest, proofs []OpeningProof, points []fr return ErrInvalidNbDigests } + // len(digests) should be nonzero because of randomNumbers + if len(digests) == 0 { + return ErrZeroNbDigests + } + // if only one digest, call Verify if len(digests) == 1 { return Verify(&digests[0], &proofs[0], points[0], srs) diff --git a/ecc/bw6-761/fr/kzg/kzg.go b/ecc/bw6-761/fr/kzg/kzg.go index 64b3cb3aa2..c17053ce6d 100644 --- a/ecc/bw6-761/fr/kzg/kzg.go +++ b/ecc/bw6-761/fr/kzg/kzg.go @@ -32,6 +32,7 @@ import ( var ( ErrInvalidNbDigests = errors.New("number of digests is not the same as the number of polynomials") + ErrZeroNbDigests = errors.New("number of digests is zero") ErrInvalidPolynomialSize = errors.New("invalid polynomial size (larger than SRS or == 0)") ErrVerifyOpeningProof = errors.New("can't verify opening proof") ErrVerifyBatchOpeningSinglePoint = errors.New("can't verify batch opening proof at single point") @@ -384,6 +385,11 @@ func BatchVerifyMultiPoints(digests []Digest, proofs []OpeningProof, points []fr return ErrInvalidNbDigests } + // len(digests) should be nonzero because of randomNumbers + if len(digests) == 0 { + return ErrZeroNbDigests + } + // if only one digest, call Verify if len(digests) == 1 { return Verify(&digests[0], &proofs[0], points[0], srs) diff --git a/internal/generator/kzg/template/kzg.go.tmpl b/internal/generator/kzg/template/kzg.go.tmpl index c0e2b670dc..26c3afe2a9 100644 --- a/internal/generator/kzg/template/kzg.go.tmpl +++ b/internal/generator/kzg/template/kzg.go.tmpl @@ -14,6 +14,7 @@ import ( var ( ErrInvalidNbDigests = errors.New("number of digests is not the same as the number of polynomials") + ErrZeroNbDigests = errors.New("number of digests is zero") ErrInvalidPolynomialSize = errors.New("invalid polynomial size (larger than SRS or == 0)") ErrVerifyOpeningProof = errors.New("can't verify opening proof") ErrVerifyBatchOpeningSinglePoint = errors.New("can't verify batch opening proof at single point") @@ -265,7 +266,7 @@ func BatchOpenSinglePoint(polynomials [][]fr.Element, digests []Digest, point fr for i := 1 ; i < len(polynomials); i++ { gammas[i].Mul(&gammas[i-1], &gamma) } - + for i := 1; i < len(polynomials); i++ { i := i parallel.Execute(len(polynomials[i]), func(start, end int) { @@ -366,6 +367,11 @@ func BatchVerifyMultiPoints(digests []Digest, proofs []OpeningProof, points []fr return ErrInvalidNbDigests } + // len(digests) should be nonzero because of randomNumbers + if len(digests) == 0 { + return ErrZeroNbDigests + } + // if only one digest, call Verify if len(digests) == 1 { return Verify(&digests[0], &proofs[0], points[0], srs)