arnaucube
arnaucube/gnark-plonky2-verifierPublic Self-hosted repository
gnark-plonky2-verifier/field/field.go
field/field.goRaw
 1package field
 2
 3import (
 4	"fmt"
 5	"math/big"
 6
 7	"github.com/consensys/gnark-crypto/ecc"
 8	"github.com/consensys/gnark/frontend"
 9	"github.com/consensys/gnark/std/math/emulated"
10)
11
12type EmulatedField = emulated.Goldilocks
13type F = emulated.Element[EmulatedField]
14type QuadraticExtension = [2]F
15type Hash = [4]F
16
17var TEST_CURVE = ecc.BN254
18
19func NewFieldElement(x uint64) F {
20	return emulated.NewElement[EmulatedField](x)
21}
22
23func NewFieldElementFromString(x string) F {
24	return emulated.NewElement[EmulatedField](x)
25}
26
27func NewFieldAPI(api frontend.API) frontend.API {
28	field, err := emulated.NewField[EmulatedField](api)
29	if err != nil {
30		panic(err)
31	}
32	return field
33}
34
35var r EmulatedField
36
37func EmulatedFieldModulus() *big.Int {
38	return r.Modulus()
39}
40
41func PrintHash(f frontend.API, h Hash) {
42	for i := 0; i < 4; i++ {
43		fmt.Println("Hash Limb", i)
44		f.Println(h[i])
45	}
46}