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

support icicle v2.0.2 #20

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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
79 changes: 79 additions & 0 deletions curves/bls12377/conversions.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
package bls12377

import (
bls12_377 "github.com/consensys/gnark-crypto/ecc/bls12-377"
"github.com/consensys/gnark-crypto/ecc/bls12-377/fp"
icicle_bls12_377 "github.com/ingonyama-zk/icicle/v2/wrappers/golang/curves/bls12377"
)

func StripZ(p *icicle_bls12_377.Projective) *icicle_bls12_377.Affine {
return &icicle_bls12_377.Affine{
X: p.X,
Y: p.Y,
}
}

func BatchConvertFromG1Affine(elements []bls12_377.G1Affine) []icicle_bls12_377.Affine {
var newElements []icicle_bls12_377.Affine
for _, e := range elements {
var newElement icicle_bls12_377.Projective
FromG1AffineGnark(&e, &newElement)

newElements = append(newElements, *StripZ(&newElement))
}
return newElements
}

func ProjectiveToGnarkAffine(p *icicle_bls12_377.Projective) *bls12_377.G1Affine {
px := BaseFieldToGnarkFp(&p.X)
py := BaseFieldToGnarkFp(&p.Y)
pz := BaseFieldToGnarkFp(&p.Z)

zInv := new(fp.Element)
x := new(fp.Element)
y := new(fp.Element)

zInv.Inverse(pz)

x.Mul(px, zInv)
y.Mul(py, zInv)

return &bls12_377.G1Affine{X: *x, Y: *y}
}

func G1ProjectivePointToGnarkJac(p *icicle_bls12_377.Projective) *bls12_377.G1Jac {
var p1 bls12_377.G1Jac
p1.FromAffine(ProjectiveToGnarkAffine(p))

return &p1
}

func FromG1AffineGnark(gnark *bls12_377.G1Affine, p *icicle_bls12_377.Projective) *icicle_bls12_377.Projective {
var z icicle_bls12_377.BaseField
z.One()

p.X = *NewFieldFromFpGnark(gnark.X)
p.Y = *NewFieldFromFpGnark(gnark.Y)
p.Z = z

return p
}

func G1ProjectivePointFromJacGnark(p *icicle_bls12_377.Projective, gnark *bls12_377.G1Jac) *icicle_bls12_377.Projective {
var pointAffine bls12_377.G1Affine
pointAffine.FromJacobian(gnark)

var z icicle_bls12_377.BaseField
z.One()

p.X = *NewFieldFromFpGnark(pointAffine.X)
p.Y = *NewFieldFromFpGnark(pointAffine.Y)
p.Z = z

return p
}

func AffineToGnarkAffine(p *icicle_bls12_377.Affine) *bls12_377.G1Affine {
pointProjective := p.ToProjective()
return ProjectiveToGnarkAffine(&pointProjective)
}
71 changes: 0 additions & 71 deletions curves/bls12377/g1_conversions.go

This file was deleted.

Loading