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
|
2022-02-27 00:49:08 +00:00
|
|
|
|
../constantine/math/config/curves,
|
|
|
|
|
../constantine/math/arithmetic,
|
|
|
|
|
../constantine/math/io/io_bigints,
|
2022-08-14 07:48:10 +00:00
|
|
|
|
../constantine/math/constants/zoo_square_roots,
|
2020-03-21 01:31:31 +00:00
|
|
|
|
# Helpers
|
2022-01-01 15:19:35 +00:00
|
|
|
|
./bench_fields_template
|
2020-03-21 01:31:31 +00:00
|
|
|
|
|
|
|
|
|
# ############################################################
|
|
|
|
|
#
|
|
|
|
|
# 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,
|
2022-02-27 00:49:08 +00:00
|
|
|
|
Edwards25519,
|
2022-01-01 15:19:35 +00:00
|
|
|
|
Bandersnatch,
|
2022-04-26 22:58:48 +00:00
|
|
|
|
Pallas,
|
|
|
|
|
Vesta,
|
2022-01-01 15:19:35 +00:00
|
|
|
|
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)
|
2022-01-01 15:19:35 +00:00
|
|
|
|
smallSeparator()
|
2022-08-14 07:48:10 +00:00
|
|
|
|
mul2xUnrBench(Fp[curve], Iters)
|
|
|
|
|
sqr2xUnrBench(Fp[curve], Iters)
|
|
|
|
|
rdc2xBench(Fp[curve], Iters)
|
|
|
|
|
smallSeparator()
|
|
|
|
|
sumprodBench(Fp[curve], Iters)
|
2022-02-20 19:15:20 +00:00
|
|
|
|
smallSeparator()
|
2022-02-13 23:16:55 +00:00
|
|
|
|
toBigBench(Fp[curve], Iters)
|
|
|
|
|
toFieldBench(Fp[curve], Iters)
|
|
|
|
|
smallSeparator()
|
2022-02-10 13:05:07 +00:00
|
|
|
|
invBench(Fp[curve], ExponentIters)
|
2023-02-16 11:45:05 +00:00
|
|
|
|
invVartimeBench(Fp[curve], ExponentIters)
|
2022-08-07 17:50:28 +00:00
|
|
|
|
isSquareBench(Fp[curve], ExponentIters)
|
2022-01-01 15:19:35 +00:00
|
|
|
|
sqrtBench(Fp[curve], ExponentIters)
|
|
|
|
|
sqrtRatioBench(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()
|