Prepare for testing finite fields, comment cleanups
This commit is contained in:
parent
edd728610c
commit
9db77ad0eb
|
@ -6,16 +6,17 @@ license = "MIT or Apache License 2.0"
|
|||
srcDir = "src"
|
||||
|
||||
### Dependencies
|
||||
requires "nim >= 0.18.0"
|
||||
requires "nim >= 1.0.6"
|
||||
|
||||
### Helper functions
|
||||
proc test(name: string, defaultLang = "c") =
|
||||
proc test(fakeCurves: string, path: string, lang = "c") =
|
||||
if not dirExists "build":
|
||||
mkDir "build"
|
||||
--run
|
||||
switch("out", ("./build/" & name))
|
||||
setCommand defaultLang, "tests/" & name & ".nim"
|
||||
exec "nim " & lang & fakeCurves & " --outdir:build -r --hints:off --warnings:off " & path
|
||||
|
||||
### tasks
|
||||
task test, "Run all tests":
|
||||
test "all_tests"
|
||||
test "", "tests/test_word_types.nim"
|
||||
test "", "tests/test_io.nim"
|
||||
test "", "tests/test_bigints.nim"
|
||||
test "-d:testingCurves", "tests/test_field_fp.nim"
|
||||
|
|
|
@ -36,7 +36,6 @@
|
|||
# We internally order the limbs in little-endian
|
||||
# So the least significant limb is limb[0]
|
||||
# This is independent from the base type endianness.
|
||||
# TODO: hexdumps
|
||||
|
||||
import ./word_types
|
||||
|
||||
|
@ -49,6 +48,16 @@ const WordBitSize* = sizeof(Word) * 8 - 1
|
|||
func wordsRequired(bits: int): int {.compileTime.}=
|
||||
(bits + WordBitSize - 1) div WordBitSize
|
||||
|
||||
# TODO: Currently the library is instantiation primitives like "add"
|
||||
# for each "bits" size supported. This will lead to duplication
|
||||
# if many sizes (for example for scp256k1, bn254 and BLS12-381)
|
||||
# are required.
|
||||
# It could be avoided by having the bitsize be a runtime field
|
||||
# of the bigint. However the tradeoff would be:
|
||||
# - overhead of this additional field
|
||||
# - limbs have to be stored in an UncheckedArray instead of an array
|
||||
# introducing memory management issues
|
||||
|
||||
type
|
||||
BigInt*[bits: static int] = object
|
||||
## Fixed-precision big integer
|
||||
|
|
|
@ -35,11 +35,18 @@ import
|
|||
# - proc MontyMagic(curve: static Curve): static Word =
|
||||
# which returns the Montgomery magic constant
|
||||
# associated with the curve modulus
|
||||
declareCurves:
|
||||
# Barreto-Naehrig curve, Prime 254 bit, 128-bit security, https://eprint.iacr.org/2013/879.pdf
|
||||
# Usage: Zero-Knowledge Proofs / zkSNARKs in ZCash and Ethereum 1
|
||||
# https://eips.ethereum.org/EIPS/eip-196
|
||||
curve BN254:
|
||||
bitsize: 254
|
||||
modulus: "0x30644e72e131a029b85045b68181585d97816a916871ca8d3c208c16d87cfd47"
|
||||
# Equation: Y^2 = X^3 + 3
|
||||
when not defined(testingCurves):
|
||||
declareCurves:
|
||||
# Barreto-Naehrig curve, Prime 254 bit, 128-bit security, https://eprint.iacr.org/2013/879.pdf
|
||||
# Usage: Zero-Knowledge Proofs / zkSNARKs in ZCash and Ethereum 1
|
||||
# https://eips.ethereum.org/EIPS/eip-196
|
||||
curve BN254:
|
||||
bitsize: 254
|
||||
modulus: "0x30644e72e131a029b85045b68181585d97816a916871ca8d3c208c16d87cfd47"
|
||||
# Equation: Y^2 = X^3 + 3
|
||||
else:
|
||||
# Fake curve for testing field arithmetic
|
||||
declareCurves:
|
||||
curve Fake101:
|
||||
bitsize: 101
|
||||
modulus: "0x65" # 101 in hex
|
||||
|
|
|
@ -17,8 +17,6 @@
|
|||
import ./word_types, ./bigints, ./curves_config
|
||||
from ./private/word_types_internal import unsafe_div2n1n
|
||||
|
||||
static: echo CurveBitSize
|
||||
|
||||
type
|
||||
Fp*[C: static Curve] = object
|
||||
## P is the prime modulus of the Curve C
|
||||
|
|
|
@ -6,7 +6,5 @@
|
|||
# * Apache v2 license (license terms in the root directory or at http://www.apache.org/licenses/LICENSE-2.0).
|
||||
# at your option. This file may not be copied, modified, or distributed except according to those terms.
|
||||
|
||||
import
|
||||
test_word_types,
|
||||
test_io,
|
||||
test_bigints
|
||||
import unittest, random,
|
||||
../constantine/[io, bigints, word_types, field_fp]
|
Loading…
Reference in New Issue