Skip to content

Commit

Permalink
fix bn254 and bw6761
Browse files Browse the repository at this point in the history
  • Loading branch information
liuxiaobleach committed Jan 29, 2024
1 parent dda3af0 commit 92d6f10
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 8 deletions.
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)
}
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)
}
8 changes: 6 additions & 2 deletions backend/groth16/groth16.go
Original file line number Diff line number Diff line change
Expand Up @@ -372,7 +372,9 @@ 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{}
Expand All @@ -386,7 +388,9 @@ func NewProvingKey(curveID ecc.ID) 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

0 comments on commit 92d6f10

Please sign in to comment.