diff --git a/wrappers/golang/core/internal/mock_curve.go b/wrappers/golang/core/internal/mock_curve.go index 0a6fe8be4..de21b3d92 100644 --- a/wrappers/golang/core/internal/mock_curve.go +++ b/wrappers/golang/core/internal/mock_curve.go @@ -32,9 +32,13 @@ func (p *MockProjective) FromAffine(a MockAffine) MockProjective { z := MockBaseField{} z.One() - p.X = a.X - p.Y = a.Y - p.Z = z + if (a.X == z.Zero()) && (a.Y == z.Zero()) { + p.Zero() + } else { + p.X = a.X + p.Y = a.Y + p.Z = z.One() + } return *p } @@ -68,6 +72,11 @@ func (a *MockAffine) FromLimbs(x, y []uint32) MockAffine { func (a MockAffine) ToProjective() MockProjective { var z MockBaseField + if (a.X == z.Zero()) && (a.Y == z.Zero()) { + var p MockProjective + return p.Zero() + } + return MockProjective{ X: a.X, Y: a.Y, diff --git a/wrappers/golang/curves/bls12377/curve.go b/wrappers/golang/curves/bls12377/curve.go index e21dd5808..8083669ab 100644 --- a/wrappers/golang/curves/bls12377/curve.go +++ b/wrappers/golang/curves/bls12377/curve.go @@ -43,9 +43,13 @@ func (p *Projective) FromAffine(a Affine) Projective { z := BaseField{} z.One() - p.X = a.X - p.Y = a.Y - p.Z = z + if (a.X == z.Zero()) && (a.Y == z.Zero()) { + p.Zero() + } else { + p.X = a.X + p.Y = a.Y + p.Z = z.One() + } return *p } @@ -109,6 +113,11 @@ func (a *Affine) FromLimbs(x, y []uint32) Affine { func (a Affine) ToProjective() Projective { var z BaseField + if (a.X == z.Zero()) && (a.Y == z.Zero()) { + var p Projective + return p.Zero() + } + return Projective{ X: a.X, Y: a.Y, diff --git a/wrappers/golang/curves/bls12377/g2/curve.go b/wrappers/golang/curves/bls12377/g2/curve.go index 50ac2a110..7da1d2717 100644 --- a/wrappers/golang/curves/bls12377/g2/curve.go +++ b/wrappers/golang/curves/bls12377/g2/curve.go @@ -43,9 +43,13 @@ func (p *G2Projective) FromAffine(a G2Affine) G2Projective { z := G2BaseField{} z.One() - p.X = a.X - p.Y = a.Y - p.Z = z + if (a.X == z.Zero()) && (a.Y == z.Zero()) { + p.Zero() + } else { + p.X = a.X + p.Y = a.Y + p.Z = z.One() + } return *p } @@ -109,6 +113,11 @@ func (a *G2Affine) FromLimbs(x, y []uint32) G2Affine { func (a G2Affine) ToProjective() G2Projective { var z G2BaseField + if (a.X == z.Zero()) && (a.Y == z.Zero()) { + var p G2Projective + return p.Zero() + } + return G2Projective{ X: a.X, Y: a.Y, diff --git a/wrappers/golang/curves/bls12381/curve.go b/wrappers/golang/curves/bls12381/curve.go index d376c5c21..02cee7b64 100644 --- a/wrappers/golang/curves/bls12381/curve.go +++ b/wrappers/golang/curves/bls12381/curve.go @@ -43,9 +43,13 @@ func (p *Projective) FromAffine(a Affine) Projective { z := BaseField{} z.One() - p.X = a.X - p.Y = a.Y - p.Z = z + if (a.X == z.Zero()) && (a.Y == z.Zero()) { + p.Zero() + } else { + p.X = a.X + p.Y = a.Y + p.Z = z.One() + } return *p } @@ -109,6 +113,11 @@ func (a *Affine) FromLimbs(x, y []uint32) Affine { func (a Affine) ToProjective() Projective { var z BaseField + if (a.X == z.Zero()) && (a.Y == z.Zero()) { + var p Projective + return p.Zero() + } + return Projective{ X: a.X, Y: a.Y, diff --git a/wrappers/golang/curves/bls12381/g2/curve.go b/wrappers/golang/curves/bls12381/g2/curve.go index 2b8caa002..d4fced658 100644 --- a/wrappers/golang/curves/bls12381/g2/curve.go +++ b/wrappers/golang/curves/bls12381/g2/curve.go @@ -43,9 +43,13 @@ func (p *G2Projective) FromAffine(a G2Affine) G2Projective { z := G2BaseField{} z.One() - p.X = a.X - p.Y = a.Y - p.Z = z + if (a.X == z.Zero()) && (a.Y == z.Zero()) { + p.Zero() + } else { + p.X = a.X + p.Y = a.Y + p.Z = z.One() + } return *p } @@ -109,6 +113,11 @@ func (a *G2Affine) FromLimbs(x, y []uint32) G2Affine { func (a G2Affine) ToProjective() G2Projective { var z G2BaseField + if (a.X == z.Zero()) && (a.Y == z.Zero()) { + var p G2Projective + return p.Zero() + } + return G2Projective{ X: a.X, Y: a.Y, diff --git a/wrappers/golang/curves/bn254/curve.go b/wrappers/golang/curves/bn254/curve.go index 80a844c7a..3bc94a8f0 100644 --- a/wrappers/golang/curves/bn254/curve.go +++ b/wrappers/golang/curves/bn254/curve.go @@ -43,9 +43,13 @@ func (p *Projective) FromAffine(a Affine) Projective { z := BaseField{} z.One() - p.X = a.X - p.Y = a.Y - p.Z = z + if (a.X == z.Zero()) && (a.Y == z.Zero()) { + p.Zero() + } else { + p.X = a.X + p.Y = a.Y + p.Z = z.One() + } return *p } @@ -109,6 +113,11 @@ func (a *Affine) FromLimbs(x, y []uint32) Affine { func (a Affine) ToProjective() Projective { var z BaseField + if (a.X == z.Zero()) && (a.Y == z.Zero()) { + var p Projective + return p.Zero() + } + return Projective{ X: a.X, Y: a.Y, diff --git a/wrappers/golang/curves/bn254/g2/curve.go b/wrappers/golang/curves/bn254/g2/curve.go index 586d23831..7ee0ec7f9 100644 --- a/wrappers/golang/curves/bn254/g2/curve.go +++ b/wrappers/golang/curves/bn254/g2/curve.go @@ -43,9 +43,13 @@ func (p *G2Projective) FromAffine(a G2Affine) G2Projective { z := G2BaseField{} z.One() - p.X = a.X - p.Y = a.Y - p.Z = z + if (a.X == z.Zero()) && (a.Y == z.Zero()) { + p.Zero() + } else { + p.X = a.X + p.Y = a.Y + p.Z = z.One() + } return *p } @@ -109,6 +113,11 @@ func (a *G2Affine) FromLimbs(x, y []uint32) G2Affine { func (a G2Affine) ToProjective() G2Projective { var z G2BaseField + if (a.X == z.Zero()) && (a.Y == z.Zero()) { + var p G2Projective + return p.Zero() + } + return G2Projective{ X: a.X, Y: a.Y, diff --git a/wrappers/golang/curves/bw6761/curve.go b/wrappers/golang/curves/bw6761/curve.go index 907971405..2e8518be9 100644 --- a/wrappers/golang/curves/bw6761/curve.go +++ b/wrappers/golang/curves/bw6761/curve.go @@ -43,9 +43,13 @@ func (p *Projective) FromAffine(a Affine) Projective { z := BaseField{} z.One() - p.X = a.X - p.Y = a.Y - p.Z = z + if (a.X == z.Zero()) && (a.Y == z.Zero()) { + p.Zero() + } else { + p.X = a.X + p.Y = a.Y + p.Z = z.One() + } return *p } @@ -109,6 +113,11 @@ func (a *Affine) FromLimbs(x, y []uint32) Affine { func (a Affine) ToProjective() Projective { var z BaseField + if (a.X == z.Zero()) && (a.Y == z.Zero()) { + var p Projective + return p.Zero() + } + return Projective{ X: a.X, Y: a.Y, diff --git a/wrappers/golang/curves/bw6761/g2/curve.go b/wrappers/golang/curves/bw6761/g2/curve.go index 4167674ef..1433602a2 100644 --- a/wrappers/golang/curves/bw6761/g2/curve.go +++ b/wrappers/golang/curves/bw6761/g2/curve.go @@ -43,9 +43,13 @@ func (p *G2Projective) FromAffine(a G2Affine) G2Projective { z := G2BaseField{} z.One() - p.X = a.X - p.Y = a.Y - p.Z = z + if (a.X == z.Zero()) && (a.Y == z.Zero()) { + p.Zero() + } else { + p.X = a.X + p.Y = a.Y + p.Z = z.One() + } return *p } @@ -109,6 +113,11 @@ func (a *G2Affine) FromLimbs(x, y []uint32) G2Affine { func (a G2Affine) ToProjective() G2Projective { var z G2BaseField + if (a.X == z.Zero()) && (a.Y == z.Zero()) { + var p G2Projective + return p.Zero() + } + return G2Projective{ X: a.X, Y: a.Y, diff --git a/wrappers/golang/curves/grumpkin/curve.go b/wrappers/golang/curves/grumpkin/curve.go index 653cbc8ed..1079ce2e4 100644 --- a/wrappers/golang/curves/grumpkin/curve.go +++ b/wrappers/golang/curves/grumpkin/curve.go @@ -43,9 +43,13 @@ func (p *Projective) FromAffine(a Affine) Projective { z := BaseField{} z.One() - p.X = a.X - p.Y = a.Y - p.Z = z + if (a.X == z.Zero()) && (a.Y == z.Zero()) { + p.Zero() + } else { + p.X = a.X + p.Y = a.Y + p.Z = z.One() + } return *p } @@ -109,6 +113,11 @@ func (a *Affine) FromLimbs(x, y []uint32) Affine { func (a Affine) ToProjective() Projective { var z BaseField + if (a.X == z.Zero()) && (a.Y == z.Zero()) { + var p Projective + return p.Zero() + } + return Projective{ X: a.X, Y: a.Y, diff --git a/wrappers/golang/internal/generator/curves/templates/curve.go.tmpl b/wrappers/golang/internal/generator/curves/templates/curve.go.tmpl index e6bd59d55..d02fe6a96 100644 --- a/wrappers/golang/internal/generator/curves/templates/curve.go.tmpl +++ b/wrappers/golang/internal/generator/curves/templates/curve.go.tmpl @@ -43,9 +43,13 @@ func (p *{{.CurvePrefix}}Projective) FromAffine(a {{.CurvePrefix}}Affine) {{.Cur z := {{.CurvePrefix}}BaseField{} z.One() + if (a.X == z.Zero()) && (a.Y == z.Zero()) { + p.Zero() + }else{ p.X = a.X p.Y = a.Y - p.Z = z + p.Z = z.One() + } return *p } @@ -109,6 +113,11 @@ func (a *{{.CurvePrefix}}Affine) FromLimbs(x, y []uint32) {{.CurvePrefix}}Affine func (a {{.CurvePrefix}}Affine) ToProjective() {{.CurvePrefix}}Projective { var z {{.CurvePrefix}}BaseField + if (a.X == z.Zero()) && (a.Y == z.Zero()) { + var p {{.CurvePrefix}}Projective + return p.Zero() + } + return {{.CurvePrefix}}Projective{ X: a.X, Y: a.Y, diff --git a/wrappers/rust/icicle-core/src/curve.rs b/wrappers/rust/icicle-core/src/curve.rs index 89bec1c2e..c0b82d113 100644 --- a/wrappers/rust/icicle-core/src/curve.rs +++ b/wrappers/rust/icicle-core/src/curve.rs @@ -79,6 +79,9 @@ impl Affine { } pub fn to_projective(&self) -> Projective { + if *self == Self::zero() { + return Projective::::zero(); + } Projective { x: self.x, y: self.y,