mirror of
https://github.com/logos-storage/constantine.git
synced 2026-01-02 21:23:11 +00:00
* Add MultiScalar recoding from "Efficient and Secure Algorithms for GLV-Based Scalar Multiplication" by Faz et al * precompute cube root of unity - Add VM precomputation of Fp - workaround upstream bug https://github.com/nim-lang/Nim/issues/14585 * Add the φ-accelerated lookup table builder * Add a dedicated bithacks file * cosmetic import consistency * Build the φ precompute table with n-1 EC additions instead of 2^(n-1) additions * remove binary * Add the GLV precomputations to the sage scripts * You can't avoid it, bigint multiplication is needed at one point * Add bigint multiplication discarding some low words * Implement the lattice decomposition in sage * Proper decomposition for BN254 * Prepare the code for a new scalar mul * We compile, and now debugging hunt * More helpers to debug GLV scalar Mul * Fix conditional negation * Endomorphism accelerated scalar mul working for BN254 curve * Implement endomorphism acceleration for BLS12-381 (needed cofactor clearing of the point) * fix nimble test script after bench rename
38 lines
1.3 KiB
Nim
38 lines
1.3 KiB
Nim
# 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 std/unittest,
|
|
../constantine/arithmetic,
|
|
../constantine/config/curves,
|
|
../constantine/io/[io_bigints, io_fields]
|
|
|
|
proc checkCubeRootOfUnity(curve: static Curve) =
|
|
test $curve & " cube root of unity (mod p)":
|
|
var cru = curve.getCubicRootOfUnity_mod_p()
|
|
cru.square()
|
|
cru *= curve.getCubicRootOfUnity_mod_p()
|
|
|
|
check: bool cru.isOne()
|
|
|
|
test $curve & " cube root of unity (mod r)":
|
|
var cru: BigInt[3 * curve.getCurveOrderBitwidth()]
|
|
cru.prod(curve.getCubicRootOfUnity_mod_r(), curve.getCubicRootOfUnity_mod_r())
|
|
cru.prod(cru, curve.getCubicRootOfUnity_mod_r())
|
|
|
|
var r: BigInt[curve.getCurveOrderBitwidth()]
|
|
r.reduce(cru, curve.getCurveOrder)
|
|
|
|
check: bool r.isOne()
|
|
|
|
proc main() =
|
|
suite "Sanity checks on precomputed values":
|
|
checkCubeRootOfUnity(BN254_Snarks)
|
|
# checkCubeRootOfUnity(BLS12_381)
|
|
|
|
main()
|