diff --git a/ecc/bls12-377/fr/element_ops_amd64.go b/ecc/bls12-377/fr/element_ops_amd64.go index ce83db318..b653e8006 100644 --- a/ecc/bls12-377/fr/element_ops_amd64.go +++ b/ecc/bls12-377/fr/element_ops_amd64.go @@ -83,6 +83,11 @@ func (vector *Vector) ScalarMul(a Vector, b *Element) { return } n := uint64(len(a)) + if n == 0 { + return + } + // the code for scalarMul is identical to mulVec; and it expects at least + // 2 elements in the vector to fill the Z registers var bb [2]Element bb[0] = *b bb[1] = *b @@ -150,6 +155,9 @@ func (vector *Vector) Mul(a, b Vector) { panic("vector.Mul: vectors don't have the same length") } n := uint64(len(a)) + if n == 0 { + return + } const maxN = (1 << 32) - 1 if !supportAvx512 || n >= maxN { // call mulVecGeneric diff --git a/ecc/bls12-381/fr/element_ops_amd64.go b/ecc/bls12-381/fr/element_ops_amd64.go index ce83db318..b653e8006 100644 --- a/ecc/bls12-381/fr/element_ops_amd64.go +++ b/ecc/bls12-381/fr/element_ops_amd64.go @@ -83,6 +83,11 @@ func (vector *Vector) ScalarMul(a Vector, b *Element) { return } n := uint64(len(a)) + if n == 0 { + return + } + // the code for scalarMul is identical to mulVec; and it expects at least + // 2 elements in the vector to fill the Z registers var bb [2]Element bb[0] = *b bb[1] = *b @@ -150,6 +155,9 @@ func (vector *Vector) Mul(a, b Vector) { panic("vector.Mul: vectors don't have the same length") } n := uint64(len(a)) + if n == 0 { + return + } const maxN = (1 << 32) - 1 if !supportAvx512 || n >= maxN { // call mulVecGeneric diff --git a/ecc/bls24-315/fr/element_ops_amd64.go b/ecc/bls24-315/fr/element_ops_amd64.go index ce83db318..b653e8006 100644 --- a/ecc/bls24-315/fr/element_ops_amd64.go +++ b/ecc/bls24-315/fr/element_ops_amd64.go @@ -83,6 +83,11 @@ func (vector *Vector) ScalarMul(a Vector, b *Element) { return } n := uint64(len(a)) + if n == 0 { + return + } + // the code for scalarMul is identical to mulVec; and it expects at least + // 2 elements in the vector to fill the Z registers var bb [2]Element bb[0] = *b bb[1] = *b @@ -150,6 +155,9 @@ func (vector *Vector) Mul(a, b Vector) { panic("vector.Mul: vectors don't have the same length") } n := uint64(len(a)) + if n == 0 { + return + } const maxN = (1 << 32) - 1 if !supportAvx512 || n >= maxN { // call mulVecGeneric diff --git a/ecc/bls24-317/fr/element_ops_amd64.go b/ecc/bls24-317/fr/element_ops_amd64.go index ce83db318..b653e8006 100644 --- a/ecc/bls24-317/fr/element_ops_amd64.go +++ b/ecc/bls24-317/fr/element_ops_amd64.go @@ -83,6 +83,11 @@ func (vector *Vector) ScalarMul(a Vector, b *Element) { return } n := uint64(len(a)) + if n == 0 { + return + } + // the code for scalarMul is identical to mulVec; and it expects at least + // 2 elements in the vector to fill the Z registers var bb [2]Element bb[0] = *b bb[1] = *b @@ -150,6 +155,9 @@ func (vector *Vector) Mul(a, b Vector) { panic("vector.Mul: vectors don't have the same length") } n := uint64(len(a)) + if n == 0 { + return + } const maxN = (1 << 32) - 1 if !supportAvx512 || n >= maxN { // call mulVecGeneric diff --git a/ecc/bn254/fp/element_ops_amd64.go b/ecc/bn254/fp/element_ops_amd64.go index 7c5fe64d1..2ab1a9839 100644 --- a/ecc/bn254/fp/element_ops_amd64.go +++ b/ecc/bn254/fp/element_ops_amd64.go @@ -83,6 +83,11 @@ func (vector *Vector) ScalarMul(a Vector, b *Element) { return } n := uint64(len(a)) + if n == 0 { + return + } + // the code for scalarMul is identical to mulVec; and it expects at least + // 2 elements in the vector to fill the Z registers var bb [2]Element bb[0] = *b bb[1] = *b @@ -150,6 +155,9 @@ func (vector *Vector) Mul(a, b Vector) { panic("vector.Mul: vectors don't have the same length") } n := uint64(len(a)) + if n == 0 { + return + } const maxN = (1 << 32) - 1 if !supportAvx512 || n >= maxN { // call mulVecGeneric diff --git a/ecc/bn254/fr/element_ops_amd64.go b/ecc/bn254/fr/element_ops_amd64.go index ce83db318..b653e8006 100644 --- a/ecc/bn254/fr/element_ops_amd64.go +++ b/ecc/bn254/fr/element_ops_amd64.go @@ -83,6 +83,11 @@ func (vector *Vector) ScalarMul(a Vector, b *Element) { return } n := uint64(len(a)) + if n == 0 { + return + } + // the code for scalarMul is identical to mulVec; and it expects at least + // 2 elements in the vector to fill the Z registers var bb [2]Element bb[0] = *b bb[1] = *b @@ -150,6 +155,9 @@ func (vector *Vector) Mul(a, b Vector) { panic("vector.Mul: vectors don't have the same length") } n := uint64(len(a)) + if n == 0 { + return + } const maxN = (1 << 32) - 1 if !supportAvx512 || n >= maxN { // call mulVecGeneric diff --git a/ecc/stark-curve/fp/element_ops_amd64.go b/ecc/stark-curve/fp/element_ops_amd64.go index 7c5fe64d1..2ab1a9839 100644 --- a/ecc/stark-curve/fp/element_ops_amd64.go +++ b/ecc/stark-curve/fp/element_ops_amd64.go @@ -83,6 +83,11 @@ func (vector *Vector) ScalarMul(a Vector, b *Element) { return } n := uint64(len(a)) + if n == 0 { + return + } + // the code for scalarMul is identical to mulVec; and it expects at least + // 2 elements in the vector to fill the Z registers var bb [2]Element bb[0] = *b bb[1] = *b @@ -150,6 +155,9 @@ func (vector *Vector) Mul(a, b Vector) { panic("vector.Mul: vectors don't have the same length") } n := uint64(len(a)) + if n == 0 { + return + } const maxN = (1 << 32) - 1 if !supportAvx512 || n >= maxN { // call mulVecGeneric diff --git a/ecc/stark-curve/fr/element_ops_amd64.go b/ecc/stark-curve/fr/element_ops_amd64.go index ce83db318..b653e8006 100644 --- a/ecc/stark-curve/fr/element_ops_amd64.go +++ b/ecc/stark-curve/fr/element_ops_amd64.go @@ -83,6 +83,11 @@ func (vector *Vector) ScalarMul(a Vector, b *Element) { return } n := uint64(len(a)) + if n == 0 { + return + } + // the code for scalarMul is identical to mulVec; and it expects at least + // 2 elements in the vector to fill the Z registers var bb [2]Element bb[0] = *b bb[1] = *b @@ -150,6 +155,9 @@ func (vector *Vector) Mul(a, b Vector) { panic("vector.Mul: vectors don't have the same length") } n := uint64(len(a)) + if n == 0 { + return + } const maxN = (1 << 32) - 1 if !supportAvx512 || n >= maxN { // call mulVecGeneric diff --git a/field/generator/internal/templates/element/ops_asm.go b/field/generator/internal/templates/element/ops_asm.go index 55fb3783f..1d1408e26 100644 --- a/field/generator/internal/templates/element/ops_asm.go +++ b/field/generator/internal/templates/element/ops_asm.go @@ -68,6 +68,11 @@ func (vector *Vector) ScalarMul(a Vector, b *{{.ElementName}}) { return } n := uint64(len(a)) + if n == 0 { + return + } + // the code for scalarMul is identical to mulVec; and it expects at least + // 2 elements in the vector to fill the Z registers var bb [2]{{.ElementName}} bb[0] = *b bb[1] = *b @@ -135,6 +140,9 @@ func (vector *Vector) Mul(a, b Vector) { panic("vector.Mul: vectors don't have the same length") } n := uint64(len(a)) + if n == 0 { + return + } const maxN = (1 << 32) - 1 if !supportAvx512 || n >= maxN { // call mulVecGeneric