Skip to content

Commit

Permalink
test: add emulated pairing circuits to stats (Consensys#1031)
Browse files Browse the repository at this point in the history
  • Loading branch information
yelhousni authored Feb 2, 2024
1 parent 351bf54 commit ac3580b
Show file tree
Hide file tree
Showing 2 changed files with 82 additions and 2 deletions.
Binary file modified internal/stats/latest.stats
Binary file not shown.
84 changes: 82 additions & 2 deletions internal/stats/snippet.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ import (
"github.com/consensys/gnark"
"github.com/consensys/gnark-crypto/ecc"
"github.com/consensys/gnark/frontend"
"github.com/consensys/gnark/std/algebra/emulated/sw_bls12381"
"github.com/consensys/gnark/std/algebra/emulated/sw_bn254"
"github.com/consensys/gnark/std/algebra/emulated/sw_bw6761"
"github.com/consensys/gnark/std/algebra/native/sw_bls12377"
"github.com/consensys/gnark/std/algebra/native/sw_bls24315"
"github.com/consensys/gnark/std/hash/mimc"
Expand Down Expand Up @@ -115,7 +118,6 @@ func initSnippets() {
dummyG2.P.Y.A0 = newVariable()
dummyG2.P.Y.A1 = newVariable()

// e(psi0, -gamma)*e(-πC, -δ)*e(πA, πB)
_, _ = sw_bls12377.Pair(api, []sw_bls12377.G1Affine{dummyG1}, []sw_bls12377.G2Affine{dummyG2})

}, ecc.BW6_761)
Expand All @@ -135,11 +137,89 @@ func initSnippets() {
dummyG2.P.Y.B1.A0 = newVariable()
dummyG2.P.Y.B1.A1 = newVariable()

// e(psi0, -gamma)*e(-πC, -δ)*e(πA, πB)
_, _ = sw_bls24315.Pair(api, []sw_bls24315.G1Affine{dummyG1}, []sw_bls24315.G2Affine{dummyG2})

}, ecc.BW6_633)

registerSnippet("pairing_bls12381", func(api frontend.API, newVariable func() frontend.Variable) {

bls12381, _ := emulated.NewField[emulated.BLS12381Fp](api)
newElement := func() *emulated.Element[emulated.BLS12381Fp] {
limbs := make([]frontend.Variable, emulated.BLS12381Fp{}.NbLimbs())
for i := 0; i < len(limbs); i++ {
limbs[i] = newVariable()
}
return bls12381.NewElement(limbs)
}
var dummyG1 sw_bls12381.G1Affine
var dummyG2 sw_bls12381.G2Affine
dummyG1.X = *newElement()
dummyG1.Y = *newElement()
dummyG2.P.X.A0 = *newElement()
dummyG2.P.X.A1 = *newElement()
dummyG2.P.Y.A0 = *newElement()
dummyG2.P.Y.A1 = *newElement()

pr, err := sw_bls12381.NewPairing(api)
if err != nil {
panic(err)
}
_, _ = pr.Pair([]*sw_bls12381.G1Affine{&dummyG1}, []*sw_bls12381.G2Affine{&dummyG2})

}, ecc.BN254)

registerSnippet("pairing_bn254", func(api frontend.API, newVariable func() frontend.Variable) {

bn254, _ := emulated.NewField[emulated.BN254Fp](api)
newElement := func() *emulated.Element[emulated.BN254Fp] {
limbs := make([]frontend.Variable, emulated.BN254Fp{}.NbLimbs())
for i := 0; i < len(limbs); i++ {
limbs[i] = newVariable()
}
return bn254.NewElement(limbs)
}
var dummyG1 sw_bn254.G1Affine
var dummyG2 sw_bn254.G2Affine
dummyG1.X = *newElement()
dummyG1.Y = *newElement()
dummyG2.P.X.A0 = *newElement()
dummyG2.P.X.A1 = *newElement()
dummyG2.P.Y.A0 = *newElement()
dummyG2.P.Y.A1 = *newElement()

pr, err := sw_bn254.NewPairing(api)
if err != nil {
panic(err)
}
_, _ = pr.Pair([]*sw_bn254.G1Affine{&dummyG1}, []*sw_bn254.G2Affine{&dummyG2})

}, ecc.BN254)

registerSnippet("pairing_bw6761", func(api frontend.API, newVariable func() frontend.Variable) {

bw6761, _ := emulated.NewField[emulated.BW6761Fp](api)
newElement := func() *emulated.Element[emulated.BW6761Fp] {
limbs := make([]frontend.Variable, emulated.BW6761Fp{}.NbLimbs())
for i := 0; i < len(limbs); i++ {
limbs[i] = newVariable()
}
return bw6761.NewElement(limbs)
}
var dummyG1 sw_bw6761.G1Affine
var dummyG2 sw_bw6761.G2Affine
dummyG1.X = *newElement()
dummyG1.Y = *newElement()
dummyG2.P.X = *newElement()
dummyG2.P.Y = *newElement()

pr, err := sw_bw6761.NewPairing(api)
if err != nil {
panic(err)
}
_, _ = pr.Pair([]*sw_bw6761.G1Affine{&dummyG1}, []*sw_bw6761.G2Affine{&dummyG2})

}, ecc.BN254)

}

type snippetCircuit struct {
Expand Down

0 comments on commit ac3580b

Please sign in to comment.