mirror of
https://github.com/logos-storage/gnark-plonky2-verifier.git
synced 2026-01-08 16:13:08 +00:00
* removed unused file * change field import * change import of field package * changed field import * moved hash to poseidon and some changes to the field package * changed file structure
68 lines
1.7 KiB
Go
68 lines
1.7 KiB
Go
package field
|
|
|
|
import (
|
|
"github.com/consensys/gnark-crypto/ecc"
|
|
"github.com/consensys/gnark-crypto/field/goldilocks"
|
|
"github.com/consensys/gnark/frontend"
|
|
"github.com/consensys/gnark/std/math/emulated"
|
|
)
|
|
|
|
type EmulatedField = emulated.Goldilocks
|
|
type F = emulated.Element[EmulatedField]
|
|
|
|
var TEST_CURVE = ecc.BN254
|
|
|
|
func NewFieldElement(x uint64) F {
|
|
return emulated.NewElement[EmulatedField](x)
|
|
}
|
|
|
|
func NewFieldElementFromString(x string) F {
|
|
return emulated.NewElement[EmulatedField](x)
|
|
}
|
|
|
|
func NewFieldAPI(api frontend.API) frontend.API {
|
|
field, err := emulated.NewField[EmulatedField](api)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
return field
|
|
}
|
|
|
|
var ONE_F = NewFieldElement(1)
|
|
var ZERO_F = NewFieldElement(0)
|
|
var NEG_ONE_F = NewFieldElement(EmulatedField{}.Modulus().Uint64() - 1)
|
|
|
|
var GOLDILOCKS_MULTIPLICATIVE_GROUP_GENERATOR = goldilocks.NewElement(7)
|
|
var GOLDILOCKS_TWO_ADICITY = uint64(32)
|
|
var GOLDILOCKS_POWER_OF_TWO_GENERATOR = goldilocks.NewElement(1753635133440165772)
|
|
|
|
func GoldilocksPrimitiveRootOfUnity(nLog uint64) goldilocks.Element {
|
|
if nLog > GOLDILOCKS_TWO_ADICITY {
|
|
panic("nLog is greater than GOLDILOCKS_TWO_ADICITY")
|
|
}
|
|
|
|
res := goldilocks.NewElement(GOLDILOCKS_POWER_OF_TWO_GENERATOR.Uint64())
|
|
for i := 0; i < int(GOLDILOCKS_TWO_ADICITY-nLog); i++ {
|
|
res.Square(&res)
|
|
}
|
|
|
|
return res
|
|
}
|
|
|
|
func TwoAdicSubgroup(nLog uint64) []goldilocks.Element {
|
|
if nLog > GOLDILOCKS_TWO_ADICITY {
|
|
panic("nLog is greater than GOLDILOCKS_TWO_ADICITY")
|
|
}
|
|
|
|
var res []goldilocks.Element
|
|
rootOfUnity := GoldilocksPrimitiveRootOfUnity(nLog)
|
|
res = append(res, goldilocks.NewElement(1))
|
|
|
|
for i := 0; i < (1 << nLog); i++ {
|
|
lastElement := res[len(res)-1]
|
|
res = append(res, *lastElement.Mul(&lastElement, &rootOfUnity))
|
|
}
|
|
|
|
return res
|
|
}
|