You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Due to upstream bug nim-lang/Nim#9679 and another hard-to reproduce one for static Word, the use of compile-time property of the modulus requires lots of workarounds.
Bug 2 gives the following errors:
========================================================================================
Running tests/test_io_fields
========================================================================================
/home/beta/Programming/Nim/constantine/tests/test_io_fields.nim(19, 9) template/generic instantiation of `suite` from here
/home/beta/Programming/Nim/constantine/tests/test_io_fields.nim(20, 10) template/generic instantiation of `test` from here
/home/beta/Programming/Nim/constantine/tests/test_io_fields.nim(26, 10) template/generic instantiation of `fromUint` from here
/home/beta/Programming/Nim/constantine/constantine/io/io_fields.nim(29, 6) template/generic instantiation of `fromBig` from here
/home/beta/Programming/Nim/constantine/constantine/arithmetic/finite_fields.nim(64, 11) Error: type mismatch: got <BigInt[61], BigInt[61], BigInt[61], BigInt[61], static[Word](2305843009213693953)>
but expected one of:
func montyResidue(mres: var BigInt; a, N, r2modN: BigInt; negInvModWord: static Word)
first type mismatch at position: 5
required type for negInvModWord: static[Word]
but expression '2305843009213693953' is of type: static[Word](2305843009213693953)
Trying to reduce it to a minimal example makes it disappear ...
import macros
typeWord=distinctuint64constWordBitSize=63funcwordsRequired*(bits: int): int {.compileTime.} =
(bits +WordBitSize-1) divWordBitSizetypeBigInt*[bits: staticint] =object
bitLength: uint32
limbs: array[bits.wordsRequired, Word]
Curve=enumBN254BLS12_381constCurveBitSize= [
BN254: 254,
BLS12_381: 381
]
templatematchingBigInt(C: staticCurve): untyped=# Need template indirection to avoid a sigmatch bugBigInt[CurveBitSize[C]]
typeFiniteField*[C: staticenum] =object
big: matchingBigInt(C)
const BN254_Modulus =BigInt[254]()
const BN254_NegInvModWord =Word(2305843009213693953)
{.experimental: "dynamicBindSym".}
macrogetModulus(C: staticCurve): untyped=result=bindSym($C &"_Modulus")
macrogetNegInvModWord(C: staticCurve): untyped=result=bindSym($C &"_NegInvModWord")
funcfoo(mres: varBigInt, a, N: BigInt, negInvModWord: staticWord) =discardfuncbar(r: varFiniteField, a: FiniteField) =foo(r.big, a.big, a.C.getModulus(), a.C.getNegInvModWord())
var r: FiniteField[BN254]
let a =FiniteField[BN254]()
bar(r, a)
The text was updated successfully, but these errors were encountered:
Due to upstream bug nim-lang/Nim#9679 and another hard-to reproduce one for static Word, the use of compile-time property of the modulus requires lots of workarounds.
Bug 2 gives the following errors:
Trying to reduce it to a minimal example makes it disappear ...
The text was updated successfully, but these errors were encountered: