Skip to content

Commit 2298474

Browse files
committed
goldilocks; Handling points with z=0.
1 parent 5a940a1 commit 2298474

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

ecc/goldilocks/curve.go

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@ func (Curve) Identity() *Point {
1818
func (Curve) IsOnCurve(P *Point) bool {
1919
x2, y2, t, t2, z2 := &fp.Elt{}, &fp.Elt{}, &fp.Elt{}, &fp.Elt{}, &fp.Elt{}
2020
rhs, lhs := &fp.Elt{}, &fp.Elt{}
21+
// Check z != 0
22+
eq0 := !fp.IsZero(&P.z)
23+
2124
fp.Mul(t, &P.ta, &P.tb) // t = ta*tb
2225
fp.Sqr(x2, &P.x) // x^2
2326
fp.Sqr(y2, &P.y) // y^2
@@ -27,13 +30,14 @@ func (Curve) IsOnCurve(P *Point) bool {
2730
fp.Mul(rhs, t2, &paramD) // dt^2
2831
fp.Add(rhs, rhs, z2) // z^2 + dt^2
2932
fp.Sub(lhs, lhs, rhs) // x^2 + y^2 - (z^2 + dt^2)
30-
eq0 := fp.IsZero(lhs)
33+
eq1 := fp.IsZero(lhs)
3134

3235
fp.Mul(lhs, &P.x, &P.y) // xy
3336
fp.Mul(rhs, t, &P.z) // tz
3437
fp.Sub(lhs, lhs, rhs) // xy - tz
35-
eq1 := fp.IsZero(lhs)
36-
return eq0 && eq1
38+
eq2 := fp.IsZero(lhs)
39+
40+
return eq0 && eq1 && eq2
3741
}
3842

3943
// Generator returns the generator point.

0 commit comments

Comments
 (0)