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

V3 golang bindings #594

Merged
merged 30 commits into from
Sep 3, 2024
Merged
Changes from 1 commit
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
0c5b6b2
pr fixes
nonam3e Aug 27, 2024
1bdcccd
update generators
nonam3e Aug 28, 2024
6bc9d37
update montgomery wrappers
nonam3e Aug 28, 2024
6e49a35
update runtime
nonam3e Aug 28, 2024
42aa21b
change golang ci
nonam3e Aug 29, 2024
7f7b432
fix malloc calls
nonam3e Aug 30, 2024
74fca20
generators
nonam3e Aug 30, 2024
d882ed6
update docs
nonam3e Aug 30, 2024
447c40c
fix typo
nonam3e Aug 30, 2024
fad0d85
update readme
nonam3e Aug 30, 2024
3cae409
r
nonam3e Aug 30, 2024
ff49d9d
First iteration of PR fixes
jeremyfelder Sep 1, 2024
945a44f
[ci skip] move extract cuda backend workflow to reusable workflow
jeremyfelder Sep 1, 2024
670f222
Add extern func for from_affine
jeremyfelder Sep 1, 2024
795a4ff
Docs WIP, add msm nof_chunks, revert cgo linkage for libs
jeremyfelder Sep 2, 2024
23fa362
fmt
jeremyfelder Sep 2, 2024
e25ab67
Run go generate for lib name revert
jeremyfelder Sep 2, 2024
c2bc65c
Fix from_affine
jeremyfelder Sep 2, 2024
88edc80
Fix cpu_msm implementation
jeremyfelder Sep 2, 2024
8bfdd04
Fix tests #1
jeremyfelder Sep 2, 2024
0e5a616
Fix golang workflow cuda backend branch ref
jeremyfelder Sep 2, 2024
0845fb1
update programmers_guide
nonam3e Sep 2, 2024
e8df7df
Merge branch 'yshekel/V3' into nonam3e/golang-bindings/V3
nonam3e Sep 2, 2024
2ea20f3
Remove TODO for SetFinalizers, update build script to not use ICICLE_…
jeremyfelder Sep 2, 2024
bdae646
Merge branch 'yshekel/V3' into nonam3e/golang-bindings/V3
yshekel Sep 2, 2024
2c21102
change cgo path
nonam3e Sep 3, 2024
8e033b6
runtime cgo
nonam3e Sep 3, 2024
8dfa22b
remove cuda_runtime import from go wrappers
nonam3e Sep 3, 2024
b5ec021
change ICICLE_BACKEND_INSTALL_DIR in golang workflow
nonam3e Sep 3, 2024
b0bf67c
Merge branch 'yshekel/V3' into nonam3e/golang-bindings/V3
nonam3e Sep 3, 2024
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
Prev Previous commit
Next Next commit
First iteration of PR fixes
  • Loading branch information
jeremyfelder committed Sep 2, 2024
commit ff49d9dd502605db3c26ae6b091c61e113771710
21 changes: 0 additions & 21 deletions wrappers/golang/core/internal/mock_curve.go
Original file line number Diff line number Diff line change
@@ -28,17 +28,6 @@ func (p *MockProjective) FromLimbs(x, y, z []uint32) MockProjective {
return *p
}

func (p *MockProjective) FromAffine(a MockAffine) MockProjective {
z := MockBaseField{}
z.One()

p.X = a.X
p.Y = a.Y
p.Z = z

return *p
}

type MockAffine struct {
X, Y MockBaseField
}
@@ -64,13 +53,3 @@ func (a *MockAffine) FromLimbs(x, y []uint32) MockAffine {

return *a
}

func (a MockAffine) ToProjective() MockProjective {
var z MockBaseField

return MockProjective{
X: a.X,
Y: a.Y,
Z: z.One(),
}
}
1 change: 0 additions & 1 deletion wrappers/golang/core/msm.go
Original file line number Diff line number Diff line change
@@ -94,7 +94,6 @@ func MsmCheck(scalars HostOrDeviceSlice, bases HostOrDeviceSlice, cfg *MSMConfig
panic(errorString)
}

// cfg.basesSize = int32(basesLength)
cfg.ArePointsSharedInBatch = basesLength < scalarsLength
cfg.BatchSize = int32(resultsLength)
cfg.areScalarsOnDevice = scalars.IsOnDevice()
4 changes: 2 additions & 2 deletions wrappers/golang/core/slice.go
Original file line number Diff line number Diff line change
@@ -56,7 +56,7 @@ func (d *DeviceSlice) Range(start, end int, endInclusive bool) DeviceSlice {
panic("Cannot have negative or zero size slices")
}

if end >= d.length {
if (endInclusive && end >= d.length) || (!endInclusive && end > d.length) {
panic("Cannot increase slice size from Range")
}

@@ -78,7 +78,7 @@ func (d *DeviceSlice) RangeTo(end int, inclusive bool) DeviceSlice {
panic("Cannot have negative or zero size slices")
}

if end >= d.length {
if (inclusive && end >= d.length) || (!inclusive && end > d.length) {
panic("Cannot increase slice size from Range")
}

24 changes: 10 additions & 14 deletions wrappers/golang/curves/bls12377/curve.go
Original file line number Diff line number Diff line change
@@ -40,13 +40,10 @@ func (p *Projective) FromLimbs(x, y, z []uint32) Projective {
}

func (p *Projective) FromAffine(a Affine) Projective {
z := BaseField{}
z.One()

p.X = a.X
p.Y = a.Y
p.Z = z

cA := (*C.affine_t)(unsafe.Pointer(&a))
cP := (*C.projective_t)(unsafe.Pointer(p))
C.bls12_377_from_affine(cA, cP)
return *p
}

@@ -57,11 +54,11 @@ func (p Projective) ProjectiveEq(p2 *Projective) bool {
return __ret == (C._Bool)(true)
}

func (p *Projective) ProjectiveToAffine() Affine {
func (p *Projective) ToAffine() Affine {
var a Affine

cA := (*C.affine_t)(unsafe.Pointer(&a))
cP := (*C.projective_t)(unsafe.Pointer(&p))
cP := (*C.projective_t)(unsafe.Pointer(p))
C.bls12_377_to_affine(cP, cA)
return a
}
@@ -107,13 +104,12 @@ func (a *Affine) FromLimbs(x, y []uint32) Affine {
}

func (a Affine) ToProjective() Projective {
var z BaseField
var p Projective

return Projective{
X: a.X,
Y: a.Y,
Z: z.One(),
}
cA := (*C.affine_t)(unsafe.Pointer(&a))
cP := (*C.projective_t)(unsafe.Pointer(&p))
C.bls12_377_from_affine(cA, cP)
return p
}

func AffineFromProjective(p *Projective) Affine {
24 changes: 10 additions & 14 deletions wrappers/golang/curves/bls12377/g2/curve.go
Original file line number Diff line number Diff line change
@@ -40,13 +40,10 @@ func (p *G2Projective) FromLimbs(x, y, z []uint32) G2Projective {
}

func (p *G2Projective) FromAffine(a G2Affine) G2Projective {
z := G2BaseField{}
z.One()

p.X = a.X
p.Y = a.Y
p.Z = z

cA := (*C.g2_affine_t)(unsafe.Pointer(&a))
cP := (*C.g2_projective_t)(unsafe.Pointer(p))
C.bls12_377_g2_from_affine(cA, cP)
return *p
}

@@ -57,11 +54,11 @@ func (p G2Projective) ProjectiveEq(p2 *G2Projective) bool {
return __ret == (C._Bool)(true)
}

func (p *G2Projective) ProjectiveToAffine() G2Affine {
func (p *G2Projective) ToAffine() G2Affine {
var a G2Affine

cA := (*C.g2_affine_t)(unsafe.Pointer(&a))
cP := (*C.g2_projective_t)(unsafe.Pointer(&p))
cP := (*C.g2_projective_t)(unsafe.Pointer(p))
C.bls12_377_g2_to_affine(cP, cA)
return a
}
@@ -107,13 +104,12 @@ func (a *G2Affine) FromLimbs(x, y []uint32) G2Affine {
}

func (a G2Affine) ToProjective() G2Projective {
var z G2BaseField
var p G2Projective

return G2Projective{
X: a.X,
Y: a.Y,
Z: z.One(),
}
cA := (*C.g2_affine_t)(unsafe.Pointer(&a))
cP := (*C.g2_projective_t)(unsafe.Pointer(&p))
C.bls12_377_g2_from_affine(cA, cP)
return p
}

func G2AffineFromProjective(p *G2Projective) G2Affine {
2 changes: 1 addition & 1 deletion wrappers/golang/curves/bls12377/main.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package bls12377

// #cgo LDFLAGS: -L${SRCDIR}/../../../../build/lib -licicle_field_bls12_377 -licicle_curve_bls12_377 -lstdc++ -Wl,-rpath=${SRCDIR}/../../../../build/lib
// #cgo LDFLAGS: -L${SRCDIR}/../../../../build/lib -libcicle_field_bls12_377 -libcicle_curve_bls12_377 -lstdc++ -Wl,-rpath=${SRCDIR}/../../../../build/lib
import "C"
2 changes: 1 addition & 1 deletion wrappers/golang/curves/bls12377/tests/g2_msm_test.go
Original file line number Diff line number Diff line change
@@ -8,7 +8,7 @@ import (
"github.com/stretchr/testify/assert"

"github.com/consensys/gnark-crypto/ecc"
bls12377 "github.com/consensys/gnark-crypto/ecc/bls12-377"
"github.com/consensys/gnark-crypto/ecc/bls12-377"
"github.com/consensys/gnark-crypto/ecc/bls12-377/fp"
"github.com/consensys/gnark-crypto/ecc/bls12-377/fr"

2 changes: 1 addition & 1 deletion wrappers/golang/curves/bls12377/tests/msm_test.go
Original file line number Diff line number Diff line change
@@ -8,7 +8,7 @@ import (
"github.com/stretchr/testify/assert"

"github.com/consensys/gnark-crypto/ecc"
bls12377 "github.com/consensys/gnark-crypto/ecc/bls12-377"
"github.com/consensys/gnark-crypto/ecc/bls12-377"
"github.com/consensys/gnark-crypto/ecc/bls12-377/fp"
"github.com/consensys/gnark-crypto/ecc/bls12-377/fr"

24 changes: 10 additions & 14 deletions wrappers/golang/curves/bls12381/curve.go
Original file line number Diff line number Diff line change
@@ -40,13 +40,10 @@ func (p *Projective) FromLimbs(x, y, z []uint32) Projective {
}

func (p *Projective) FromAffine(a Affine) Projective {
z := BaseField{}
z.One()

p.X = a.X
p.Y = a.Y
p.Z = z

cA := (*C.affine_t)(unsafe.Pointer(&a))
cP := (*C.projective_t)(unsafe.Pointer(p))
C.bls12_381_from_affine(cA, cP)
return *p
}

@@ -57,11 +54,11 @@ func (p Projective) ProjectiveEq(p2 *Projective) bool {
return __ret == (C._Bool)(true)
}

func (p *Projective) ProjectiveToAffine() Affine {
func (p *Projective) ToAffine() Affine {
var a Affine

cA := (*C.affine_t)(unsafe.Pointer(&a))
cP := (*C.projective_t)(unsafe.Pointer(&p))
cP := (*C.projective_t)(unsafe.Pointer(p))
C.bls12_381_to_affine(cP, cA)
return a
}
@@ -107,13 +104,12 @@ func (a *Affine) FromLimbs(x, y []uint32) Affine {
}

func (a Affine) ToProjective() Projective {
var z BaseField
var p Projective

return Projective{
X: a.X,
Y: a.Y,
Z: z.One(),
}
cA := (*C.affine_t)(unsafe.Pointer(&a))
cP := (*C.projective_t)(unsafe.Pointer(&p))
C.bls12_381_from_affine(cA, cP)
return p
}

func AffineFromProjective(p *Projective) Affine {
24 changes: 10 additions & 14 deletions wrappers/golang/curves/bls12381/g2/curve.go
Original file line number Diff line number Diff line change
@@ -40,13 +40,10 @@ func (p *G2Projective) FromLimbs(x, y, z []uint32) G2Projective {
}

func (p *G2Projective) FromAffine(a G2Affine) G2Projective {
z := G2BaseField{}
z.One()

p.X = a.X
p.Y = a.Y
p.Z = z

cA := (*C.g2_affine_t)(unsafe.Pointer(&a))
cP := (*C.g2_projective_t)(unsafe.Pointer(p))
C.bls12_381_g2_from_affine(cA, cP)
return *p
}

@@ -57,11 +54,11 @@ func (p G2Projective) ProjectiveEq(p2 *G2Projective) bool {
return __ret == (C._Bool)(true)
}

func (p *G2Projective) ProjectiveToAffine() G2Affine {
func (p *G2Projective) ToAffine() G2Affine {
var a G2Affine

cA := (*C.g2_affine_t)(unsafe.Pointer(&a))
cP := (*C.g2_projective_t)(unsafe.Pointer(&p))
cP := (*C.g2_projective_t)(unsafe.Pointer(p))
C.bls12_381_g2_to_affine(cP, cA)
return a
}
@@ -107,13 +104,12 @@ func (a *G2Affine) FromLimbs(x, y []uint32) G2Affine {
}

func (a G2Affine) ToProjective() G2Projective {
var z G2BaseField
var p G2Projective

return G2Projective{
X: a.X,
Y: a.Y,
Z: z.One(),
}
cA := (*C.g2_affine_t)(unsafe.Pointer(&a))
cP := (*C.g2_projective_t)(unsafe.Pointer(&p))
C.bls12_381_g2_from_affine(cA, cP)
return p
}

func G2AffineFromProjective(p *G2Projective) G2Affine {
2 changes: 1 addition & 1 deletion wrappers/golang/curves/bls12381/main.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package bls12381

// #cgo LDFLAGS: -L${SRCDIR}/../../../../build/lib -licicle_field_bls12_381 -licicle_curve_bls12_381 -lstdc++ -Wl,-rpath=${SRCDIR}/../../../../build/lib
// #cgo LDFLAGS: -L${SRCDIR}/../../../../build/lib -libcicle_field_bls12_381 -libcicle_curve_bls12_381 -lstdc++ -Wl,-rpath=${SRCDIR}/../../../../build/lib
import "C"
2 changes: 1 addition & 1 deletion wrappers/golang/curves/bls12381/tests/g2_msm_test.go
Original file line number Diff line number Diff line change
@@ -8,7 +8,7 @@ import (
"github.com/stretchr/testify/assert"

"github.com/consensys/gnark-crypto/ecc"
bls12381 "github.com/consensys/gnark-crypto/ecc/bls12-381"
"github.com/consensys/gnark-crypto/ecc/bls12-381"
"github.com/consensys/gnark-crypto/ecc/bls12-381/fp"
"github.com/consensys/gnark-crypto/ecc/bls12-381/fr"

2 changes: 1 addition & 1 deletion wrappers/golang/curves/bls12381/tests/msm_test.go
Original file line number Diff line number Diff line change
@@ -8,7 +8,7 @@ import (
"github.com/stretchr/testify/assert"

"github.com/consensys/gnark-crypto/ecc"
bls12381 "github.com/consensys/gnark-crypto/ecc/bls12-381"
"github.com/consensys/gnark-crypto/ecc/bls12-381"
"github.com/consensys/gnark-crypto/ecc/bls12-381/fp"
"github.com/consensys/gnark-crypto/ecc/bls12-381/fr"

24 changes: 10 additions & 14 deletions wrappers/golang/curves/bn254/curve.go
Original file line number Diff line number Diff line change
@@ -40,13 +40,10 @@ func (p *Projective) FromLimbs(x, y, z []uint32) Projective {
}

func (p *Projective) FromAffine(a Affine) Projective {
z := BaseField{}
z.One()

p.X = a.X
p.Y = a.Y
p.Z = z

cA := (*C.affine_t)(unsafe.Pointer(&a))
cP := (*C.projective_t)(unsafe.Pointer(p))
C.bn254_from_affine(cA, cP)
return *p
}

@@ -57,11 +54,11 @@ func (p Projective) ProjectiveEq(p2 *Projective) bool {
return __ret == (C._Bool)(true)
}

func (p *Projective) ProjectiveToAffine() Affine {
func (p *Projective) ToAffine() Affine {
var a Affine

cA := (*C.affine_t)(unsafe.Pointer(&a))
cP := (*C.projective_t)(unsafe.Pointer(&p))
cP := (*C.projective_t)(unsafe.Pointer(p))
C.bn254_to_affine(cP, cA)
return a
}
@@ -107,13 +104,12 @@ func (a *Affine) FromLimbs(x, y []uint32) Affine {
}

func (a Affine) ToProjective() Projective {
var z BaseField
var p Projective

return Projective{
X: a.X,
Y: a.Y,
Z: z.One(),
}
cA := (*C.affine_t)(unsafe.Pointer(&a))
cP := (*C.projective_t)(unsafe.Pointer(&p))
C.bn254_from_affine(cA, cP)
return p
}

func AffineFromProjective(p *Projective) Affine {
Loading