47 lines
1.2 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,
2023-10-24 13:54:39 +02:00
constantine/math/config/curves
#-------------------------------------------------------------------------------
type B* = BigInt[254]
2023-10-24 14:16:54 +02:00
type F* = Fr[BN254Snarks]
type S* = (F,F,F)
#-------------------------------------------------------------------------------
func getZero*() : F =
var z : F
setZero(z)
return z
2023-11-07 14:21:37 +01:00
# Remark: since `fromInt()` does not work at compile time, this doesn't either
2023-10-24 13:55:04 +02:00
func toF*(a: int) : F =
var y : F
2023-11-07 11:58:15 +01:00
y.fromInt(a)
return y
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