2018-12-01 20:12:05 +01:00
packageName = "constantine"
2018-07-24 16:52:18 +02:00
version = "0.0.1"
author = "Status Research & Development GmbH"
2018-09-04 22:38:34 -06:00
description = "This library provides constant time big int primitives."
2018-07-24 16:52:18 +02:00
license = "MIT or Apache License 2.0"
srcDir = "src"
2020-06-15 22:58:56 +02:00
# Dependencies
# ----------------------------------------------------------------
2020-02-22 16:37:31 +01:00
requires "nim >= 1.1.0"
2018-07-24 16:52:18 +02:00
2020-06-15 22:58:56 +02:00
# Test config
# ----------------------------------------------------------------
2020-06-07 19:39:34 +02:00
const buildParallel = "test_parallel.txt"
2020-06-15 22:58:56 +02:00
const testDesc: seq[tuple[path: string, useGMP: bool]] = @[
# Primitives
2020-06-15 23:15:01 +02:00
("tests/t_primitives.nim", false),
2020-06-23 01:27:40 +02:00
("tests/t_primitives_extended_precision.nim", false),
2020-06-15 22:58:56 +02:00
# Big ints
2020-06-15 23:15:01 +02:00
("tests/t_io_bigints.nim", false),
("tests/t_bigints.nim", false),
("tests/t_bigints_multimod.nim", false),
("tests/t_bigints_mod_vs_gmp.nim", true),
("tests/t_bigints_mul_vs_gmp.nim", true),
("tests/t_bigints_mul_high_words_vs_gmp.nim", true),
2020-06-15 22:58:56 +02:00
# Field
2020-06-15 23:15:01 +02:00
("tests/t_io_fields", false),
("tests/t_finite_fields.nim", false),
("tests/t_finite_fields_mulsquare.nim", false),
("tests/t_finite_fields_sqrt.nim", false),
("tests/t_finite_fields_powinv.nim", false),
("tests/t_finite_fields_vs_gmp.nim", true),
2020-06-15 22:58:56 +02:00
# Precompute
2020-06-15 23:15:01 +02:00
("tests/t_precomputed", false),
2020-08-20 10:21:39 +02:00
# Double-width finite fields
("tests/t_finite_fields_double_width.nim", false),
2020-06-15 22:58:56 +02:00
# Towers of extension fields
2020-06-15 23:15:01 +02:00
("tests/t_fp2.nim", false),
("tests/t_fp2_sqrt.nim", false),
("tests/t_fp6_bn254_snarks.nim", false),
("tests/t_fp6_bls12_377.nim", false),
("tests/t_fp6_bls12_381.nim", false),
("tests/t_fp12_bn254_snarks.nim", false),
("tests/t_fp12_bls12_377.nim", false),
("tests/t_fp12_bls12_381.nim", false),
2020-09-21 23:24:00 +02:00
("tests/t_fp12_exponentiation.nim", false),
("tests/t_fp4_frobenius.nim", false),
2020-06-15 22:58:56 +02:00
# Elliptic curve arithmetic G1
2020-06-15 23:15:01 +02:00
("tests/t_ec_wstrass_prj_g1_add_double.nim", false),
("tests/t_ec_wstrass_prj_g1_mul_sanity.nim", false),
("tests/t_ec_wstrass_prj_g1_mul_distri.nim", false),
("tests/t_ec_wstrass_prj_g1_mul_vs_ref.nim", false),
2020-06-15 22:58:56 +02:00
# Elliptic curve arithmetic G2
2020-06-15 23:15:01 +02:00
("tests/t_ec_wstrass_prj_g2_add_double_bn254_snarks.nim", false),
("tests/t_ec_wstrass_prj_g2_mul_sanity_bn254_snarks.nim", false),
("tests/t_ec_wstrass_prj_g2_mul_distri_bn254_snarks.nim", false),
("tests/t_ec_wstrass_prj_g2_mul_vs_ref_bn254_snarks.nim", false),
2020-06-15 22:58:56 +02:00
2020-06-15 23:15:01 +02:00
("tests/t_ec_wstrass_prj_g2_add_double_bls12_381.nim", false),
("tests/t_ec_wstrass_prj_g2_mul_sanity_bls12_381.nim", false),
("tests/t_ec_wstrass_prj_g2_mul_distri_bls12_381.nim", false),
("tests/t_ec_wstrass_prj_g2_mul_vs_ref_bls12_381.nim", false),
2020-06-15 22:58:56 +02:00
# Elliptic curve arithmetic vs Sagemath
2020-08-31 23:18:48 +02:00
("tests/t_ec_frobenius.nim", false),
2020-06-15 23:15:01 +02:00
("tests/t_ec_sage_bn254.nim", false),
2020-06-23 01:27:40 +02:00
("tests/t_ec_sage_bls12_381.nim", false),
# Edge cases highlighted by past bugs
2020-09-21 23:24:00 +02:00
("tests/t_ec_wstrass_prj_edge_cases.nim", false),
# Pairing
2020-09-24 17:18:23 +02:00
("tests/t_pairing_mul_fp12_by_lines.nim", false),
("tests/t_pairing_cyclotomic_fp12.nim", false),
2020-09-21 23:24:00 +02:00
("tests/t_pairing_bn254_nogami_optate.nim", false),
("tests/t_pairing_bn254_snarks_optate.nim", false),
("tests/t_pairing_bls12_381_optate.nim", false)
2020-06-15 22:58:56 +02:00
]
2020-06-19 22:08:15 +02:00
# For temporary (hopefully) investigation that can only be reproduced in CI
const useDebug = [
"tests/t_bigints.nim"
]
2020-06-15 22:58:56 +02:00
# Helper functions
# ----------------------------------------------------------------
2020-06-07 19:39:34 +02:00
proc test(flags, path: string, commandFile = false) =
# commandFile should be a "file" but Nimscript doesn't support IO
# TODO: use a proper runner
2018-07-24 16:52:18 +02:00
if not dirExists "build":
mkDir "build"
2020-02-23 18:27:26 +01:00
# Compilation language is controlled by WEAVE_TEST_LANG
var lang = "c"
if existsEnv"TEST_LANG":
lang = getEnv"TEST_LANG"
2020-03-16 16:33:51 +01:00
var cc = ""
if existsEnv"CC":
cc = " --cc:" & getEnv"CC"
2020-08-22 23:00:05 +02:00
let command = "nim " & lang & cc & " " & flags &
" --verbosity:0 --outdir:build/testsuite -r --hints:off --warnings:off " &
" --nimcache:nimcache/" & path & " " &
path
2020-06-07 19:39:34 +02:00
if not commandFile:
2020-06-15 22:58:56 +02:00
echo "\n=============================================================================================="
2020-06-07 19:39:34 +02:00
echo "Running [flags: ", flags, "] ", path
2020-06-15 22:58:56 +02:00
echo "=============================================================================================="
2020-06-07 19:39:34 +02:00
exec command
else:
# commandFile.writeLine command
exec "echo \'" & command & "\' >> " & buildParallel
2018-07-24 16:52:18 +02:00
2020-08-20 10:21:39 +02:00
proc runBench(benchName: string, compiler = "", useAsm = true) =
2020-04-15 19:46:25 +02:00
if not dirExists "build":
mkDir "build"
var cc = ""
if compiler != "":
2020-08-20 10:21:39 +02:00
cc = "--cc:" & compiler
if not useAsm:
cc &= " -d:ConstantineASM=false"
2020-04-15 19:46:25 +02:00
exec "nim c " & cc &
2020-08-22 23:00:05 +02:00
" -d:danger --verbosity:0 -o:build/bench/" & benchName & "_" & compiler & "_" & (if useAsm: "useASM" else: "noASM") &
" --nimcache:nimcache/" & benchName & "_" & compiler & "_" & (if useAsm: "useASM" else: "noASM") &
2020-04-15 19:46:25 +02:00
" -r --hints:off --warnings:off benchmarks/" & benchName & ".nim"
2020-06-15 22:58:56 +02:00
# Tasks
# ----------------------------------------------------------------
2018-07-24 16:52:18 +02:00
task test, "Run all tests":
2020-02-23 18:27:26 +01:00
# -d:testingCurves is configured in a *.nim.cfg for convenience
2020-03-17 22:04:37 +01:00
2020-06-15 22:58:56 +02:00
for td in testDesc:
2020-06-19 22:08:15 +02:00
if td.path in useDebug:
test "-d:debugConstantine", td.path
else:
test "", td.path
2020-04-13 19:25:59 +02:00
if sizeof(int) == 8: # 32-bit tests on 64-bit arch
2020-06-15 22:58:56 +02:00
for td in testDesc:
2020-06-19 22:08:15 +02:00
if td.path in useDebug:
test "-d:Constantine32 -d:debugConstantine", td.path
else:
test "-d:Constantine32", td.path
2020-04-13 19:25:59 +02:00
2020-04-15 21:28:37 +02:00
# Ensure benchmarks stay relevant. Ignore Windows 32-bit at the moment
if not defined(windows) or not (existsEnv"UCPU" or getEnv"UCPU" == "i686"):
runBench("bench_fp")
runBench("bench_fp2")
runBench("bench_fp6")
runBench("bench_fp12")
2020-06-14 15:39:06 +02:00
runBench("bench_ec_g1")
2020-06-15 22:58:56 +02:00
runBench("bench_ec_g2")
2020-04-15 19:46:25 +02:00
2020-02-23 18:27:26 +01:00
task test_no_gmp, "Run tests that don't require GMP":
# -d:testingCurves is configured in a *.nim.cfg for convenience
2020-06-15 22:58:56 +02:00
for td in testDesc:
if not td.useGMP:
2020-06-19 22:08:15 +02:00
if td.path in useDebug:
test "-d:debugConstantine", td.path
else:
test "", td.path
2020-03-17 22:04:37 +01:00
2020-06-15 22:58:56 +02:00
if sizeof(int) == 8: # 32-bit tests on 64-bit arch
for td in testDesc:
if not td.useGMP:
2020-06-19 22:08:15 +02:00
if td.path in useDebug:
test "-d:Constantine32 -d:debugConstantine", td.path
else:
test "-d:Constantine32", td.path
2020-04-15 21:28:37 +02:00
# Ensure benchmarks stay relevant. Ignore Windows 32-bit at the moment
if not defined(windows) or not (existsEnv"UCPU" or getEnv"UCPU" == "i686"):
runBench("bench_fp")
runBench("bench_fp2")
runBench("bench_fp6")
runBench("bench_fp12")
2020-06-14 15:39:06 +02:00
runBench("bench_ec_g1")
2020-06-15 22:58:56 +02:00
runBench("bench_ec_g2")
2020-03-20 23:03:52 +01:00
2020-06-07 19:39:34 +02:00
task test_parallel, "Run all tests in parallel (via GNU parallel)":
# -d:testingCurves is configured in a *.nim.cfg for convenience
let cmdFile = true # open(buildParallel, mode = fmWrite) # Nimscript doesn't support IO :/
exec "> " & buildParallel
2020-06-15 22:58:56 +02:00
for td in testDesc:
2020-06-19 22:08:15 +02:00
if td.path in useDebug:
test "-d:debugConstantine", td.path, cmdFile
else:
test "", td.path, cmdFile
2020-06-07 19:39:34 +02:00
# cmdFile.close()
# Execute everything in parallel with GNU parallel
exec "parallel --keep-order --group < " & buildParallel
exec "> " & buildParallel
if sizeof(int) == 8: # 32-bit tests on 64-bit arch
2020-06-15 22:58:56 +02:00
for td in testDesc:
2020-06-19 22:08:15 +02:00
if td.path in useDebug:
test "-d:Constantine32 -d:debugConstantine", td.path, cmdFile
else:
test "-d:Constantine32", td.path, cmdFile
2020-06-07 19:39:34 +02:00
# cmdFile.close()
# Execute everything in parallel with GNU parallel
exec "parallel --keep-order --group < " & buildParallel
# Now run the benchmarks
#
# Benchmarks compile and run
# ignore Windows 32-bit for the moment
# Ensure benchmarks stay relevant. Ignore Windows 32-bit at the moment
if not defined(windows) or not (existsEnv"UCPU" or getEnv"UCPU" == "i686"):
runBench("bench_fp")
runBench("bench_fp2")
runBench("bench_fp6")
runBench("bench_fp12")
2020-06-14 15:39:06 +02:00
runBench("bench_ec_g1")
2020-06-20 19:46:30 +02:00
runBench("bench_ec_g2")
2020-07-24 22:02:30 +02:00
task test_parallel_no_assembler, "Run all tests (without macro assembler) in parallel (via GNU parallel)":
# -d:testingCurves is configured in a *.nim.cfg for convenience
let cmdFile = true # open(buildParallel, mode = fmWrite) # Nimscript doesn't support IO :/
exec "> " & buildParallel
for td in testDesc:
if td.path in useDebug:
test "-d:debugConstantine -d:ConstantineASM=false", td.path, cmdFile
else:
test " -d:ConstantineASM=false", td.path, cmdFile
# cmdFile.close()
# Execute everything in parallel with GNU parallel
exec "parallel --keep-order --group < " & buildParallel
exec "> " & buildParallel
if sizeof(int) == 8: # 32-bit tests on 64-bit arch
for td in testDesc:
if td.path in useDebug:
test "-d:Constantine32 -d:debugConstantine -d:ConstantineASM=false", td.path, cmdFile
else:
test "-d:Constantine32 -d:ConstantineASM=false", td.path, cmdFile
# cmdFile.close()
# Execute everything in parallel with GNU parallel
exec "parallel --keep-order --group < " & buildParallel
# Now run the benchmarks
#
# Benchmarks compile and run
# ignore Windows 32-bit for the moment
# Ensure benchmarks stay relevant. Ignore Windows 32-bit at the moment
if not defined(windows) or not (existsEnv"UCPU" or getEnv"UCPU" == "i686"):
runBench("bench_fp")
runBench("bench_fp2")
runBench("bench_fp6")
runBench("bench_fp12")
runBench("bench_ec_g1")
runBench("bench_ec_g2")
2020-06-20 19:46:30 +02:00
task test_parallel_no_gmp, "Run all tests in parallel (via GNU parallel)":
# -d:testingCurves is configured in a *.nim.cfg for convenience
let cmdFile = true # open(buildParallel, mode = fmWrite) # Nimscript doesn't support IO :/
exec "> " & buildParallel
for td in testDesc:
if not td.useGMP:
if td.path in useDebug:
test "-d:debugConstantine", td.path, cmdFile
else:
test "", td.path, cmdFile
# cmdFile.close()
# Execute everything in parallel with GNU parallel
exec "parallel --keep-order --group < " & buildParallel
2020-09-21 23:24:00 +02:00
exec "> " & buildParallel
if sizeof(int) == 8: # 32-bit tests on 64-bit arch
for td in testDesc:
if not td.useGMP:
if td.path in useDebug:
test "-d:Constantine32 -d:debugConstantine", td.path, cmdFile
else:
test "-d:Constantine32", td.path, cmdFile
# cmdFile.close()
# Execute everything in parallel with GNU parallel
exec "parallel --keep-order --group < " & buildParallel
# Now run the benchmarks
#
# Benchmarks compile and run
# ignore Windows 32-bit for the moment
# Ensure benchmarks stay relevant. Ignore Windows 32-bit at the moment
if not defined(windows) or not (existsEnv"UCPU" or getEnv"UCPU" == "i686"):
runBench("bench_fp")
runBench("bench_fp2")
runBench("bench_fp6")
runBench("bench_fp12")
runBench("bench_ec_g1")
runBench("bench_ec_g2")
task test_parallel_no_gmp_no_assembler, "Run all tests in parallel (via GNU parallel)":
# -d:testingCurves is configured in a *.nim.cfg for convenience
let cmdFile = true # open(buildParallel, mode = fmWrite) # Nimscript doesn't support IO :/
exec "> " & buildParallel
for td in testDesc:
if not td.useGMP:
if td.path in useDebug:
test "-d:debugConstantine -d:ConstantineASM=false", td.path, cmdFile
else:
test "-d:ConstantineASM=false", td.path, cmdFile
# cmdFile.close()
# Execute everything in parallel with GNU parallel
exec "parallel --keep-order --group < " & buildParallel
2020-06-20 19:46:30 +02:00
exec "> " & buildParallel
if sizeof(int) == 8: # 32-bit tests on 64-bit arch
for td in testDesc:
if not td.useGMP:
if td.path in useDebug:
test "-d:Constantine32 -d:debugConstantine", td.path, cmdFile
else:
test "-d:Constantine32", td.path, cmdFile
# cmdFile.close()
# Execute everything in parallel with GNU parallel
exec "parallel --keep-order --group < " & buildParallel
# Now run the benchmarks
#
# Benchmarks compile and run
# ignore Windows 32-bit for the moment
# Ensure benchmarks stay relevant. Ignore Windows 32-bit at the moment
if not defined(windows) or not (existsEnv"UCPU" or getEnv"UCPU" == "i686"):
runBench("bench_fp")
runBench("bench_fp2")
runBench("bench_fp6")
runBench("bench_fp12")
runBench("bench_ec_g1")
2020-06-15 22:58:56 +02:00
runBench("bench_ec_g2")
2020-06-07 19:39:34 +02:00
2020-03-21 02:31:31 +01:00
task bench_fp, "Run benchmark 𝔽 p with your default compiler":
runBench("bench_fp")
task bench_fp_gcc, "Run benchmark 𝔽 p with gcc":
runBench("bench_fp", "gcc")
task bench_fp_clang, "Run benchmark 𝔽 p with clang":
runBench("bench_fp", "clang")
2020-08-20 10:21:39 +02:00
task bench_fp_gcc_noasm, "Run benchmark 𝔽 p with gcc - no Assembly":
runBench("bench_fp", "gcc", useAsm = false)
task bench_fp_clang_noasm, "Run benchmark 𝔽 p with clang - no Assembly":
runBench("bench_fp", "clang", useAsm = false)
task bench_fpdbl, "Run benchmark 𝔽 pDbl with your default compiler":
runBench("bench_fp_double_width")
task bench_fpdbl_gcc, "Run benchmark 𝔽 p with gcc":
runBench("bench_fp_double_width", "gcc")
task bench_fpdbl_clang, "Run benchmark 𝔽 p with clang":
runBench("bench_fp_double_width", "clang")
task bench_fpdbl_gcc_noasm, "Run benchmark 𝔽 p with gcc - no Assembly":
runBench("bench_fp_double_width", "gcc", useAsm = false)
task bench_fpdbl_clang_noasm, "Run benchmark 𝔽 p with clang - no Assembly":
runBench("bench_fp_double_width", "clang", useAsm = false)
2020-03-21 02:31:31 +01:00
task bench_fp2, "Run benchmark with 𝔽 p2 your default compiler":
runBench("bench_fp2")
task bench_fp2_gcc, "Run benchmark 𝔽 p2 with gcc":
runBench("bench_fp2", "gcc")
task bench_fp2_clang, "Run benchmark 𝔽 p2 with clang":
runBench("bench_fp2", "clang")
2020-08-20 10:21:39 +02:00
task bench_fp2_gcc_noasm, "Run benchmark 𝔽 p2 with gcc - no Assembly":
runBench("bench_fp2", "gcc", useAsm = false)
task bench_fp2_clang_noasm, "Run benchmark 𝔽 p2 with clang - no Assembly":
runBench("bench_fp2", "clang", useAsm = false)
2020-03-21 02:31:31 +01:00
task bench_fp6, "Run benchmark with 𝔽 p6 your default compiler":
runBench("bench_fp6")
task bench_fp6_gcc, "Run benchmark 𝔽 p6 with gcc":
runBench("bench_fp6", "gcc")
task bench_fp6_clang, "Run benchmark 𝔽 p6 with clang":
runBench("bench_fp6", "clang")
2020-04-09 14:28:01 +02:00
2020-08-20 10:21:39 +02:00
task bench_fp6_gcc_noasm, "Run benchmark 𝔽 p6 with gcc - no Assembly":
runBench("bench_fp6", "gcc", useAsm = false)
task bench_fp6_clang_noasm, "Run benchmark 𝔽 p6 with clang - no Assembly":
runBench("bench_fp6", "clang", useAsm = false)
2020-04-09 14:28:01 +02:00
task bench_fp12, "Run benchmark with 𝔽 p12 your default compiler":
runBench("bench_fp12")
task bench_fp12_gcc, "Run benchmark 𝔽 p12 with gcc":
runBench("bench_fp12", "gcc")
task bench_fp12_clang, "Run benchmark 𝔽 p12 with clang":
runBench("bench_fp12", "clang")
2020-04-15 19:43:31 +02:00
2020-08-20 10:21:39 +02:00
task bench_fp12_gcc_noasm, "Run benchmark 𝔽 p12 with gcc - no Assembly":
runBench("bench_fp12", "gcc", useAsm = false)
task bench_fp12_clang_noasm, "Run benchmark 𝔽 p12 with clang - no Assembly":
runBench("bench_fp12", "clang", useAsm = false)
2020-09-24 17:18:23 +02:00
task bench_ec_g1, "Run benchmark on Elliptic Curve group 𝔾 1 - Short Weierstrass with Projective Coordinates - Default compiler":
2020-06-14 15:39:06 +02:00
runBench("bench_ec_g1")
2020-04-15 19:43:31 +02:00
2020-06-15 22:58:56 +02:00
task bench_ec_g1_gcc, "Run benchmark on Elliptic Curve group 𝔾 1 - Short Weierstrass with Projective Coordinates - GCC":
2020-06-14 15:39:06 +02:00
runBench("bench_ec_g1", "gcc")
2020-04-15 19:43:31 +02:00
2020-06-14 15:39:06 +02:00
task bench_ec_g1_clang, "Run benchmark on Elliptic Curve group 𝔾 1 - Short Weierstrass with Projective Coordinates - Clang":
runBench("bench_ec_g1", "clang")
2020-06-15 22:58:56 +02:00
2020-08-20 10:21:39 +02:00
task bench_ec_g1_gcc_noasm, "Run benchmark on Elliptic Curve group 𝔾 1 - Short Weierstrass with Projective Coordinates - GCC no Assembly":
runBench("bench_ec_g1", "gcc", useAsm = false)
task bench_ec_g1_clang_noasm, "Run benchmark on Elliptic Curve group 𝔾 1 - Short Weierstrass with Projective Coordinates - Clang no Assembly":
runBench("bench_ec_g1", "clang", useAsm = false)
2020-09-24 17:18:23 +02:00
task bench_ec_g2, "Run benchmark on Elliptic Curve group 𝔾 2 - Short Weierstrass with Projective Coordinates - Default compiler":
2020-06-15 22:58:56 +02:00
runBench("bench_ec_g2")
task bench_ec_g2_gcc, "Run benchmark on Elliptic Curve group 𝔾 2 - Short Weierstrass with Projective Coordinates - GCC":
runBench("bench_ec_g2", "gcc")
task bench_ec_g2_clang, "Run benchmark on Elliptic Curve group 𝔾 2 - Short Weierstrass with Projective Coordinates - Clang":
runBench("bench_ec_g2", "clang")
2020-08-20 10:21:39 +02:00
task bench_ec_g2_gcc_noasm, "Run benchmark on Elliptic Curve group 𝔾 2 - Short Weierstrass with Projective Coordinates - GCC no Assembly":
runBench("bench_ec_g2", "gcc", useAsm = false)
task bench_ec_g2_clang_noasm, "Run benchmark on Elliptic Curve group 𝔾 2 - Short Weierstrass with Projective Coordinates - Clang no Assembly":
runBench("bench_ec_g2", "clang", useAsm = false)
2020-09-24 17:18:23 +02:00
task bench_pairing_bls12_381, "Run pairings benchmarks for BLS12-381 - Default compiler":
runBench("bench_pairing_bls12_381")
task bench_pairing_bls12_381_gcc, "Run benchmark on Elliptic Curve group 𝔾 2 - Short Weierstrass with Projective Coordinates - GCC":
runBench("bench_pairing_bls12_381", "gcc")
task bench_pairing_bls12_381_clang, "Run benchmark on Elliptic Curve group 𝔾 2 - Short Weierstrass with Projective Coordinates - Clang":
runBench("bench_pairing_bls12_381", "clang")
task bench_pairing_bls12_381_gcc_noasm, "Run benchmark on Elliptic Curve group 𝔾 2 - Short Weierstrass with Projective Coordinates - GCC no Assembly":
runBench("bench_pairing_bls12_381", "gcc", useAsm = false)
task bench_pairing_bls12_381_clang_noasm, "Run benchmark on Elliptic Curve group 𝔾 2 - Short Weierstrass with Projective Coordinates - Clang no Assembly":
runBench("bench_pairing_bls12_381", "clang", useAsm = false)