From b4815d64b148817932e0c23d18ae2f778a7a5eda Mon Sep 17 00:00:00 2001 From: Thomas Piellard Date: Wed, 18 Sep 2024 19:02:36 +0200 Subject: [PATCH] fix: raise error when nbDigest != number of polynomials --- ecc/bls12-377/shplonk/shplonk.go | 8 ++++++-- ecc/bls12-378/shplonk/shplonk.go | 8 ++++++-- ecc/bls12-381/shplonk/shplonk.go | 8 ++++++-- ecc/bls24-315/shplonk/shplonk.go | 8 ++++++-- ecc/bls24-317/shplonk/shplonk.go | 8 ++++++-- ecc/bn254/shplonk/shplonk.go | 8 ++++++-- ecc/bw6-633/shplonk/shplonk.go | 8 ++++++-- ecc/bw6-756/shplonk/shplonk.go | 8 ++++++-- ecc/bw6-761/shplonk/shplonk.go | 8 ++++++-- internal/generator/shplonk/template/shplonk.go.tmpl | 4 ++++ 10 files changed, 58 insertions(+), 18 deletions(-) diff --git a/ecc/bls12-377/shplonk/shplonk.go b/ecc/bls12-377/shplonk/shplonk.go index 13faee07d..fb17486b4 100644 --- a/ecc/bls12-377/shplonk/shplonk.go +++ b/ecc/bls12-377/shplonk/shplonk.go @@ -29,8 +29,9 @@ import ( ) var ( - ErrInvalidNumberOfPoints = errors.New("number of digests should be equal to the number of points") - ErrVerifyOpeningProof = errors.New("can't verify batch opening proof") + ErrInvalidNumberOfPoints = errors.New("number of digests should be equal to the number of points") + ErrVerifyOpeningProof = errors.New("can't verify batch opening proof") + ErrInvalidNumberOfDigests = errors.New("number of digests should be equal to the number of polynomials") ) // OpeningProof KZG proof for opening (fᵢ)_{i} at a different points (xᵢ)_{i}. @@ -58,6 +59,9 @@ func BatchOpen(polynomials [][]fr.Element, digests []kzg.Digest, points [][]fr.E if len(polynomials) != len(points) { return res, ErrInvalidNumberOfPoints } + if len(polynomials) != len(digests) { + return res, ErrInvalidNumberOfDigests + } // transcript fs := fiatshamir.NewTranscript(hf, "gamma", "z") diff --git a/ecc/bls12-378/shplonk/shplonk.go b/ecc/bls12-378/shplonk/shplonk.go index 1f447522a..6f464422c 100644 --- a/ecc/bls12-378/shplonk/shplonk.go +++ b/ecc/bls12-378/shplonk/shplonk.go @@ -29,8 +29,9 @@ import ( ) var ( - ErrInvalidNumberOfPoints = errors.New("number of digests should be equal to the number of points") - ErrVerifyOpeningProof = errors.New("can't verify batch opening proof") + ErrInvalidNumberOfPoints = errors.New("number of digests should be equal to the number of points") + ErrVerifyOpeningProof = errors.New("can't verify batch opening proof") + ErrInvalidNumberOfDigests = errors.New("number of digests should be equal to the number of polynomials") ) // OpeningProof KZG proof for opening (fᵢ)_{i} at a different points (xᵢ)_{i}. @@ -58,6 +59,9 @@ func BatchOpen(polynomials [][]fr.Element, digests []kzg.Digest, points [][]fr.E if len(polynomials) != len(points) { return res, ErrInvalidNumberOfPoints } + if len(polynomials) != len(digests) { + return res, ErrInvalidNumberOfDigests + } // transcript fs := fiatshamir.NewTranscript(hf, "gamma", "z") diff --git a/ecc/bls12-381/shplonk/shplonk.go b/ecc/bls12-381/shplonk/shplonk.go index 43d624ae2..09fc264dd 100644 --- a/ecc/bls12-381/shplonk/shplonk.go +++ b/ecc/bls12-381/shplonk/shplonk.go @@ -29,8 +29,9 @@ import ( ) var ( - ErrInvalidNumberOfPoints = errors.New("number of digests should be equal to the number of points") - ErrVerifyOpeningProof = errors.New("can't verify batch opening proof") + ErrInvalidNumberOfPoints = errors.New("number of digests should be equal to the number of points") + ErrVerifyOpeningProof = errors.New("can't verify batch opening proof") + ErrInvalidNumberOfDigests = errors.New("number of digests should be equal to the number of polynomials") ) // OpeningProof KZG proof for opening (fᵢ)_{i} at a different points (xᵢ)_{i}. @@ -58,6 +59,9 @@ func BatchOpen(polynomials [][]fr.Element, digests []kzg.Digest, points [][]fr.E if len(polynomials) != len(points) { return res, ErrInvalidNumberOfPoints } + if len(polynomials) != len(digests) { + return res, ErrInvalidNumberOfDigests + } // transcript fs := fiatshamir.NewTranscript(hf, "gamma", "z") diff --git a/ecc/bls24-315/shplonk/shplonk.go b/ecc/bls24-315/shplonk/shplonk.go index f3be3f5bf..e0733e5d1 100644 --- a/ecc/bls24-315/shplonk/shplonk.go +++ b/ecc/bls24-315/shplonk/shplonk.go @@ -29,8 +29,9 @@ import ( ) var ( - ErrInvalidNumberOfPoints = errors.New("number of digests should be equal to the number of points") - ErrVerifyOpeningProof = errors.New("can't verify batch opening proof") + ErrInvalidNumberOfPoints = errors.New("number of digests should be equal to the number of points") + ErrVerifyOpeningProof = errors.New("can't verify batch opening proof") + ErrInvalidNumberOfDigests = errors.New("number of digests should be equal to the number of polynomials") ) // OpeningProof KZG proof for opening (fᵢ)_{i} at a different points (xᵢ)_{i}. @@ -58,6 +59,9 @@ func BatchOpen(polynomials [][]fr.Element, digests []kzg.Digest, points [][]fr.E if len(polynomials) != len(points) { return res, ErrInvalidNumberOfPoints } + if len(polynomials) != len(digests) { + return res, ErrInvalidNumberOfDigests + } // transcript fs := fiatshamir.NewTranscript(hf, "gamma", "z") diff --git a/ecc/bls24-317/shplonk/shplonk.go b/ecc/bls24-317/shplonk/shplonk.go index dc8cdfa14..722ca208c 100644 --- a/ecc/bls24-317/shplonk/shplonk.go +++ b/ecc/bls24-317/shplonk/shplonk.go @@ -29,8 +29,9 @@ import ( ) var ( - ErrInvalidNumberOfPoints = errors.New("number of digests should be equal to the number of points") - ErrVerifyOpeningProof = errors.New("can't verify batch opening proof") + ErrInvalidNumberOfPoints = errors.New("number of digests should be equal to the number of points") + ErrVerifyOpeningProof = errors.New("can't verify batch opening proof") + ErrInvalidNumberOfDigests = errors.New("number of digests should be equal to the number of polynomials") ) // OpeningProof KZG proof for opening (fᵢ)_{i} at a different points (xᵢ)_{i}. @@ -58,6 +59,9 @@ func BatchOpen(polynomials [][]fr.Element, digests []kzg.Digest, points [][]fr.E if len(polynomials) != len(points) { return res, ErrInvalidNumberOfPoints } + if len(polynomials) != len(digests) { + return res, ErrInvalidNumberOfDigests + } // transcript fs := fiatshamir.NewTranscript(hf, "gamma", "z") diff --git a/ecc/bn254/shplonk/shplonk.go b/ecc/bn254/shplonk/shplonk.go index 3ed334464..c33fa05c4 100644 --- a/ecc/bn254/shplonk/shplonk.go +++ b/ecc/bn254/shplonk/shplonk.go @@ -29,8 +29,9 @@ import ( ) var ( - ErrInvalidNumberOfPoints = errors.New("number of digests should be equal to the number of points") - ErrVerifyOpeningProof = errors.New("can't verify batch opening proof") + ErrInvalidNumberOfPoints = errors.New("number of digests should be equal to the number of points") + ErrVerifyOpeningProof = errors.New("can't verify batch opening proof") + ErrInvalidNumberOfDigests = errors.New("number of digests should be equal to the number of polynomials") ) // OpeningProof KZG proof for opening (fᵢ)_{i} at a different points (xᵢ)_{i}. @@ -58,6 +59,9 @@ func BatchOpen(polynomials [][]fr.Element, digests []kzg.Digest, points [][]fr.E if len(polynomials) != len(points) { return res, ErrInvalidNumberOfPoints } + if len(polynomials) != len(digests) { + return res, ErrInvalidNumberOfDigests + } // transcript fs := fiatshamir.NewTranscript(hf, "gamma", "z") diff --git a/ecc/bw6-633/shplonk/shplonk.go b/ecc/bw6-633/shplonk/shplonk.go index a3d6bd199..a07892371 100644 --- a/ecc/bw6-633/shplonk/shplonk.go +++ b/ecc/bw6-633/shplonk/shplonk.go @@ -29,8 +29,9 @@ import ( ) var ( - ErrInvalidNumberOfPoints = errors.New("number of digests should be equal to the number of points") - ErrVerifyOpeningProof = errors.New("can't verify batch opening proof") + ErrInvalidNumberOfPoints = errors.New("number of digests should be equal to the number of points") + ErrVerifyOpeningProof = errors.New("can't verify batch opening proof") + ErrInvalidNumberOfDigests = errors.New("number of digests should be equal to the number of polynomials") ) // OpeningProof KZG proof for opening (fᵢ)_{i} at a different points (xᵢ)_{i}. @@ -58,6 +59,9 @@ func BatchOpen(polynomials [][]fr.Element, digests []kzg.Digest, points [][]fr.E if len(polynomials) != len(points) { return res, ErrInvalidNumberOfPoints } + if len(polynomials) != len(digests) { + return res, ErrInvalidNumberOfDigests + } // transcript fs := fiatshamir.NewTranscript(hf, "gamma", "z") diff --git a/ecc/bw6-756/shplonk/shplonk.go b/ecc/bw6-756/shplonk/shplonk.go index d8353e303..252c034fc 100644 --- a/ecc/bw6-756/shplonk/shplonk.go +++ b/ecc/bw6-756/shplonk/shplonk.go @@ -29,8 +29,9 @@ import ( ) var ( - ErrInvalidNumberOfPoints = errors.New("number of digests should be equal to the number of points") - ErrVerifyOpeningProof = errors.New("can't verify batch opening proof") + ErrInvalidNumberOfPoints = errors.New("number of digests should be equal to the number of points") + ErrVerifyOpeningProof = errors.New("can't verify batch opening proof") + ErrInvalidNumberOfDigests = errors.New("number of digests should be equal to the number of polynomials") ) // OpeningProof KZG proof for opening (fᵢ)_{i} at a different points (xᵢ)_{i}. @@ -58,6 +59,9 @@ func BatchOpen(polynomials [][]fr.Element, digests []kzg.Digest, points [][]fr.E if len(polynomials) != len(points) { return res, ErrInvalidNumberOfPoints } + if len(polynomials) != len(digests) { + return res, ErrInvalidNumberOfDigests + } // transcript fs := fiatshamir.NewTranscript(hf, "gamma", "z") diff --git a/ecc/bw6-761/shplonk/shplonk.go b/ecc/bw6-761/shplonk/shplonk.go index a4d81d6de..9e6e90b00 100644 --- a/ecc/bw6-761/shplonk/shplonk.go +++ b/ecc/bw6-761/shplonk/shplonk.go @@ -29,8 +29,9 @@ import ( ) var ( - ErrInvalidNumberOfPoints = errors.New("number of digests should be equal to the number of points") - ErrVerifyOpeningProof = errors.New("can't verify batch opening proof") + ErrInvalidNumberOfPoints = errors.New("number of digests should be equal to the number of points") + ErrVerifyOpeningProof = errors.New("can't verify batch opening proof") + ErrInvalidNumberOfDigests = errors.New("number of digests should be equal to the number of polynomials") ) // OpeningProof KZG proof for opening (fᵢ)_{i} at a different points (xᵢ)_{i}. @@ -58,6 +59,9 @@ func BatchOpen(polynomials [][]fr.Element, digests []kzg.Digest, points [][]fr.E if len(polynomials) != len(points) { return res, ErrInvalidNumberOfPoints } + if len(polynomials) != len(digests) { + return res, ErrInvalidNumberOfDigests + } // transcript fs := fiatshamir.NewTranscript(hf, "gamma", "z") diff --git a/internal/generator/shplonk/template/shplonk.go.tmpl b/internal/generator/shplonk/template/shplonk.go.tmpl index c5f8fcbee..9d6a153c2 100644 --- a/internal/generator/shplonk/template/shplonk.go.tmpl +++ b/internal/generator/shplonk/template/shplonk.go.tmpl @@ -13,6 +13,7 @@ import ( var ( ErrInvalidNumberOfPoints = errors.New("number of digests should be equal to the number of points") ErrVerifyOpeningProof = errors.New("can't verify batch opening proof") + ErrInvalidNumberOfDigests = errors.New("number of digests should be equal to the number of polynomials") ) // OpeningProof KZG proof for opening (fᵢ)_{i} at a different points (xᵢ)_{i}. @@ -40,6 +41,9 @@ func BatchOpen(polynomials [][]fr.Element, digests []kzg.Digest, points [][]fr.E if len(polynomials) != len(points) { return res, ErrInvalidNumberOfPoints } + if len(polynomials) != len(digests) { + return res, ErrInvalidNumberOfDigests + } // transcript fs := fiatshamir.NewTranscript(hf, "gamma", "z")