-
Notifications
You must be signed in to change notification settings - Fork 516
bug: Error multiplying a twistededwards point by scalar zero #1547
Copy link
Copy link
Closed
Description
Some of the hints used to perform an efficient ScalarMul operation over TwistedEdwards curve point does not check if the scalar used to the multiplication is zero, causing a division by zero.
Description
Here is a gist with a simple test and the current output: div_zero_test.go
The route of the error is the following:
func (c *curve) ScalarMul(p1 Point, scalar frontend.Variable) Point { - https://github.com/Consensys/gnark/blob/master/std/algebra/native/twistededwards/point.go#L130
- https://github.com/Consensys/gnark/blob/master/std/algebra/native/twistededwards/point.go#L245
func halfGCD(mod *big.Int, inputs, outputs []*big.Int) error { - https://github.com/Consensys/gnark-crypto/blob/master/ecc/utils.go#L102
Expected Behavior
If the scalar used to the multiplication is zero, the result should be the Identity Point of the curve.
Possible Fix
Add something similar to this in
| glvBasis := new(ecc.Lattice) |
if inputs[0].Sign() == 0 {
outputs[0].SetUint64(0) // s1
outputs[1].SetUint64(0) // s2
return nil
}Steps to Reproduce
Check the gists with the test: div_zero_test.go
Context
We are trying to re-encrypt a frontend.Variable with elGamal, which involves to add a encrypted zero. The bug comes when we tried to encrypt a zero value.
Your Environment
- gnark version used (e.g. v0.8.1,
HEAD@develop): HEAD@master - gnark-crypto version used: v0.18.0
- go version (e.g. 1.20.6): v1.24.2
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels