Skip to content

Commit

Permalink
feat: added NbG1 and NbG2 apis on groth16 Proving and Verifying keys c…
Browse files Browse the repository at this point in the history
…loses #116
  • Loading branch information
gbotrel committed Aug 18, 2021
1 parent 754cd26 commit e2c0e81
Show file tree
Hide file tree
Showing 7 changed files with 141 additions and 2 deletions.
23 changes: 21 additions & 2 deletions backend/groth16/groth16.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,13 @@ type Proof interface {
// it's underlying implementation is strongly typed with the curve (see gnark/internal/backend)
type ProvingKey interface {
groth16Object

// NbG1 returns the number of G1 elements in the ProvingKey
NbG1() int

// NbG2 returns the number of G2 elements in the ProvingKey
NbG2() int

IsDifferent(interface{}) bool
}

Expand All @@ -75,9 +82,21 @@ type ProvingKey interface {
// ExportSolidity is implemented for BN254 and will return an error with other curves
type VerifyingKey interface {
groth16Object
NbPublicWitness() int // number of elements expected in the public witness
IsDifferent(interface{}) bool

// NbPublicWitness returns number of elements expected in the public witness
NbPublicWitness() int

// NbG1 returns the number of G1 elements in the VerifyingKey
NbG1() int

// NbG2 returns the number of G2 elements in the VerifyingKey
NbG2() int

// ExportSolidity writes a solidity Verifier contract from the VerifyingKey
// this will return an error if not supported on the CurveID()
ExportSolidity(w io.Writer) error

IsDifferent(interface{}) bool
}

// Verify runs the groth16.Verify algorithm on provided proof with given witness
Expand Down
20 changes: 20 additions & 0 deletions internal/backend/bls12-377/groth16/setup.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 20 additions & 0 deletions internal/backend/bls12-381/groth16/setup.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 20 additions & 0 deletions internal/backend/bls24-315/groth16/setup.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 20 additions & 0 deletions internal/backend/bn254/groth16/setup.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 20 additions & 0 deletions internal/backend/bw6-761/groth16/setup.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -420,6 +420,26 @@ func (vk *VerifyingKey) NbPublicWitness() int {
return (len(vk.G1.K) - 1)
}

// NbG1 returns the number of G1 elements in the VerifyingKey
func (vk *VerifyingKey) NbG1() int {
return 3 + len(vk.G1.K)
}

// NbG2 returns the number of G2 elements in the VerifyingKey
func (vk *VerifyingKey) NbG2() int {
return 3
}

// NbG1 returns the number of G1 elements in the ProvingKey
func (pk *ProvingKey) NbG1() int {
return 3 + len(pk.G1.A)+ len(pk.G1.B) + len(pk.G1.Z) + len(pk.G1.K)
}

// NbG2 returns the number of G2 elements in the ProvingKey
func (pk *ProvingKey) NbG2() int {
return 2 + len(pk.G2.B)
}

// bitRerverse permutation as in fft.BitReverse , but with []curve.G1Affine
func bitReverse(a []curve.G1Affine) {
n := uint(len(a))
Expand Down

0 comments on commit e2c0e81

Please sign in to comment.