Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix/vlad/affine to proj #552

Merged
merged 5 commits into from
Jul 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 12 additions & 3 deletions wrappers/golang/core/internal/mock_curve.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -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,
Expand Down
15 changes: 12 additions & 3 deletions wrappers/golang/curves/bls12377/curve.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -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,
Expand Down
15 changes: 12 additions & 3 deletions wrappers/golang/curves/bls12377/g2/curve.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -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,
Expand Down
15 changes: 12 additions & 3 deletions wrappers/golang/curves/bls12381/curve.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -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,
Expand Down
15 changes: 12 additions & 3 deletions wrappers/golang/curves/bls12381/g2/curve.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -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,
Expand Down
15 changes: 12 additions & 3 deletions wrappers/golang/curves/bn254/curve.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -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,
Expand Down
15 changes: 12 additions & 3 deletions wrappers/golang/curves/bn254/g2/curve.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -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,
Expand Down
15 changes: 12 additions & 3 deletions wrappers/golang/curves/bw6761/curve.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -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,
Expand Down
15 changes: 12 additions & 3 deletions wrappers/golang/curves/bw6761/g2/curve.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -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,
Expand Down
15 changes: 12 additions & 3 deletions wrappers/golang/curves/grumpkin/curve.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -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,
Expand Down
3 changes: 3 additions & 0 deletions wrappers/rust/icicle-core/src/curve.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,9 @@ impl<C: Curve> Affine<C> {
}

pub fn to_projective(&self) -> Projective<C> {
if *self == Self::zero() {
return Projective::<C>::zero();
}
Projective {
x: self.x,
y: self.y,
Expand Down
Loading