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 icicle read write #11

Merged
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
2 changes: 1 addition & 1 deletion backend/groth16/bls12-377/icicle/icicle.go
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ func Prove(r1cs *cs.R1CS, pk *ProvingKey, fullWitness witness.Witness, opts ...b
opt.HashToFieldFn = hash_to_field.New([]byte(constraint.CommitmentDst))
}
if opt.Accelerator != "icicle" {
return groth16_bls12377.Prove(r1cs, &pk.ProvingKey, fullWitness, opts...)
return groth16_bls12377.Prove(r1cs, pk.ProvingKey, fullWitness, opts...)
}

log := logger.Logger().With().Str("curve", r1cs.CurveID().String()).Str("acceleration", "icicle").Int("nbConstraints", r1cs.GetNbConstraints()).Str("backend", "groth16").Logger()
Expand Down
20 changes: 17 additions & 3 deletions backend/groth16/bls12-377/icicle/provingkey.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package icicle_bls12377

import (
"io"
"unsafe"

groth16_bls12377 "github.com/consensys/gnark/backend/groth16/bls12-377"
Expand All @@ -23,14 +24,27 @@ type deviceInfo struct {
}

type ProvingKey struct {
groth16_bls12377.ProvingKey
*groth16_bls12377.ProvingKey
*deviceInfo
}

// WriteTo writes binary encoding of the key elements to writer
// points are compressed
// use WriteRawTo(...) to encode the key without point compression
func (pk *ProvingKey) WriteTo(w io.Writer) (n int64, err error) {
return pk.ProvingKey.WriteTo(w)
}

// UnsafeReadFrom behaves like ReadFrom excepts it doesn't check if the decoded points are on the curve
// or in the correct subgroup
func (pk *ProvingKey) UnsafeReadFrom(r io.Reader) (int64, error) {
return pk.ProvingKey.UnsafeReadFrom(r)
}

func Setup(r1cs *cs.R1CS, pk *ProvingKey, vk *groth16_bls12377.VerifyingKey) error {
return groth16_bls12377.Setup(r1cs, &pk.ProvingKey, vk)
return groth16_bls12377.Setup(r1cs, pk.ProvingKey, vk)
}

func DummySetup(r1cs *cs.R1CS, pk *ProvingKey) error {
return groth16_bls12377.DummySetup(r1cs, &pk.ProvingKey)
return groth16_bls12377.DummySetup(r1cs, pk.ProvingKey)
}
2 changes: 1 addition & 1 deletion backend/groth16/bn254/icicle/icicle.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ func Prove(r1cs *cs.R1CS, pk *ProvingKey, fullWitness witness.Witness, opts ...b
opt.HashToFieldFn = hash_to_field.New([]byte(constraint.CommitmentDst))
}
if opt.Accelerator != "icicle" {
return groth16_bn254.Prove(r1cs, &pk.ProvingKey, fullWitness, opts...)
return groth16_bn254.Prove(r1cs, pk.ProvingKey, fullWitness, opts...)
}
log := logger.Logger().With().Str("curve", r1cs.CurveID().String()).Str("acceleration", "icicle").Int("nbConstraints", r1cs.GetNbConstraints()).Str("backend", "groth16").Logger()
if pk.deviceInfo == nil {
Expand Down
20 changes: 17 additions & 3 deletions backend/groth16/bn254/icicle/provingkey.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package icicle_bn254

import (
"io"
"unsafe"

groth16_bn254 "github.com/consensys/gnark/backend/groth16/bn254"
Expand All @@ -23,14 +24,27 @@ type deviceInfo struct {
}

type ProvingKey struct {
groth16_bn254.ProvingKey
*groth16_bn254.ProvingKey
*deviceInfo
}

// WriteTo writes binary encoding of the key elements to writer
// points are compressed
// use WriteRawTo(...) to encode the key without point compression
func (pk *ProvingKey) WriteTo(w io.Writer) (n int64, err error) {
return pk.ProvingKey.WriteTo(w)
}

// UnsafeReadFrom behaves like ReadFrom excepts it doesn't check if the decoded points are on the curve
// or in the correct subgroup
func (pk *ProvingKey) UnsafeReadFrom(r io.Reader) (int64, error) {
return pk.ProvingKey.UnsafeReadFrom(r)
}

func Setup(r1cs *cs.R1CS, pk *ProvingKey, vk *groth16_bn254.VerifyingKey) error {
return groth16_bn254.Setup(r1cs, &pk.ProvingKey, vk)
return groth16_bn254.Setup(r1cs, pk.ProvingKey, vk)
}

func DummySetup(r1cs *cs.R1CS, pk *ProvingKey) error {
return groth16_bn254.DummySetup(r1cs, &pk.ProvingKey)
return groth16_bn254.DummySetup(r1cs, pk.ProvingKey)
}
2 changes: 1 addition & 1 deletion backend/groth16/bw6-761/icicle/icicle.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ func Prove(r1cs *cs.R1CS, pk *ProvingKey, fullWitness witness.Witness, opts ...b
opt.HashToFieldFn = hash_to_field.New([]byte(constraint.CommitmentDst))
}
if opt.Accelerator != "icicle" {
return groth16_bw6761.Prove(r1cs, &pk.ProvingKey, fullWitness, opts...)
return groth16_bw6761.Prove(r1cs, pk.ProvingKey, fullWitness, opts...)
}
log := logger.Logger().With().Str("curve", r1cs.CurveID().String()).Str("acceleration", "icicle").Int("nbConstraints", r1cs.GetNbConstraints()).Str("backend", "groth16").Logger()
if pk.deviceInfo == nil {
Expand Down
20 changes: 17 additions & 3 deletions backend/groth16/bw6-761/icicle/provingkey.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package icicle_bw6761

import (
"io"
"unsafe"

groth16_bw6761 "github.com/consensys/gnark/backend/groth16/bw6-761"
Expand All @@ -23,14 +24,27 @@ type deviceInfo struct {
}

type ProvingKey struct {
groth16_bw6761.ProvingKey
*groth16_bw6761.ProvingKey
*deviceInfo
}

// WriteTo writes binary encoding of the key elements to writer
// points are compressed
// use WriteRawTo(...) to encode the key without point compression
func (pk *ProvingKey) WriteTo(w io.Writer) (n int64, err error) {
return pk.ProvingKey.WriteTo(w)
}

// UnsafeReadFrom behaves like ReadFrom excepts it doesn't check if the decoded points are on the curve
// or in the correct subgroup
func (pk *ProvingKey) UnsafeReadFrom(r io.Reader) (int64, error) {
return pk.ProvingKey.UnsafeReadFrom(r)
}

func Setup(r1cs *cs.R1CS, pk *ProvingKey, vk *groth16_bw6761.VerifyingKey) error {
return groth16_bw6761.Setup(r1cs, &pk.ProvingKey, vk)
return groth16_bw6761.Setup(r1cs, pk.ProvingKey, vk)
}

func DummySetup(r1cs *cs.R1CS, pk *ProvingKey) error {
return groth16_bw6761.DummySetup(r1cs, &pk.ProvingKey)
return groth16_bw6761.DummySetup(r1cs, pk.ProvingKey)
}
12 changes: 9 additions & 3 deletions backend/groth16/groth16.go
Original file line number Diff line number Diff line change
Expand Up @@ -372,19 +372,25 @@ func NewProvingKey(curveID ecc.ID) ProvingKey {
case ecc.BN254:
pk = &groth16_bn254.ProvingKey{}
if icicle_bn254.HasIcicle {
pk = &icicle_bn254.ProvingKey{}
pk = &icicle_bn254.ProvingKey{
ProvingKey: &groth16_bn254.ProvingKey{},
}
}
case ecc.BLS12_377:
pk = &groth16_bls12377.ProvingKey{}
if icicle_bls12377.HasIcicle {
pk = &icicle_bls12377.ProvingKey{}
pk = &icicle_bls12377.ProvingKey{
ProvingKey: &groth16_bls12377.ProvingKey{},
}
}
case ecc.BLS12_381:
pk = &groth16_bls12381.ProvingKey{}
case ecc.BW6_761:
pk = &groth16_bw6761.ProvingKey{}
if icicle_bw6761.HasIcicle {
pk = &icicle_bw6761.ProvingKey{}
pk = &icicle_bw6761.ProvingKey{
ProvingKey: &groth16_bw6761.ProvingKey{},
}
}
case ecc.BLS24_317:
pk = &groth16_bls24317.ProvingKey{}
Expand Down
5 changes: 1 addition & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,8 @@ github.com/icza/bitio v1.1.0 h1:ysX4vtldjdi3Ygai5m1cWy4oLkhWTAi+SyO6HC8L9T0=
github.com/icza/bitio v1.1.0/go.mod h1:0jGnlLAx8MKMr9VGnn/4YrvZiprkvBelsVIbA9Jjr9A=
github.com/icza/mighty v0.0.0-20180919140131-cfd07d671de6 h1:8UsGZ2rr2ksmEru6lToqnXgA8Mz1DP11X4zSJ159C3k=
github.com/icza/mighty v0.0.0-20180919140131-cfd07d671de6/go.mod h1:xQig96I1VNBDIWGCdTt54nHt6EeI639SmHycLYL7FkA=
github.com/ingonyama-zk/icicle v0.1.0 h1:9zbHaYv8/4g3HWRabBCpeH+64U8GJ99K1qeqE2jO6LM=
github.com/ingonyama-zk/icicle v0.1.0/go.mod h1:kAK8/EoN7fUEmakzgZIYdWy1a2rBnpCaZLqSHwZWxEk=
github.com/ingonyama-zk/icicle v0.1.1-0.20240120093837-db9eff751859 h1:zUNn7pKri9mM6+2fMEoGbt822QWh4xzVB65L2peHW1w=
github.com/ingonyama-zk/icicle v0.1.1-0.20240120093837-db9eff751859/go.mod h1:kAK8/EoN7fUEmakzgZIYdWy1a2rBnpCaZLqSHwZWxEk=
github.com/ingonyama-zk/iciclegnark v0.1.1 h1:BugVGAkKFu2uy02cRsgQdsE18VaFIJz55dBeZQJl4R0=
github.com/ingonyama-zk/iciclegnark v0.1.1/go.mod h1:g17CDuMfNBiN4hhZ4aA0rGF24Abv5GBFHJqE7aLxaZQ=
github.com/ingonyama-zk/iciclegnark v0.1.2-0.20240120100015-8653136f9db4 h1:G6rREPYobR/WTuXcypQAedckBhdh6XlDtDs3rZC/K5I=
github.com/ingonyama-zk/iciclegnark v0.1.2-0.20240120100015-8653136f9db4/go.mod h1:L4ipdq3/9xeOW3t6RGEpy5n1h88jJsvtuTopHd9x4dQ=
github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE=
Expand Down
Loading