2023-07-28 22:10:14 +02:00
|
|
|
|
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
|
2023-07-28 22:10:14 +02:00
|
|
|
|
|
|
|
#-------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
type B* = BigInt[254]
|
2023-10-24 14:16:54 +02:00
|
|
|
type F* = Fr[BN254Snarks]
|
2023-07-28 22:10:14 +02:00
|
|
|
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 =
|
2023-07-28 22:10:14 +02:00
|
|
|
var y : F
|
2023-11-07 11:58:15 +01:00
|
|
|
y.fromInt(a)
|
2023-07-28 22:10:14 +02:00
|
|
|
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
|
|
|
|
|
2023-11-07 14:54:10 +01:00
|
|
|
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-07-28 22:10:14 +02:00
|
|
|
|
2023-10-26 14:39:27 +02:00
|
|
|
func arrayFromHex*[N](
|
|
|
|
inp: array[N, string],
|
|
|
|
endian: static Endianness = bigEndian) : array[N, F] =
|
2023-07-28 22:10:14 +02:00
|
|
|
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)
|
2023-07-28 22:10:14 +02:00
|
|
|
return tmp
|