From f08b5bb49dc9c78f8d9aad7d33278a9e899a2c1d Mon Sep 17 00:00:00 2001 From: Vlad <88586482+vladfdp@users.noreply.github.com> Date: Wed, 3 Jul 2024 09:07:43 +0200 Subject: [PATCH 1/5] fixed fromAffine and toProj in golang --- wrappers/golang/core/internal/mock_curve.go | 20 ++++++++++++++++--- wrappers/golang/curves/bls12377/curve.go | 20 ++++++++++++++++--- wrappers/golang/curves/bls12377/g2/curve.go | 20 ++++++++++++++++--- wrappers/golang/curves/bls12381/curve.go | 20 ++++++++++++++++--- wrappers/golang/curves/bls12381/g2/curve.go | 20 ++++++++++++++++--- wrappers/golang/curves/bn254/curve.go | 20 ++++++++++++++++--- wrappers/golang/curves/bn254/g2/curve.go | 20 ++++++++++++++++--- wrappers/golang/curves/bw6761/curve.go | 20 ++++++++++++++++--- wrappers/golang/curves/bw6761/g2/curve.go | 20 ++++++++++++++++--- wrappers/golang/curves/grumpkin/curve.go | 20 ++++++++++++++++--- .../generator/curves/templates/curve.go.tmpl | 16 ++++++++++++++- 11 files changed, 185 insertions(+), 31 deletions(-) diff --git a/wrappers/golang/core/internal/mock_curve.go b/wrappers/golang/core/internal/mock_curve.go index 0a6fe8be4..a980aeb38 100644 --- a/wrappers/golang/core/internal/mock_curve.go +++ b/wrappers/golang/core/internal/mock_curve.go @@ -32,9 +32,15 @@ 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.X = z.Zero() + p.Y = z.One() + p.Z = z.Zero() + } else { + p.X = a.X + p.Y = a.Y + p.Z = z.One() + } return *p } @@ -68,6 +74,14 @@ 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()) { + return MockProjective{ + X: z.Zero(), + Y: z.One(), + Z: z.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..c24c71731 100644 --- a/wrappers/golang/curves/bls12377/curve.go +++ b/wrappers/golang/curves/bls12377/curve.go @@ -43,9 +43,15 @@ 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.X = z.Zero() + p.Y = z.One() + p.Z = z.Zero() + } else { + p.X = a.X + p.Y = a.Y + p.Z = z.One() + } return *p } @@ -109,6 +115,14 @@ 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()) { + return Projective{ + X: z.Zero(), + Y: z.One(), + Z: z.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..433e83642 100644 --- a/wrappers/golang/curves/bls12377/g2/curve.go +++ b/wrappers/golang/curves/bls12377/g2/curve.go @@ -43,9 +43,15 @@ 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.X = z.Zero() + p.Y = z.One() + p.Z = z.Zero() + } else { + p.X = a.X + p.Y = a.Y + p.Z = z.One() + } return *p } @@ -109,6 +115,14 @@ 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()) { + return G2Projective{ + X: z.Zero(), + Y: z.One(), + Z: z.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..f4646914b 100644 --- a/wrappers/golang/curves/bls12381/curve.go +++ b/wrappers/golang/curves/bls12381/curve.go @@ -43,9 +43,15 @@ 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.X = z.Zero() + p.Y = z.One() + p.Z = z.Zero() + } else { + p.X = a.X + p.Y = a.Y + p.Z = z.One() + } return *p } @@ -109,6 +115,14 @@ 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()) { + return Projective{ + X: z.Zero(), + Y: z.One(), + Z: z.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..701513316 100644 --- a/wrappers/golang/curves/bls12381/g2/curve.go +++ b/wrappers/golang/curves/bls12381/g2/curve.go @@ -43,9 +43,15 @@ 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.X = z.Zero() + p.Y = z.One() + p.Z = z.Zero() + } else { + p.X = a.X + p.Y = a.Y + p.Z = z.One() + } return *p } @@ -109,6 +115,14 @@ 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()) { + return G2Projective{ + X: z.Zero(), + Y: z.One(), + Z: z.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..c91ee0cd6 100644 --- a/wrappers/golang/curves/bn254/curve.go +++ b/wrappers/golang/curves/bn254/curve.go @@ -43,9 +43,15 @@ 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.X = z.Zero() + p.Y = z.One() + p.Z = z.Zero() + } else { + p.X = a.X + p.Y = a.Y + p.Z = z.One() + } return *p } @@ -109,6 +115,14 @@ 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()) { + return Projective{ + X: z.Zero(), + Y: z.One(), + Z: z.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..58456188a 100644 --- a/wrappers/golang/curves/bn254/g2/curve.go +++ b/wrappers/golang/curves/bn254/g2/curve.go @@ -43,9 +43,15 @@ 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.X = z.Zero() + p.Y = z.One() + p.Z = z.Zero() + } else { + p.X = a.X + p.Y = a.Y + p.Z = z.One() + } return *p } @@ -109,6 +115,14 @@ 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()) { + return G2Projective{ + X: z.Zero(), + Y: z.One(), + Z: z.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..7d881dd90 100644 --- a/wrappers/golang/curves/bw6761/curve.go +++ b/wrappers/golang/curves/bw6761/curve.go @@ -43,9 +43,15 @@ 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.X = z.Zero() + p.Y = z.One() + p.Z = z.Zero() + } else { + p.X = a.X + p.Y = a.Y + p.Z = z.One() + } return *p } @@ -109,6 +115,14 @@ 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()) { + return Projective{ + X: z.Zero(), + Y: z.One(), + Z: z.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..dcb523e34 100644 --- a/wrappers/golang/curves/bw6761/g2/curve.go +++ b/wrappers/golang/curves/bw6761/g2/curve.go @@ -43,9 +43,15 @@ 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.X = z.Zero() + p.Y = z.One() + p.Z = z.Zero() + } else { + p.X = a.X + p.Y = a.Y + p.Z = z.One() + } return *p } @@ -109,6 +115,14 @@ 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()) { + return G2Projective{ + X: z.Zero(), + Y: z.One(), + Z: z.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..d23ff2417 100644 --- a/wrappers/golang/curves/grumpkin/curve.go +++ b/wrappers/golang/curves/grumpkin/curve.go @@ -43,9 +43,15 @@ 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.X = z.Zero() + p.Y = z.One() + p.Z = z.Zero() + } else { + p.X = a.X + p.Y = a.Y + p.Z = z.One() + } return *p } @@ -109,6 +115,14 @@ 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()) { + return Projective{ + X: z.Zero(), + Y: z.One(), + Z: z.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..15eecef98 100644 --- a/wrappers/golang/internal/generator/curves/templates/curve.go.tmpl +++ b/wrappers/golang/internal/generator/curves/templates/curve.go.tmpl @@ -43,9 +43,15 @@ func (p *{{.CurvePrefix}}Projective) FromAffine(a {{.CurvePrefix}}Affine) {{.Cur z := {{.CurvePrefix}}BaseField{} z.One() + if (a.X == z.Zero()) && (a.Y == z.Zero()) { + p.X = z.Zero() + p.Y = z.One() + p.Z = z.Zero() + }else{ p.X = a.X p.Y = a.Y - p.Z = z + p.Z = z.One() + } return *p } @@ -109,6 +115,14 @@ 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()) { + return {{.CurvePrefix}}Projective{ + X: z.Zero(), + Y: z.One(), + Z: z.Zero(), + } + } + return {{.CurvePrefix}}Projective{ X: a.X, Y: a.Y, From 9e057c835dafd72f8e265eb9b3bb032c08ae559d Mon Sep 17 00:00:00 2001 From: Vlad <88586482+vladfdp@users.noreply.github.com> Date: Wed, 3 Jul 2024 09:18:41 +0200 Subject: [PATCH 2/5] fixed to_projective in rust --- wrappers/rust/icicle-core/src/curve.rs | 3 +++ 1 file changed, 3 insertions(+) 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, From 17732ea013729170add5a97c5ac2dadca8af621f Mon Sep 17 00:00:00 2001 From: Vlad <88586482+vladfdp@users.noreply.github.com> Date: Wed, 3 Jul 2024 10:36:14 +0200 Subject: [PATCH 3/5] use zero method of projective in fromAffine Co-authored-by: Jeremy Felder --- .../golang/internal/generator/curves/templates/curve.go.tmpl | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/wrappers/golang/internal/generator/curves/templates/curve.go.tmpl b/wrappers/golang/internal/generator/curves/templates/curve.go.tmpl index 15eecef98..a43bee98e 100644 --- a/wrappers/golang/internal/generator/curves/templates/curve.go.tmpl +++ b/wrappers/golang/internal/generator/curves/templates/curve.go.tmpl @@ -44,9 +44,7 @@ func (p *{{.CurvePrefix}}Projective) FromAffine(a {{.CurvePrefix}}Affine) {{.Cur z.One() if (a.X == z.Zero()) && (a.Y == z.Zero()) { - p.X = z.Zero() - p.Y = z.One() - p.Z = z.Zero() + p.Zero() }else{ p.X = a.X p.Y = a.Y From 81644fc28c2c4d35b12b83146821a5861fff4658 Mon Sep 17 00:00:00 2001 From: Vlad <88586482+vladfdp@users.noreply.github.com> Date: Wed, 3 Jul 2024 10:37:02 +0200 Subject: [PATCH 4/5] use zero method of projective in toProjective Co-authored-by: Jeremy Felder --- .../internal/generator/curves/templates/curve.go.tmpl | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/wrappers/golang/internal/generator/curves/templates/curve.go.tmpl b/wrappers/golang/internal/generator/curves/templates/curve.go.tmpl index a43bee98e..d02fe6a96 100644 --- a/wrappers/golang/internal/generator/curves/templates/curve.go.tmpl +++ b/wrappers/golang/internal/generator/curves/templates/curve.go.tmpl @@ -114,11 +114,8 @@ func (a {{.CurvePrefix}}Affine) ToProjective() {{.CurvePrefix}}Projective { var z {{.CurvePrefix}}BaseField if (a.X == z.Zero()) && (a.Y == z.Zero()) { - return {{.CurvePrefix}}Projective{ - X: z.Zero(), - Y: z.One(), - Z: z.Zero(), - } + var p {{.CurvePrefix}}Projective + return p.Zero() } return {{.CurvePrefix}}Projective{ From 279cdc66e05c434244b99890e764c2c68d371101 Mon Sep 17 00:00:00 2001 From: Vlad <88586482+vladfdp@users.noreply.github.com> Date: Wed, 3 Jul 2024 10:41:32 +0200 Subject: [PATCH 5/5] generated go files --- wrappers/golang/core/internal/mock_curve.go | 11 +++-------- wrappers/golang/curves/bls12377/curve.go | 11 +++-------- wrappers/golang/curves/bls12377/g2/curve.go | 11 +++-------- wrappers/golang/curves/bls12381/curve.go | 11 +++-------- wrappers/golang/curves/bls12381/g2/curve.go | 11 +++-------- wrappers/golang/curves/bn254/curve.go | 11 +++-------- wrappers/golang/curves/bn254/g2/curve.go | 11 +++-------- wrappers/golang/curves/bw6761/curve.go | 11 +++-------- wrappers/golang/curves/bw6761/g2/curve.go | 11 +++-------- wrappers/golang/curves/grumpkin/curve.go | 11 +++-------- 10 files changed, 30 insertions(+), 80 deletions(-) diff --git a/wrappers/golang/core/internal/mock_curve.go b/wrappers/golang/core/internal/mock_curve.go index a980aeb38..de21b3d92 100644 --- a/wrappers/golang/core/internal/mock_curve.go +++ b/wrappers/golang/core/internal/mock_curve.go @@ -33,9 +33,7 @@ func (p *MockProjective) FromAffine(a MockAffine) MockProjective { z.One() if (a.X == z.Zero()) && (a.Y == z.Zero()) { - p.X = z.Zero() - p.Y = z.One() - p.Z = z.Zero() + p.Zero() } else { p.X = a.X p.Y = a.Y @@ -75,11 +73,8 @@ func (a MockAffine) ToProjective() MockProjective { var z MockBaseField if (a.X == z.Zero()) && (a.Y == z.Zero()) { - return MockProjective{ - X: z.Zero(), - Y: z.One(), - Z: z.Zero(), - } + var p MockProjective + return p.Zero() } return MockProjective{ diff --git a/wrappers/golang/curves/bls12377/curve.go b/wrappers/golang/curves/bls12377/curve.go index c24c71731..8083669ab 100644 --- a/wrappers/golang/curves/bls12377/curve.go +++ b/wrappers/golang/curves/bls12377/curve.go @@ -44,9 +44,7 @@ func (p *Projective) FromAffine(a Affine) Projective { z.One() if (a.X == z.Zero()) && (a.Y == z.Zero()) { - p.X = z.Zero() - p.Y = z.One() - p.Z = z.Zero() + p.Zero() } else { p.X = a.X p.Y = a.Y @@ -116,11 +114,8 @@ func (a Affine) ToProjective() Projective { var z BaseField if (a.X == z.Zero()) && (a.Y == z.Zero()) { - return Projective{ - X: z.Zero(), - Y: z.One(), - Z: z.Zero(), - } + var p Projective + return p.Zero() } return Projective{ diff --git a/wrappers/golang/curves/bls12377/g2/curve.go b/wrappers/golang/curves/bls12377/g2/curve.go index 433e83642..7da1d2717 100644 --- a/wrappers/golang/curves/bls12377/g2/curve.go +++ b/wrappers/golang/curves/bls12377/g2/curve.go @@ -44,9 +44,7 @@ func (p *G2Projective) FromAffine(a G2Affine) G2Projective { z.One() if (a.X == z.Zero()) && (a.Y == z.Zero()) { - p.X = z.Zero() - p.Y = z.One() - p.Z = z.Zero() + p.Zero() } else { p.X = a.X p.Y = a.Y @@ -116,11 +114,8 @@ func (a G2Affine) ToProjective() G2Projective { var z G2BaseField if (a.X == z.Zero()) && (a.Y == z.Zero()) { - return G2Projective{ - X: z.Zero(), - Y: z.One(), - Z: z.Zero(), - } + var p G2Projective + return p.Zero() } return G2Projective{ diff --git a/wrappers/golang/curves/bls12381/curve.go b/wrappers/golang/curves/bls12381/curve.go index f4646914b..02cee7b64 100644 --- a/wrappers/golang/curves/bls12381/curve.go +++ b/wrappers/golang/curves/bls12381/curve.go @@ -44,9 +44,7 @@ func (p *Projective) FromAffine(a Affine) Projective { z.One() if (a.X == z.Zero()) && (a.Y == z.Zero()) { - p.X = z.Zero() - p.Y = z.One() - p.Z = z.Zero() + p.Zero() } else { p.X = a.X p.Y = a.Y @@ -116,11 +114,8 @@ func (a Affine) ToProjective() Projective { var z BaseField if (a.X == z.Zero()) && (a.Y == z.Zero()) { - return Projective{ - X: z.Zero(), - Y: z.One(), - Z: z.Zero(), - } + var p Projective + return p.Zero() } return Projective{ diff --git a/wrappers/golang/curves/bls12381/g2/curve.go b/wrappers/golang/curves/bls12381/g2/curve.go index 701513316..d4fced658 100644 --- a/wrappers/golang/curves/bls12381/g2/curve.go +++ b/wrappers/golang/curves/bls12381/g2/curve.go @@ -44,9 +44,7 @@ func (p *G2Projective) FromAffine(a G2Affine) G2Projective { z.One() if (a.X == z.Zero()) && (a.Y == z.Zero()) { - p.X = z.Zero() - p.Y = z.One() - p.Z = z.Zero() + p.Zero() } else { p.X = a.X p.Y = a.Y @@ -116,11 +114,8 @@ func (a G2Affine) ToProjective() G2Projective { var z G2BaseField if (a.X == z.Zero()) && (a.Y == z.Zero()) { - return G2Projective{ - X: z.Zero(), - Y: z.One(), - Z: z.Zero(), - } + var p G2Projective + return p.Zero() } return G2Projective{ diff --git a/wrappers/golang/curves/bn254/curve.go b/wrappers/golang/curves/bn254/curve.go index c91ee0cd6..3bc94a8f0 100644 --- a/wrappers/golang/curves/bn254/curve.go +++ b/wrappers/golang/curves/bn254/curve.go @@ -44,9 +44,7 @@ func (p *Projective) FromAffine(a Affine) Projective { z.One() if (a.X == z.Zero()) && (a.Y == z.Zero()) { - p.X = z.Zero() - p.Y = z.One() - p.Z = z.Zero() + p.Zero() } else { p.X = a.X p.Y = a.Y @@ -116,11 +114,8 @@ func (a Affine) ToProjective() Projective { var z BaseField if (a.X == z.Zero()) && (a.Y == z.Zero()) { - return Projective{ - X: z.Zero(), - Y: z.One(), - Z: z.Zero(), - } + var p Projective + return p.Zero() } return Projective{ diff --git a/wrappers/golang/curves/bn254/g2/curve.go b/wrappers/golang/curves/bn254/g2/curve.go index 58456188a..7ee0ec7f9 100644 --- a/wrappers/golang/curves/bn254/g2/curve.go +++ b/wrappers/golang/curves/bn254/g2/curve.go @@ -44,9 +44,7 @@ func (p *G2Projective) FromAffine(a G2Affine) G2Projective { z.One() if (a.X == z.Zero()) && (a.Y == z.Zero()) { - p.X = z.Zero() - p.Y = z.One() - p.Z = z.Zero() + p.Zero() } else { p.X = a.X p.Y = a.Y @@ -116,11 +114,8 @@ func (a G2Affine) ToProjective() G2Projective { var z G2BaseField if (a.X == z.Zero()) && (a.Y == z.Zero()) { - return G2Projective{ - X: z.Zero(), - Y: z.One(), - Z: z.Zero(), - } + var p G2Projective + return p.Zero() } return G2Projective{ diff --git a/wrappers/golang/curves/bw6761/curve.go b/wrappers/golang/curves/bw6761/curve.go index 7d881dd90..2e8518be9 100644 --- a/wrappers/golang/curves/bw6761/curve.go +++ b/wrappers/golang/curves/bw6761/curve.go @@ -44,9 +44,7 @@ func (p *Projective) FromAffine(a Affine) Projective { z.One() if (a.X == z.Zero()) && (a.Y == z.Zero()) { - p.X = z.Zero() - p.Y = z.One() - p.Z = z.Zero() + p.Zero() } else { p.X = a.X p.Y = a.Y @@ -116,11 +114,8 @@ func (a Affine) ToProjective() Projective { var z BaseField if (a.X == z.Zero()) && (a.Y == z.Zero()) { - return Projective{ - X: z.Zero(), - Y: z.One(), - Z: z.Zero(), - } + var p Projective + return p.Zero() } return Projective{ diff --git a/wrappers/golang/curves/bw6761/g2/curve.go b/wrappers/golang/curves/bw6761/g2/curve.go index dcb523e34..1433602a2 100644 --- a/wrappers/golang/curves/bw6761/g2/curve.go +++ b/wrappers/golang/curves/bw6761/g2/curve.go @@ -44,9 +44,7 @@ func (p *G2Projective) FromAffine(a G2Affine) G2Projective { z.One() if (a.X == z.Zero()) && (a.Y == z.Zero()) { - p.X = z.Zero() - p.Y = z.One() - p.Z = z.Zero() + p.Zero() } else { p.X = a.X p.Y = a.Y @@ -116,11 +114,8 @@ func (a G2Affine) ToProjective() G2Projective { var z G2BaseField if (a.X == z.Zero()) && (a.Y == z.Zero()) { - return G2Projective{ - X: z.Zero(), - Y: z.One(), - Z: z.Zero(), - } + var p G2Projective + return p.Zero() } return G2Projective{ diff --git a/wrappers/golang/curves/grumpkin/curve.go b/wrappers/golang/curves/grumpkin/curve.go index d23ff2417..1079ce2e4 100644 --- a/wrappers/golang/curves/grumpkin/curve.go +++ b/wrappers/golang/curves/grumpkin/curve.go @@ -44,9 +44,7 @@ func (p *Projective) FromAffine(a Affine) Projective { z.One() if (a.X == z.Zero()) && (a.Y == z.Zero()) { - p.X = z.Zero() - p.Y = z.One() - p.Z = z.Zero() + p.Zero() } else { p.X = a.X p.Y = a.Y @@ -116,11 +114,8 @@ func (a Affine) ToProjective() Projective { var z BaseField if (a.X == z.Zero()) && (a.Y == z.Zero()) { - return Projective{ - X: z.Zero(), - Y: z.One(), - Z: z.Zero(), - } + var p Projective + return p.Zero() } return Projective{