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

Add Plonk functions #17

Open
wants to merge 3 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
14 changes: 11 additions & 3 deletions curves/bn254/icicle.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ func NttOnDevice(scalars_out, scalars_d, twiddles_d, coset_powers_d unsafe.Point
}

func MsmOnDevice(scalars_d, points_d unsafe.Pointer, count int, convert bool) (bn254.G1Jac, unsafe.Pointer, error) {
pointBytes := fp.Bytes * 3 // 3 Elements because of 3 coordinates
pointBytes := fp.Bytes * 3 // 3 Elements because of 3 coordinates
out_d, _ := goicicle.CudaMalloc(pointBytes)

icicle.Commit(out_d, scalars_d, points_d, count, 10)
Expand All @@ -51,7 +51,7 @@ func MsmOnDevice(scalars_d, points_d unsafe.Pointer, count int, convert bool) (b
}

func MsmG2OnDevice(scalars_d, points_d unsafe.Pointer, count int, convert bool) (bn254.G2Jac, unsafe.Pointer, error) {
pointBytes := fp.Bytes * 6 // 6 Elements because of 3 coordinates each with real and imaginary elements
pointBytes := fp.Bytes * 6 // 6 Elements because of 3 coordinates each with real and imaginary elements
out_d, _ := goicicle.CudaMalloc(pointBytes)

icicle.CommitG2(out_d, scalars_d, points_d, count, 10)
Expand All @@ -74,7 +74,7 @@ func ReverseScalars(ptr unsafe.Pointer, size int) error {
if success, err := icicle.ReverseScalars(ptr, size); success != 0 {
return err
}

return nil
}

Expand Down Expand Up @@ -103,3 +103,11 @@ func MontConvOnDevice(scalars_d unsafe.Pointer, size int, is_into bool) {
icicle.FromMontgomery(scalars_d, size)
}
}

func VecMulOnDevice(scalars_a, scalars_d unsafe.Pointer, size int) {
ret := icicle.VecScalarMulMod(scalars_a, scalars_d, size)

if ret != 0 {
fmt.Print("Vector mul issue")
}
}
17 changes: 14 additions & 3 deletions curves/bn254/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import (
"github.com/consensys/gnark-crypto/ecc/bn254"
"github.com/consensys/gnark-crypto/ecc/bn254/fp"
"github.com/consensys/gnark-crypto/ecc/bn254/fr"
icicle "github.com/ingonyama-zk/icicle/goicicle/curves/bn254"
goicicle "github.com/ingonyama-zk/icicle/goicicle"
icicle "github.com/ingonyama-zk/icicle/goicicle/curves/bn254"
)

func CopyToDevice(scalars []fr.Element, bytes int, copyDone chan unsafe.Pointer) {
Expand All @@ -26,19 +26,30 @@ func CopyPointsToDevice(points []bn254.G1Affine, pointsBytes int, copyDone chan
devicePtr, _ := goicicle.CudaMalloc(pointsBytes)
iciclePoints := BatchConvertFromG1Affine(points)
goicicle.CudaMemCpyHtoD[icicle.G1PointAffine](devicePtr, iciclePoints, pointsBytes)

copyDone <- devicePtr
}
}

func CopyScalarsToHost(a_device unsafe.Pointer, n int, sizeBytes int) []fr.Element {
outHost := make([]fr.Element, n)

ret := goicicle.CudaMemCpyDtoH[fr.Element](outHost, a_device, sizeBytes)
if ret != 0 {
fmt.Print("Memory copy error")
}

return outHost
}

func CopyG2PointsToDevice(points []bn254.G2Affine, pointsBytes int, copyDone chan unsafe.Pointer) {
if pointsBytes == 0 {
copyDone <- nil
} else {
devicePtr, _ := goicicle.CudaMalloc(pointsBytes)
iciclePoints := BatchConvertFromG2Affine(points)
goicicle.CudaMemCpyHtoD[icicle.G2PointAffine](devicePtr, iciclePoints, pointsBytes)

copyDone <- devicePtr
}
}
Expand Down