github.com/consensys/gnark-crypto@v0.14.0/ecc/bn254/internal/fptower/generators_test.go (about) 1 package fptower 2 3 import ( 4 "github.com/consensys/gnark-crypto/ecc/bn254/fp" 5 "github.com/leanovate/gopter" 6 ) 7 8 // GenFp generates an Fp element 9 func GenFp() gopter.Gen { 10 return func(genParams *gopter.GenParameters) *gopter.GenResult { 11 var elmt fp.Element 12 13 if _, err := elmt.SetRandom(); err != nil { 14 panic(err) 15 } 16 genResult := gopter.NewGenResult(elmt, gopter.NoShrinker) 17 return genResult 18 } 19 } 20 21 // GenE2 generates an E2 elmt 22 func GenE2() gopter.Gen { 23 return gopter.CombineGens( 24 GenFp(), 25 GenFp(), 26 ).Map(func(values []interface{}) *E2 { 27 return &E2{A0: values[0].(fp.Element), A1: values[1].(fp.Element)} 28 }) 29 } 30 31 // GenE6 generates an E6 elmt 32 func GenE6() gopter.Gen { 33 return gopter.CombineGens( 34 GenE2(), 35 GenE2(), 36 GenE2(), 37 ).Map(func(values []interface{}) *E6 { 38 return &E6{B0: *values[0].(*E2), B1: *values[1].(*E2), B2: *values[2].(*E2)} 39 }) 40 } 41 42 // GenE12 generates an E6 elmt 43 func GenE12() gopter.Gen { 44 return gopter.CombineGens( 45 GenE6(), 46 GenE6(), 47 ).Map(func(values []interface{}) *E12 { 48 return &E12{C0: *values[0].(*E6), C1: *values[1].(*E6)} 49 }) 50 }