Closed syntrust closed 1 year ago
Hi, you have to be a bit more specific -- what version are you using? Which target did you compile for? Is it for a gnark-crypto generated modulus or another one?
Thank you for your quick response. I am trying to create a prime field for bn254 with version v0.10.0:
package main
import (
"log"
"github.com/consensys/gnark-crypto/field/generator"
"github.com/consensys/gnark-crypto/field/generator/config"
)
func main() {
cfg, err := config.NewFieldConfig("fp", "Element", "21888242871839275222246405745257275088548364400416034343698204186575808495617", false)
if err != nil {
log.Fatal(err)
}
generator.GenerateFF(cfg, "../fp")
}
It seems the generated Element
type missing some methods which are referenced inside the package, e.g. Mul()
. This is the full list of methods:
type Element [4]uint64
func (*Element).Add(x *Element, y *Element) *Element
func (*Element).BigInt(res *big.Int) *big.Int
func (*Element).BitLen() int
func (*Element).Bits() [4]uint64
func (*Element).Bytes() (res [32]byte)
func (*Element).Cmp(x *Element) int
func (*Element).Div(x *Element, y *Element) *Element
func (*Element).Double(x *Element) *Element
func (*Element).Equal(x *Element) bool
func (*Element).Exp(x Element, k *big.Int) *Element
func (*Element).FitsOnOneWord() bool
func (*Element).Halve()
func (*Element).Inverse(x *Element) *Element
func (*Element).IsOne() bool
func (*Element).IsUint64() bool
func (*Element).IsZero() bool
func (*Element).Legendre() int
func (*Element).LexicographicallyLargest() bool
func (*Element).Marshal() []byte
func (*Element).MarshalJSON() ([]byte, error)
func (*Element).Neg(x *Element) *Element
func (*Element).NotEqual(x *Element) uint64
func (*Element).Select(c int, x0 *Element, x1 *Element) *Element
func (*Element).Set(x *Element) *Element
func (*Element).SetBigInt(v *big.Int) *Element
func (*Element).SetBytes(e []byte) *Element
func (*Element).SetBytesCanonical(e []byte) error
func (*Element).SetInt64(v int64) *Element
func (*Element).SetInterface(i1 interface{}) (*Element, error)
func (*Element).SetOne() *Element
func (*Element).SetRandom() (*Element, error)
func (*Element).SetString(number string) (*Element, error)
func (*Element).SetUint64(v uint64) *Element
func (*Element).SetZero() *Element
func (*Element).Sqrt(x *Element) *Element
func (*Element).String() string
func (*Element).Sub(x *Element, y *Element) *Element
func (*Element).Text(base int) string
func (Element).ToBigIntRegular(res *big.Int) *big.Int
func (*Element).Uint64() uint64
func (*Element).UnmarshalJSON(data []byte) error
func (*Element).expByLegendreExp(x Element) *Element
func (*Element).expBySqrtExp(x Element) *Element
func (*Element).fromMont() *Element
func (*Element).inverseExp(x Element) *Element
func (*Element).linearComb(x *Element, xC int64, y *Element, yC int64)
func (*Element).linearCombNonModular(x *Element, xC int64, y *Element, yC int64) uint64
func (*Element).montReduceSigned(x *Element, xHi uint64)
func (*Element).mulWNonModular(x *Element, y int64) uint64
func (*Element).setBigInt(v *big.Int) *Element
func (*Element).smallerThanModulus() bool
func (*Element).toBigInt(res *big.Int) *big.Int
func (*Element).toMont() *Element
Element represents a field element stored on 4 words (uint64)
Element are assumed to be in Montgomery form in all methods.
Modulus q =
q[base10] = 21888242871839275222246405745257275088548364400416034343698204186575808495617
q[base16] = 0x30644e72e131a029b85045b68181585d2833e84879b9709143e1f593f0000001
Warning
This code has not been audited and is provided as-is. In particular, there is no security guarantees such as constant time implementation or side-channel attack resistance.
[fp.Element on pkg.go.dev](vscode-file://vscode-app/c:/Users/ldeng/AppData/Local/Programs/Microsoft%20VS%20Code/resources/app/out/vs/code/electron-sandbox/workbench/workbench.html)
-- can't reproduce that one, Mul is correctly generated (see element_ops_purego.go
and element_ops_amd64.go
)
It's ok as there is a workaround anyway.
..\fp\element.go:99:4: z.Mul undefined (type Element has no field or method Mul) ..\fp\element.go:107:11: z.Mul undefined (type Element has no field or method Mul) ..\fp\element.go:217:4: z.Mul undefined (type Element has no field or method Mul) ..\fp\element.go:397:2: undefined: fromMont ..\fp\element.go:722:15: accumulator.Mul undefined (type Element has no field or method Mul) ..\fp\element.go:731:10: res[i].Mul undefined (type Element has no field or method Mul) ..\fp\element.go:732:15: accumulator.Mul undefined (type Element has no field or method Mul) ..\fp\element.go:819:5: z.Square undefined (type Element has no field or method Square) ..\fp\element.go:821:6: z.Mul undefined (type Element has no field or method Mul) ..\fp\element.go:843:11: z.Mul undefined (type *Element has no field or method Mul) ..\fp\element.go:843:11: too many errors