Skip to content

Commit

Permalink
test: add scalar mul to stats
Browse files Browse the repository at this point in the history
  • Loading branch information
yelhousni committed Sep 10, 2024
1 parent e8cb61d commit d48cced
Show file tree
Hide file tree
Showing 2 changed files with 91 additions and 0 deletions.
Binary file modified internal/stats/latest.stats
Binary file not shown.
91 changes: 91 additions & 0 deletions internal/stats/snippet.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"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/emulated/sw_emulated"
"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 @@ -214,6 +215,96 @@ func initSnippets() {

}, ecc.BN254)

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

cr, err := sw_emulated.New[emulated.BN254Fp, emulated.BN254Fr](api, sw_emulated.GetCurveParams[emulated.BN254Fp]())
if err != nil {
panic(err)
}
bn_fr, _ := emulated.NewField[emulated.BN254Fr](api)
newFr := func() *emulated.Element[emulated.BN254Fr] {
limbs := make([]frontend.Variable, emulated.BN254Fr{}.NbLimbs())
for i := 0; i < len(limbs); i++ {
limbs[i] = newVariable()
}
return bn_fr.NewElement(limbs)
}
bn_fp, _ := emulated.NewField[emulated.BN254Fp](api)
newFp := func() *emulated.Element[emulated.BN254Fp] {
limbs := make([]frontend.Variable, emulated.BN254Fp{}.NbLimbs())
for i := 0; i < len(limbs); i++ {
limbs[i] = newVariable()
}
return bn_fp.NewElement(limbs)
}
dummyG1 := sw_emulated.AffinePoint[emulated.BN254Fp]{*newFp(), *newFp()}

Check failure on line 240 in internal/stats/snippet.go

View workflow job for this annotation

GitHub Actions / staticcheck

composites: github.com/consensys/gnark/std/algebra/emulated/sw_emulated.AffinePoint[github.com/consensys/gnark/std/math/emulated/emparams.BN254Fp] struct literal uses unkeyed fields (govet)
_ = cr.ScalarMul(
(&dummyG1),
newFr(),
)

}, ecc.BN254)

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

cr, err := sw_emulated.New[emulated.Secp256k1Fp, emulated.Secp256k1Fr](api, sw_emulated.GetCurveParams[emulated.Secp256k1Fp]())
if err != nil {
panic(err)
}
bn_fr, _ := emulated.NewField[emulated.Secp256k1Fr](api)
newFr := func() *emulated.Element[emulated.Secp256k1Fr] {
limbs := make([]frontend.Variable, emulated.Secp256k1Fr{}.NbLimbs())
for i := 0; i < len(limbs); i++ {
limbs[i] = newVariable()
}
return bn_fr.NewElement(limbs)
}
bn_fp, _ := emulated.NewField[emulated.Secp256k1Fp](api)
newFp := func() *emulated.Element[emulated.Secp256k1Fp] {
limbs := make([]frontend.Variable, emulated.Secp256k1Fp{}.NbLimbs())
for i := 0; i < len(limbs); i++ {
limbs[i] = newVariable()
}
return bn_fp.NewElement(limbs)
}
dummyG1 := sw_emulated.AffinePoint[emulated.Secp256k1Fp]{*newFp(), *newFp()}

Check failure on line 270 in internal/stats/snippet.go

View workflow job for this annotation

GitHub Actions / staticcheck

composites: github.com/consensys/gnark/std/algebra/emulated/sw_emulated.AffinePoint[github.com/consensys/gnark/std/math/emulated/emparams.Secp256k1Fp] struct literal uses unkeyed fields (govet)
_ = cr.ScalarMul(
(&dummyG1),
newFr(),
)

}, ecc.BN254)

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

cr, err := sw_emulated.New[emulated.P256Fp, emulated.P256Fr](api, sw_emulated.GetCurveParams[emulated.P256Fp]())
if err != nil {
panic(err)
}
bn_fr, _ := emulated.NewField[emulated.P256Fr](api)
newFr := func() *emulated.Element[emulated.P256Fr] {
limbs := make([]frontend.Variable, emulated.P256Fr{}.NbLimbs())
for i := 0; i < len(limbs); i++ {
limbs[i] = newVariable()
}
return bn_fr.NewElement(limbs)
}
bn_fp, _ := emulated.NewField[emulated.P256Fp](api)
newFp := func() *emulated.Element[emulated.P256Fp] {
limbs := make([]frontend.Variable, emulated.P256Fp{}.NbLimbs())
for i := 0; i < len(limbs); i++ {
limbs[i] = newVariable()
}
return bn_fp.NewElement(limbs)
}
dummyG1 := sw_emulated.AffinePoint[emulated.P256Fp]{*newFp(), *newFp()}

Check failure on line 300 in internal/stats/snippet.go

View workflow job for this annotation

GitHub Actions / staticcheck

composites: github.com/consensys/gnark/std/algebra/emulated/sw_emulated.AffinePoint[github.com/consensys/gnark/std/math/emulated/emparams.P256Fp] struct literal uses unkeyed fields (govet)
_ = cr.ScalarMul(
(&dummyG1),
newFr(),
)

}, ecc.BN254)

}

type snippetCircuit struct {
Expand Down

0 comments on commit d48cced

Please sign in to comment.