mirror of
https://github.com/status-im/constantine.git
synced 2025-02-23 17:38:09 +00:00
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"
|
srcDir = "src"
|
||||||
|
|
||||||
### Dependencies
|
### Dependencies
|
||||||
requires "nim >= 0.18.0"
|
requires "nim >= 1.0.6"
|
||||||
|
|
||||||
### Helper functions
|
### Helper functions
|
||||||
proc test(name: string, defaultLang = "c") =
|
proc test(fakeCurves: string, path: string, lang = "c") =
|
||||||
if not dirExists "build":
|
if not dirExists "build":
|
||||||
mkDir "build"
|
mkDir "build"
|
||||||
--run
|
exec "nim " & lang & fakeCurves & " --outdir:build -r --hints:off --warnings:off " & path
|
||||||
switch("out", ("./build/" & name))
|
|
||||||
setCommand defaultLang, "tests/" & name & ".nim"
|
|
||||||
|
|
||||||
### tasks
|
### tasks
|
||||||
task test, "Run all tests":
|
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
|
# We internally order the limbs in little-endian
|
||||||
# So the least significant limb is limb[0]
|
# So the least significant limb is limb[0]
|
||||||
# This is independent from the base type endianness.
|
# This is independent from the base type endianness.
|
||||||
# TODO: hexdumps
|
|
||||||
|
|
||||||
import ./word_types
|
import ./word_types
|
||||||
|
|
||||||
@ -49,6 +48,16 @@ const WordBitSize* = sizeof(Word) * 8 - 1
|
|||||||
func wordsRequired(bits: int): int {.compileTime.}=
|
func wordsRequired(bits: int): int {.compileTime.}=
|
||||||
(bits + WordBitSize - 1) div WordBitSize
|
(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
|
type
|
||||||
BigInt*[bits: static int] = object
|
BigInt*[bits: static int] = object
|
||||||
## Fixed-precision big integer
|
## Fixed-precision big integer
|
||||||
|
@ -35,11 +35,18 @@ import
|
|||||||
# - proc MontyMagic(curve: static Curve): static Word =
|
# - proc MontyMagic(curve: static Curve): static Word =
|
||||||
# which returns the Montgomery magic constant
|
# which returns the Montgomery magic constant
|
||||||
# associated with the curve modulus
|
# associated with the curve modulus
|
||||||
declareCurves:
|
when not defined(testingCurves):
|
||||||
# Barreto-Naehrig curve, Prime 254 bit, 128-bit security, https://eprint.iacr.org/2013/879.pdf
|
declareCurves:
|
||||||
# Usage: Zero-Knowledge Proofs / zkSNARKs in ZCash and Ethereum 1
|
# Barreto-Naehrig curve, Prime 254 bit, 128-bit security, https://eprint.iacr.org/2013/879.pdf
|
||||||
# https://eips.ethereum.org/EIPS/eip-196
|
# Usage: Zero-Knowledge Proofs / zkSNARKs in ZCash and Ethereum 1
|
||||||
curve BN254:
|
# https://eips.ethereum.org/EIPS/eip-196
|
||||||
bitsize: 254
|
curve BN254:
|
||||||
modulus: "0x30644e72e131a029b85045b68181585d97816a916871ca8d3c208c16d87cfd47"
|
bitsize: 254
|
||||||
# Equation: Y^2 = X^3 + 3
|
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
|
import ./word_types, ./bigints, ./curves_config
|
||||||
from ./private/word_types_internal import unsafe_div2n1n
|
from ./private/word_types_internal import unsafe_div2n1n
|
||||||
|
|
||||||
static: echo CurveBitSize
|
|
||||||
|
|
||||||
type
|
type
|
||||||
Fp*[C: static Curve] = object
|
Fp*[C: static Curve] = object
|
||||||
## P is the prime modulus of the Curve C
|
## 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).
|
# * 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.
|
# at your option. This file may not be copied, modified, or distributed except according to those terms.
|
||||||
|
|
||||||
import
|
import unittest, random,
|
||||||
test_word_types,
|
../constantine/[io, bigints, word_types, field_fp]
|
||||||
test_io,
|
|
||||||
test_bigints
|
|
Loading…
x
Reference in New Issue
Block a user