2020-03-21 01:31:31 +00:00
|
|
|
|
# Constantine
|
|
|
|
|
# Copyright (c) 2018-2019 Status Research & Development GmbH
|
|
|
|
|
# Copyright (c) 2020-Present Mamy André-Ratsimbazafy
|
|
|
|
|
# Licensed and distributed under either of
|
|
|
|
|
# * MIT license (license terms in the root directory or at http://opensource.org/licenses/MIT).
|
|
|
|
|
# * 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
|
|
|
|
|
# Internals
|
2021-01-23 19:55:40 +00:00
|
|
|
|
../constantine/config/[curves, common],
|
2020-03-22 12:24:37 +00:00
|
|
|
|
../constantine/arithmetic,
|
2020-06-17 20:44:52 +00:00
|
|
|
|
../constantine/io/io_bigints,
|
2021-01-23 19:55:40 +00:00
|
|
|
|
../constantine/curves/[zoo_inversions, zoo_square_roots],
|
2020-03-21 01:31:31 +00:00
|
|
|
|
# Helpers
|
|
|
|
|
../helpers/static_for,
|
|
|
|
|
./bench_fields_template,
|
|
|
|
|
# Standard library
|
|
|
|
|
std/strutils
|
|
|
|
|
|
|
|
|
|
# ############################################################
|
|
|
|
|
#
|
|
|
|
|
# Benchmark of 𝔽p
|
|
|
|
|
#
|
|
|
|
|
# ############################################################
|
|
|
|
|
|
|
|
|
|
|
2021-01-23 19:55:40 +00:00
|
|
|
|
const Iters = 100_000
|
|
|
|
|
const ExponentIters = 100
|
2020-03-21 01:31:31 +00:00
|
|
|
|
const AvailableCurves = [
|
2020-06-17 20:44:52 +00:00
|
|
|
|
# P224,
|
2020-09-27 07:15:14 +00:00
|
|
|
|
BN254_Nogami,
|
2020-04-12 01:01:50 +00:00
|
|
|
|
BN254_Snarks,
|
2020-06-17 20:44:52 +00:00
|
|
|
|
# Curve25519,
|
|
|
|
|
# P256,
|
|
|
|
|
# Secp256k1,
|
2020-09-27 07:15:14 +00:00
|
|
|
|
BLS12_377,
|
2020-03-21 12:05:58 +00:00
|
|
|
|
BLS12_381,
|
2021-01-23 19:55:40 +00:00
|
|
|
|
BW6_761
|
2020-03-21 01:31:31 +00:00
|
|
|
|
]
|
|
|
|
|
|
|
|
|
|
proc main() =
|
2020-04-15 17:38:02 +00:00
|
|
|
|
separator()
|
2020-03-21 01:31:31 +00:00
|
|
|
|
staticFor i, 0, AvailableCurves.len:
|
|
|
|
|
const curve = AvailableCurves[i]
|
|
|
|
|
addBench(Fp[curve], Iters)
|
|
|
|
|
subBench(Fp[curve], Iters)
|
|
|
|
|
negBench(Fp[curve], Iters)
|
2020-10-01 22:01:09 +00:00
|
|
|
|
ccopyBench(Fp[curve], Iters)
|
|
|
|
|
div2Bench(Fp[curve], Iters)
|
2020-03-21 01:31:31 +00:00
|
|
|
|
mulBench(Fp[curve], Iters)
|
|
|
|
|
sqrBench(Fp[curve], Iters)
|
2020-09-04 17:04:32 +00:00
|
|
|
|
invEuclidBench(Fp[curve], ExponentIters)
|
|
|
|
|
invPowFermatBench(Fp[curve], ExponentIters)
|
2021-01-23 19:55:40 +00:00
|
|
|
|
when curve.hasInversionAddchain():
|
2020-09-27 07:15:14 +00:00
|
|
|
|
invAddChainBench(Fp[curve], ExponentIters)
|
2021-01-23 19:55:40 +00:00
|
|
|
|
when (BaseType(curve.Mod.limbs[0]) and 3) == 3:
|
|
|
|
|
sqrtP3mod4Bench(Fp[curve], ExponentIters)
|
|
|
|
|
when curve.hasSqrtAddchain():
|
|
|
|
|
sqrtAddChainBench(Fp[curve], ExponentIters)
|
|
|
|
|
when curve in {BLS12_377}:
|
|
|
|
|
sqrtTonelliBench(Fp[curve], ExponentIters)
|
|
|
|
|
sqrtTonelliAddChainBench(Fp[curve], ExponentIters)
|
2020-06-17 20:44:52 +00:00
|
|
|
|
# Exponentiation by a "secret" of size ~the curve order
|
|
|
|
|
powBench(Fp[curve], ExponentIters)
|
|
|
|
|
powUnsafeBench(Fp[curve], ExponentIters)
|
2020-04-15 17:38:02 +00:00
|
|
|
|
separator()
|
2020-03-21 01:31:31 +00:00
|
|
|
|
|
|
|
|
|
main()
|
2020-07-24 20:02:30 +00:00
|
|
|
|
notes()
|