-
-
Notifications
You must be signed in to change notification settings - Fork 43
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
EIP-2537 - BLS12-381 precompiles for the EVM (#368)
* eip2537: initial metering * eip2537: improve markdown reporting * eip2537: iterate on reporting * eip2537: iterate on reporting 2 * eip2537: fix constant-time scalar mul * eip2537: add projective coordinates * eip2537: more comprehensive metering * eip2537: use Clang and also add benchmarks * eip2537: fix bench table * eip2537: add pic * eip2537: add vartime benches * eip2537: benches for rollcall and https://ethereum-magicians.org/t/eip-2537-bls12-precompile-discussion-thread/4187/66 * eip2537: create bench with subgroup checks * eip2537: fix import of MSM on G2 - frobenius endomorphism * commit subgroup check benches from https://github.com/mratsim/constantine/pull/368\#issuecomment-2047473465 * EVM: move modexp precompiles above the rest of elliptic precompiles * EVM: implement BLS12381_G1ADD and BLS12381_G2ADD * eip2537: bn254 tests properly call renamed procedure * EVM: implement BLS12381_G1MUL and BLS12381_G2MUL * EVM: implement BLS12381_G1MSM and BLS12381_G2MSM * EVM: Pass geth and EIP-2537 precompiles test suite * MSM: fix types for field coefficients * EVM: implement map to field and pass all tests * bench: consistent use of eth prefix for Ethereum benches * EVM: add precompiles benchmark * EVM: add BLS12 pairings * EVM: fix bench bls sig
- Loading branch information
Showing
67 changed files
with
3,997 additions
and
929 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
# 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 | ||
../constantine/math/config/curves, | ||
../constantine/math/extension_fields, | ||
../constantine/math/elliptic/[ | ||
ec_shortweierstrass_projective, | ||
ec_shortweierstrass_jacobian], | ||
# Helpers | ||
../helpers/prng_unsafe, | ||
./bench_elliptic_parallel_template | ||
|
||
# ############################################################ | ||
# | ||
# Benchmark of the G1 group of | ||
# Short Weierstrass elliptic curves | ||
# in (homogeneous) projective coordinates | ||
# | ||
# ############################################################ | ||
|
||
|
||
const Iters = 10_000 | ||
const AvailableCurves = [ | ||
BLS12_381, | ||
] | ||
|
||
# const testNumPoints = [10, 100, 1000, 10000, 100000] | ||
const testNumPoints = [2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192] | ||
|
||
proc main() = | ||
separator() | ||
staticFor i, 0, AvailableCurves.len: | ||
const curve = AvailableCurves[i] | ||
var ctx = createBenchMsmContext(ECP_ShortW_Jac[Fp2[curve], G2], testNumPoints) | ||
separator() | ||
for numPoints in testNumPoints: | ||
let batchIters = max(1, Iters div numPoints) | ||
ctx.msmParallelBench(numPoints, batchIters) | ||
separator() | ||
separator() | ||
|
||
main() | ||
notes() |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
# 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 | ||
../constantine/math/config/curves, | ||
../constantine/math/arithmetic, | ||
../constantine/math/extension_fields, | ||
../constantine/math/elliptic/ec_shortweierstrass_jacobian, | ||
# Helpers | ||
./bench_elliptic_template | ||
|
||
# ############################################################ | ||
# | ||
# EIP-2537 benchmarks for | ||
# subgroup checks discussion | ||
# | ||
# ############################################################ | ||
|
||
|
||
const Iters = 10_000 | ||
const MulIters = 100 | ||
const AvailableCurves = [ | ||
BLS12_381, | ||
] | ||
|
||
proc main() = | ||
separator() | ||
staticFor i, 0, AvailableCurves.len: | ||
const curve = AvailableCurves[i] | ||
const bits = curve.getCurveOrderBitwidth() | ||
|
||
# G1 | ||
separator() | ||
scalarMulVartimeDoubleAddBench(ECP_ShortW_Jac[Fp[curve], G1], bits, MulIters) | ||
separator() | ||
scalarMulVartimeWNAFBench(ECP_ShortW_Jac[Fp[curve], G1], bits, window = 3, MulIters) | ||
scalarMulVartimeWNAFBench(ECP_ShortW_Jac[Fp[curve], G1], bits, window = 4, MulIters) | ||
scalarMulVartimeWNAFBench(ECP_ShortW_Jac[Fp[curve], G1], bits, window = 5, MulIters) | ||
separator() | ||
scalarMulVartimeEndoWNAFBench(ECP_ShortW_Jac[Fp[curve], G1], bits, window = 3, MulIters) | ||
scalarMulVartimeEndoWNAFBench(ECP_ShortW_Jac[Fp[curve], G1], bits, window = 4, MulIters) | ||
scalarMulVartimeEndoWNAFBench(ECP_ShortW_Jac[Fp[curve], G1], bits, window = 5, MulIters) | ||
separator() | ||
scalarMulEndo( ECP_ShortW_Jac[Fp[curve], G1], bits, MulIters) | ||
scalarMulEndoWindow(ECP_ShortW_Jac[Fp[curve], G1], bits, MulIters) | ||
separator() | ||
subgroupCheckBench(ECP_ShortW_Jac[Fp[curve], G1], MulIters) | ||
subgroupCheckScalarMulVartimeEndoWNAFBench(ECP_ShortW_Jac[Fp[curve], G1], bits, window = 3, MulIters) | ||
subgroupCheckScalarMulVartimeEndoWNAFBench(ECP_ShortW_Jac[Fp[curve], G1], bits, window = 4, MulIters) | ||
subgroupCheckScalarMulVartimeEndoWNAFBench(ECP_ShortW_Jac[Fp[curve], G1], bits, window = 5, MulIters) | ||
separator() | ||
|
||
# G2 | ||
separator() | ||
scalarMulVartimeDoubleAddBench(ECP_ShortW_Jac[Fp2[curve], G2], bits, MulIters) | ||
separator() | ||
scalarMulVartimeWNAFBench(ECP_ShortW_Jac[Fp2[curve], G2], bits, window = 3, MulIters) | ||
scalarMulVartimeWNAFBench(ECP_ShortW_Jac[Fp2[curve], G2], bits, window = 4, MulIters) | ||
separator() | ||
scalarMulVartimeEndoWNAFBench(ECP_ShortW_Jac[Fp2[curve], G2], bits, window = 3, MulIters) | ||
scalarMulVartimeEndoWNAFBench(ECP_ShortW_Jac[Fp2[curve], G2], bits, window = 4, MulIters) | ||
separator() | ||
scalarMulEndo(ECP_ShortW_Jac[Fp2[curve], G2], bits, MulIters) | ||
separator() | ||
subgroupCheckBench(ECP_ShortW_Jac[Fp2[curve], G2], MulIters) | ||
subgroupCheckScalarMulVartimeEndoWNAFBench(ECP_ShortW_Jac[Fp2[curve], G2], bits, window = 3, MulIters) | ||
subgroupCheckScalarMulVartimeEndoWNAFBench(ECP_ShortW_Jac[Fp2[curve], G2], bits, window = 4, MulIters) | ||
separator() | ||
|
||
main() | ||
notes() |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
--threads:on |
File renamed without changes.
Oops, something went wrong.