2020-03-21 02:31:31 +01: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
|
2022-02-27 01:49:08 +01:00
|
|
|
|
../constantine/math/config/curves,
|
|
|
|
|
../constantine/math/arithmetic,
|
|
|
|
|
../constantine/math/io/io_bigints,
|
2022-08-14 09:48:10 +02:00
|
|
|
|
../constantine/math/constants/zoo_square_roots,
|
2020-03-21 02:31:31 +01:00
|
|
|
|
# Helpers
|
2022-01-01 16:19:35 +01:00
|
|
|
|
./bench_fields_template
|
2020-03-21 02:31:31 +01:00
|
|
|
|
|
|
|
|
|
# ############################################################
|
|
|
|
|
#
|
|
|
|
|
# Benchmark of 𝔽p
|
|
|
|
|
#
|
|
|
|
|
# ############################################################
|
|
|
|
|
|
|
|
|
|
|
2021-01-23 20:55:40 +01:00
|
|
|
|
const Iters = 100_000
|
|
|
|
|
const ExponentIters = 100
|
2020-03-21 02:31:31 +01:00
|
|
|
|
const AvailableCurves = [
|
2020-06-17 22:44:52 +02:00
|
|
|
|
# P224,
|
2020-09-27 09:15:14 +02:00
|
|
|
|
BN254_Nogami,
|
2020-04-12 03:01:50 +02:00
|
|
|
|
BN254_Snarks,
|
2022-02-27 01:49:08 +01:00
|
|
|
|
Edwards25519,
|
2022-01-01 16:19:35 +01:00
|
|
|
|
Bandersnatch,
|
2022-04-27 00:58:48 +02:00
|
|
|
|
Pallas,
|
|
|
|
|
Vesta,
|
2022-01-01 16:19:35 +01:00
|
|
|
|
P256,
|
|
|
|
|
Secp256k1,
|
2020-09-27 09:15:14 +02:00
|
|
|
|
BLS12_377,
|
2020-03-21 13:05:58 +01:00
|
|
|
|
BLS12_381,
|
2021-01-23 20:55:40 +01:00
|
|
|
|
BW6_761
|
2020-03-21 02:31:31 +01:00
|
|
|
|
]
|
|
|
|
|
|
|
|
|
|
proc main() =
|
2020-04-15 19:38:02 +02:00
|
|
|
|
separator()
|
2020-03-21 02:31:31 +01:00
|
|
|
|
staticFor i, 0, AvailableCurves.len:
|
|
|
|
|
const curve = AvailableCurves[i]
|
|
|
|
|
addBench(Fp[curve], Iters)
|
|
|
|
|
subBench(Fp[curve], Iters)
|
|
|
|
|
negBench(Fp[curve], Iters)
|
2020-10-02 00:01:09 +02:00
|
|
|
|
ccopyBench(Fp[curve], Iters)
|
|
|
|
|
div2Bench(Fp[curve], Iters)
|
2020-03-21 02:31:31 +01:00
|
|
|
|
mulBench(Fp[curve], Iters)
|
|
|
|
|
sqrBench(Fp[curve], Iters)
|
2022-01-01 16:19:35 +01:00
|
|
|
|
smallSeparator()
|
2022-08-14 09:48:10 +02:00
|
|
|
|
mul2xUnrBench(Fp[curve], Iters)
|
|
|
|
|
sqr2xUnrBench(Fp[curve], Iters)
|
|
|
|
|
rdc2xBench(Fp[curve], Iters)
|
|
|
|
|
smallSeparator()
|
|
|
|
|
sumprodBench(Fp[curve], Iters)
|
2022-02-20 20:15:20 +01:00
|
|
|
|
smallSeparator()
|
2022-02-14 00:16:55 +01:00
|
|
|
|
toBigBench(Fp[curve], Iters)
|
|
|
|
|
toFieldBench(Fp[curve], Iters)
|
|
|
|
|
smallSeparator()
|
2022-02-10 14:05:07 +01:00
|
|
|
|
invBench(Fp[curve], ExponentIters)
|
2022-08-07 19:50:28 +02:00
|
|
|
|
isSquareBench(Fp[curve], ExponentIters)
|
2022-01-01 16:19:35 +01:00
|
|
|
|
sqrtBench(Fp[curve], ExponentIters)
|
|
|
|
|
sqrtRatioBench(Fp[curve], ExponentIters)
|
2020-06-17 22:44:52 +02:00
|
|
|
|
# Exponentiation by a "secret" of size ~the curve order
|
|
|
|
|
powBench(Fp[curve], ExponentIters)
|
|
|
|
|
powUnsafeBench(Fp[curve], ExponentIters)
|
2020-04-15 19:38:02 +02:00
|
|
|
|
separator()
|
2020-03-21 02:31:31 +01:00
|
|
|
|
|
|
|
|
|
main()
|
2020-07-24 22:02:30 +02:00
|
|
|
|
notes()
|