From 23812e3e531bc02b4d3b09b0e274f2ed8bd784ec Mon Sep 17 00:00:00 2001 From: Youssef El Housni Date: Thu, 6 Apr 2023 15:17:22 +0200 Subject: [PATCH] fix(kzg): nb of digests in BatchVerifyMultiPoints should be nonzeo --- ecc/bls12-377/fr/kzg/kzg.go | 6 ++++++ ecc/bls12-378/fr/kzg/kzg.go | 6 ++++++ ecc/bls12-381/fr/kzg/kzg.go | 6 ++++++ ecc/bls24-315/fr/kzg/kzg.go | 6 ++++++ ecc/bls24-317/fr/kzg/kzg.go | 6 ++++++ ecc/bn254/fr/kzg/kzg.go | 6 ++++++ ecc/bw6-633/fr/kzg/kzg.go | 6 ++++++ ecc/bw6-756/fr/kzg/kzg.go | 6 ++++++ ecc/bw6-761/fr/kzg/kzg.go | 6 ++++++ internal/generator/kzg/template/kzg.go.tmpl | 8 +++++++- 10 files changed, 61 insertions(+), 1 deletion(-) diff --git a/ecc/bls12-377/fr/kzg/kzg.go b/ecc/bls12-377/fr/kzg/kzg.go index a1b3a7690a..34412f2ba6 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") @@ -380,6 +381,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 d0cde383bb..abb384db4e 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") @@ -380,6 +381,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 3f5c98b034..4983b618fe 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") @@ -380,6 +381,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 9dfbc64313..837c0096d8 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") @@ -380,6 +381,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 39d229288a..8d9c13b409 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") @@ -380,6 +381,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 3a90e10fd4..5acf80e7c3 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") @@ -380,6 +381,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 dfb5565a13..c173e949ac 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") @@ -380,6 +381,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 9a03e34dfd..d34d88696e 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") @@ -380,6 +381,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 f6636b9948..a5e99e61d6 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") @@ -380,6 +381,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 0f42fb5a27..0dd25a7ff1 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") @@ -264,7 +265,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) { @@ -362,6 +363,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)