44 lines
1.1 KiB
Nim
Raw Normal View History

2023-10-24 13:54:39 +02:00
import
2023-11-07 11:58:15 +01:00
constantine/math/arithmetic,
2023-10-24 13:54:39 +02:00
constantine/math/io/io_fields,
2023-10-26 14:39:27 +02:00
constantine/math/io/io_bigints,
2024-08-08 14:45:13 +02:00
constantine/named/algebras
#-------------------------------------------------------------------------------
type B* = BigInt[254]
2024-08-08 14:45:13 +02:00
type F* = Fr[BN254_Snarks]
type S* = (F,F,F)
#-------------------------------------------------------------------------------
func getZero*() : F =
var z : F
setZero(z)
return z
2023-11-07 14:21:37 +01:00
#-------------------------------------------------------------------------------
const zero* : F = getZero()
const one* : F = fromHex(F,"0x01") # note: `fromUint()` does not work at compile time
const twoToThe64* : F = fromHex(F,"0x10000000000000000")
2023-11-07 14:21:37 +01:00
#-------------------------------------------------------------------------------
2023-10-26 14:39:27 +02:00
func hexToF*(s : string, endian: static Endianness = bigEndian) : F =
let bigint = B.fromHex(s, endian)
return F.fromBig(bigint)
2023-10-26 14:39:27 +02:00
func arrayFromHex*[N](
inp: array[N, string],
endian: static Endianness = bigEndian) : array[N, F] =
var tmp : array[N, F]
for i in low(inp)..high(inp):
2023-10-26 14:39:27 +02:00
tmp[i] = hexToF(inp[i], endian)
return tmp
func `==`*(a, b: F): bool =
bool(arithmetic.`==`(a, b))