* Fix another typo in the Jubjub curve comment * fix * progress * get_point_from_x_unchecked * fix * soft link * Fix Bandersnatch * Fix Edwards form of Bandersnatch * Actually fix ed_on_bls12_381_bandersnatch/src/curves/mod.rs * fix * fix * curve-benches * fix the last mul_by_a; fmt Co-authored-by: onewayfunc <onewayfunc@gmail.com> Co-authored-by: Pratyush Mishra <pratyushmishra@berkeley.edu>cherry-pick
@ -1,16 +1,9 @@ |
|||||
use ark_algebra_test_templates::{
|
|
||||
curves::*, generate_bilinearity_test, generate_g1_test, generate_g2_test, msm::*,
|
|
||||
};
|
|
||||
use ark_ec::{AffineCurve, PairingEngine};
|
|
||||
use ark_ff::{
|
|
||||
fields::{Field, PrimeField},
|
|
||||
One,
|
|
||||
};
|
|
||||
use ark_std::{rand::Rng, test_rng};
|
|
||||
use core::ops::MulAssign;
|
|
||||
|
use ark_algebra_test_templates::*;
|
||||
|
use ark_ff::fields::Field;
|
||||
|
|
||||
use crate::{g1, g2, Bn254, Fq12, Fr, G1Affine, G1Projective, G2Affine, G2Projective};
|
|
||||
|
use crate::{Bn254, G1Projective, G2Projective};
|
||||
|
|
||||
generate_g1_test!(bn254; curve_tests; sw_tests;);
|
|
||||
generate_g2_test!(bn254; curve_tests; sw_tests;);
|
|
||||
generate_bilinearity_test!(Bn254, Fq12);
|
|
||||
|
test_group!(g1; G1Projective; sw);
|
||||
|
test_group!(g2; G2Projective; sw);
|
||||
|
test_group!(pairing_output; ark_ec::pairing::PairingOutput<Bn254>; msm);
|
||||
|
test_pairing!(pairing; crate::Bn254);
|
@ -0,0 +1 @@ |
|||||
|
../LICENSE-APACHE |
@ -0,0 +1 @@ |
|||||
|
../LICENSE-MIT |
@ -1,13 +1,8 @@ |
|||||
use ark_algebra_test_templates::{
|
|
||||
curves::*, generate_bilinearity_test, generate_g1_test, generate_g2_test, msm::*,
|
|
||||
};
|
|
||||
use ark_ec::{AffineCurve, PairingEngine};
|
|
||||
use ark_ff::{Field, One, PrimeField};
|
|
||||
use ark_std::{rand::Rng, test_rng};
|
|
||||
use core::ops::MulAssign;
|
|
||||
|
|
||||
use crate::*;
|
use crate::*;
|
||||
|
use ark_algebra_test_templates::*;
|
||||
|
use ark_ff::Field;
|
||||
|
|
||||
generate_g1_test!(bw6_761; curve_tests; sw_tests;);
|
|
||||
generate_g2_test!(bw6_761; curve_tests; sw_tests;);
|
|
||||
generate_bilinearity_test!(BW6_761, Fq6);
|
|
||||
|
test_group!(g1; G1Projective; sw);
|
||||
|
test_group!(g2; G2Projective; sw);
|
||||
|
test_group!(pairing_output; ark_ec::pairing::PairingOutput<BW6_761>; msm);
|
||||
|
test_pairing!(pairing; crate::BW6_761);
|
@ -1,12 +1,7 @@ |
|||||
use ark_algebra_test_templates::{
|
|
||||
fields::*, generate_field_serialization_test, generate_field_test,
|
|
||||
};
|
|
||||
use ark_ff::{Field, One, PrimeField, UniformRand, Zero};
|
|
||||
use ark_serialize::{buffer_bit_byte_size, CanonicalSerialize};
|
|
||||
use ark_std::{rand::Rng, test_rng};
|
|
||||
use core::ops::{AddAssign, MulAssign, SubAssign};
|
|
||||
|
|
||||
use crate::*;
|
use crate::*;
|
||||
|
use ark_algebra_test_templates::*;
|
||||
|
|
||||
generate_field_test!(bw6_761; fq3; fq6_2_on_3; false; mont(12, 6); );
|
|
||||
generate_field_serialization_test!(bw6_761;);
|
|
||||
|
test_field!(fr; Fr; mont_prime_field);
|
||||
|
test_field!(fq; Fq; mont_prime_field);
|
||||
|
test_field!(fq3; Fq3);
|
||||
|
test_field!(fq6; Fq6);
|
@ -0,0 +1 @@ |
|||||
|
../LICENSE-APACHE |
@ -0,0 +1 @@ |
|||||
|
../LICENSE-MIT |
@ -1,13 +1,9 @@ |
|||||
use ark_algebra_test_templates::{
|
|
||||
curves::*, generate_bilinearity_test, generate_g1_test, generate_g2_test, msm::*,
|
|
||||
};
|
|
||||
use ark_ec::{AffineCurve, PairingEngine};
|
|
||||
use ark_ff::{Field, One, PrimeField};
|
|
||||
use ark_std::{rand::Rng, test_rng};
|
|
||||
use core::ops::MulAssign;
|
|
||||
|
use ark_algebra_test_templates::*;
|
||||
|
use ark_ff::Field;
|
||||
|
|
||||
use crate::*;
|
use crate::*;
|
||||
|
|
||||
generate_g1_test!(cp6_782; curve_tests; sw_tests;);
|
|
||||
generate_g2_test!(cp6_782; curve_tests; sw_tests;);
|
|
||||
generate_bilinearity_test!(CP6_782, Fq6);
|
|
||||
|
test_group!(g1; G1Projective; sw);
|
||||
|
test_group!(g2; G2Projective; sw);
|
||||
|
test_group!(pairing_output; ark_ec::pairing::PairingOutput<CP6_782>; msm);
|
||||
|
test_pairing!(pairing; crate::CP6_782);
|
@ -1,12 +1,7 @@ |
|||||
use ark_algebra_test_templates::{
|
|
||||
fields::*, generate_field_serialization_test, generate_field_test,
|
|
||||
};
|
|
||||
use ark_ff::{Field, One, PrimeField, UniformRand, Zero};
|
|
||||
use ark_serialize::{buffer_bit_byte_size, CanonicalSerialize};
|
|
||||
use ark_std::{rand::Rng, test_rng};
|
|
||||
use core::ops::{AddAssign, MulAssign, SubAssign};
|
|
||||
|
|
||||
use crate::*;
|
use crate::*;
|
||||
|
use ark_algebra_test_templates::*;
|
||||
|
|
||||
generate_field_test!(cp6_782; fq3; fq6_2_on_3; mont(13, 6); );
|
|
||||
generate_field_serialization_test!(cp6_782;);
|
|
||||
|
test_field!(fr; Fr; mont_prime_field);
|
||||
|
test_field!(fq; Fq; mont_prime_field);
|
||||
|
test_field!(fq3; Fq3);
|
||||
|
test_field!(fq6; Fq6);
|
@ -1,9 +0,0 @@ |
|||||
extern crate rustc_version;
|
|
||||
|
|
||||
use rustc_version::{version_meta, Channel};
|
|
||||
|
|
||||
fn main() {
|
|
||||
if version_meta().expect("nightly check failed").channel == Channel::Nightly {
|
|
||||
println!("cargo:rustc-cfg=nightly");
|
|
||||
}
|
|
||||
}
|
|
@ -1,8 +0,0 @@ |
|||||
#![allow(unused_macros, unused_imports)]
|
|
||||
#[macro_use]
|
|
||||
pub mod macros;
|
|
||||
pub use macros::*;
|
|
||||
|
|
||||
#[macro_use]
|
|
||||
pub extern crate bencher;
|
|
||||
pub use bencher::*;
|
|
@ -1,258 +0,0 @@ |
|||||
#[macro_export]
|
|
||||
macro_rules! ec_bench {
|
|
||||
($projective:ty, $affine:ty) => {
|
|
||||
fn rand(b: &mut $crate::bencher::Bencher) {
|
|
||||
let mut rng = ark_std::test_rng();
|
|
||||
b.iter(|| <$projective>::rand(&mut rng));
|
|
||||
}
|
|
||||
|
|
||||
fn mul_assign(b: &mut $crate::bencher::Bencher) {
|
|
||||
const SAMPLES: usize = 1000;
|
|
||||
|
|
||||
let mut rng = ark_std::test_rng();
|
|
||||
|
|
||||
let v: Vec<($projective, Fr)> = (0..SAMPLES)
|
|
||||
.map(|_| (<$projective>::rand(&mut rng), Fr::rand(&mut rng)))
|
|
||||
.collect();
|
|
||||
|
|
||||
let mut count = 0;
|
|
||||
b.iter(|| {
|
|
||||
let mut tmp = v[count].0;
|
|
||||
tmp *= v[count].1;
|
|
||||
count = (count + 1) % SAMPLES;
|
|
||||
tmp
|
|
||||
});
|
|
||||
}
|
|
||||
|
|
||||
fn add_assign(b: &mut $crate::bencher::Bencher) {
|
|
||||
const SAMPLES: usize = 1000;
|
|
||||
|
|
||||
let mut rng = ark_std::test_rng();
|
|
||||
|
|
||||
let v: Vec<($projective, $projective)> = (0..SAMPLES)
|
|
||||
.map(|_| (<$projective>::rand(&mut rng), <$projective>::rand(&mut rng)))
|
|
||||
.collect();
|
|
||||
|
|
||||
let mut count = 0;
|
|
||||
b.iter(|| {
|
|
||||
let mut tmp = v[count].0;
|
|
||||
n_fold!(tmp, v, add_assign, count);
|
|
||||
count = (count + 1) % SAMPLES;
|
|
||||
tmp
|
|
||||
});
|
|
||||
}
|
|
||||
|
|
||||
fn sub_assign(b: &mut $crate::bencher::Bencher) {
|
|
||||
const SAMPLES: usize = 1000;
|
|
||||
|
|
||||
let mut rng = ark_std::test_rng();
|
|
||||
|
|
||||
let v: Vec<($projective, $projective)> = (0..SAMPLES)
|
|
||||
.map(|_| (<$projective>::rand(&mut rng), <$projective>::rand(&mut rng)))
|
|
||||
.collect();
|
|
||||
|
|
||||
let mut count = 0;
|
|
||||
b.iter(|| {
|
|
||||
let mut tmp = v[count].0;
|
|
||||
n_fold!(tmp, v, sub_assign, count);
|
|
||||
count = (count + 1) % SAMPLES;
|
|
||||
tmp
|
|
||||
});
|
|
||||
}
|
|
||||
|
|
||||
fn double(b: &mut $crate::bencher::Bencher) {
|
|
||||
const SAMPLES: usize = 1000;
|
|
||||
|
|
||||
let mut rng = ark_std::test_rng();
|
|
||||
|
|
||||
let v: Vec<$projective> = (0..SAMPLES)
|
|
||||
.map(|_| <$projective>::rand(&mut rng))
|
|
||||
.collect();
|
|
||||
|
|
||||
let mut count = 0;
|
|
||||
b.iter(|| {
|
|
||||
let mut tmp = v[count];
|
|
||||
n_fold!(tmp, double_in_place);
|
|
||||
count = (count + 1) % SAMPLES;
|
|
||||
tmp
|
|
||||
});
|
|
||||
}
|
|
||||
|
|
||||
fn add_assign_mixed(b: &mut $crate::bencher::Bencher) {
|
|
||||
const SAMPLES: usize = 1000;
|
|
||||
|
|
||||
let mut rng = ark_std::test_rng();
|
|
||||
|
|
||||
let v: Vec<($projective, $affine)> = (0..SAMPLES)
|
|
||||
.map(|_| {
|
|
||||
(
|
|
||||
<$projective>::rand(&mut rng),
|
|
||||
<$projective>::rand(&mut rng).into(),
|
|
||||
)
|
|
||||
})
|
|
||||
.collect();
|
|
||||
|
|
||||
let mut count = 0;
|
|
||||
b.iter(|| {
|
|
||||
let mut tmp = v[count].0;
|
|
||||
n_fold!(tmp, v, add_assign_mixed, count);
|
|
||||
count = (count + 1) % SAMPLES;
|
|
||||
tmp
|
|
||||
});
|
|
||||
}
|
|
||||
|
|
||||
fn deser(b: &mut $crate::bencher::Bencher) {
|
|
||||
use ark_ec::ProjectiveCurve;
|
|
||||
use ark_serialize::{CanonicalDeserialize, CanonicalSerialize};
|
|
||||
const SAMPLES: usize = 1000;
|
|
||||
|
|
||||
let mut rng = ark_std::test_rng();
|
|
||||
|
|
||||
let mut num_bytes = 0;
|
|
||||
let tmp = <$projective>::rand(&mut rng).into_affine();
|
|
||||
let v: Vec<_> = (0..SAMPLES)
|
|
||||
.flat_map(|_| {
|
|
||||
let mut bytes = Vec::with_capacity(1000);
|
|
||||
tmp.serialize(&mut bytes).unwrap();
|
|
||||
num_bytes = bytes.len();
|
|
||||
bytes
|
|
||||
})
|
|
||||
.collect();
|
|
||||
|
|
||||
let mut count = 0;
|
|
||||
b.iter(|| {
|
|
||||
count = (count + 1) % SAMPLES;
|
|
||||
let index = count * num_bytes;
|
|
||||
<$affine>::deserialize(&v[index..(index + num_bytes)]).unwrap()
|
|
||||
});
|
|
||||
}
|
|
||||
|
|
||||
fn ser(b: &mut $crate::bencher::Bencher) {
|
|
||||
use ark_ec::ProjectiveCurve;
|
|
||||
use ark_serialize::CanonicalSerialize;
|
|
||||
const SAMPLES: usize = 1000;
|
|
||||
|
|
||||
let mut rng = ark_std::test_rng();
|
|
||||
|
|
||||
let mut v: Vec<_> = (0..SAMPLES)
|
|
||||
.map(|_| <$projective>::rand(&mut rng))
|
|
||||
.collect();
|
|
||||
let v = <$projective>::batch_normalization_into_affine(v.as_mut_slice());
|
|
||||
let mut bytes = Vec::with_capacity(1000);
|
|
||||
|
|
||||
let mut count = 0;
|
|
||||
b.iter(|| {
|
|
||||
let tmp = v[count];
|
|
||||
count = (count + 1) % SAMPLES;
|
|
||||
bytes.clear();
|
|
||||
tmp.serialize(&mut bytes)
|
|
||||
});
|
|
||||
}
|
|
||||
|
|
||||
fn deser_unchecked(b: &mut $crate::bencher::Bencher) {
|
|
||||
use ark_ec::ProjectiveCurve;
|
|
||||
use ark_serialize::{CanonicalDeserialize, CanonicalSerialize};
|
|
||||
const SAMPLES: usize = 1000;
|
|
||||
|
|
||||
let mut rng = ark_std::test_rng();
|
|
||||
|
|
||||
let mut num_bytes = 0;
|
|
||||
let tmp = <$projective>::rand(&mut rng).into_affine();
|
|
||||
let v: Vec<_> = (0..SAMPLES)
|
|
||||
.flat_map(|_| {
|
|
||||
let mut bytes = Vec::with_capacity(1000);
|
|
||||
tmp.serialize_unchecked(&mut bytes).unwrap();
|
|
||||
num_bytes = bytes.len();
|
|
||||
bytes
|
|
||||
})
|
|
||||
.collect();
|
|
||||
|
|
||||
let mut count = 0;
|
|
||||
b.iter(|| {
|
|
||||
count = (count + 1) % SAMPLES;
|
|
||||
let index = count * num_bytes;
|
|
||||
<$affine>::deserialize_unchecked(&v[index..(index + num_bytes)]).unwrap()
|
|
||||
});
|
|
||||
}
|
|
||||
|
|
||||
fn ser_unchecked(b: &mut $crate::bencher::Bencher) {
|
|
||||
use ark_serialize::{CanonicalDeserialize, CanonicalSerialize};
|
|
||||
const SAMPLES: usize = 1000;
|
|
||||
|
|
||||
let mut rng = ark_std::test_rng();
|
|
||||
|
|
||||
let mut v: Vec<_> = (0..SAMPLES)
|
|
||||
.map(|_| <$projective>::rand(&mut rng))
|
|
||||
.collect();
|
|
||||
let v = <$projective>::batch_normalization_into_affine(v.as_mut_slice());
|
|
||||
let mut bytes = Vec::with_capacity(1000);
|
|
||||
|
|
||||
let mut count = 0;
|
|
||||
b.iter(|| {
|
|
||||
let tmp = v[count];
|
|
||||
count = (count + 1) % SAMPLES;
|
|
||||
bytes.clear();
|
|
||||
tmp.serialize_unchecked(&mut bytes)
|
|
||||
});
|
|
||||
}
|
|
||||
|
|
||||
fn deser_uncompressed(b: &mut $crate::bencher::Bencher) {
|
|
||||
use ark_ec::ProjectiveCurve;
|
|
||||
use ark_serialize::{CanonicalDeserialize, CanonicalSerialize};
|
|
||||
const SAMPLES: usize = 1000;
|
|
||||
|
|
||||
let mut rng = ark_std::test_rng();
|
|
||||
|
|
||||
let mut num_bytes = 0;
|
|
||||
let tmp = <$projective>::rand(&mut rng).into_affine();
|
|
||||
let v: Vec<_> = (0..SAMPLES)
|
|
||||
.flat_map(|_| {
|
|
||||
let mut bytes = Vec::with_capacity(1000);
|
|
||||
tmp.serialize_uncompressed(&mut bytes).unwrap();
|
|
||||
num_bytes = bytes.len();
|
|
||||
bytes
|
|
||||
})
|
|
||||
.collect();
|
|
||||
|
|
||||
let mut count = 0;
|
|
||||
b.iter(|| {
|
|
||||
count = (count + 1) % SAMPLES;
|
|
||||
let index = count * num_bytes;
|
|
||||
<$affine>::deserialize_uncompressed(&v[index..(index + num_bytes)]).unwrap()
|
|
||||
});
|
|
||||
}
|
|
||||
|
|
||||
fn msm_131072(b: &mut $crate::bencher::Bencher) {
|
|
||||
use ark_ec::msm::VariableBaseMSM;
|
|
||||
use ark_serialize::{CanonicalDeserialize, CanonicalSerialize};
|
|
||||
const SAMPLES: usize = 131072;
|
|
||||
|
|
||||
let mut rng = ark_std::test_rng();
|
|
||||
|
|
||||
let g = <$projective>::rand(&mut rng).into_affine();
|
|
||||
let v: Vec<_> = (0..SAMPLES).map(|_| g).collect();
|
|
||||
let scalars: Vec<_> = (0..SAMPLES)
|
|
||||
.map(|_| Fr::rand(&mut rng).into_bigint())
|
|
||||
.collect();
|
|
||||
b.bench_n(1, |b| {
|
|
||||
b.iter(|| <$projective as VariableBaseMSM>::msm_bigint(&v, &scalars));
|
|
||||
})
|
|
||||
}
|
|
||||
|
|
||||
$crate::benchmark_group!(
|
|
||||
group_ops,
|
|
||||
rand,
|
|
||||
mul_assign,
|
|
||||
add_assign,
|
|
||||
sub_assign,
|
|
||||
add_assign_mixed,
|
|
||||
double,
|
|
||||
ser,
|
|
||||
deser,
|
|
||||
ser_unchecked,
|
|
||||
deser_unchecked,
|
|
||||
deser_uncompressed,
|
|
||||
msm_131072,
|
|
||||
);
|
|
||||
};
|
|
||||
}
|
|
@ -1,455 +0,0 @@ |
|||||
#[macro_export]
|
|
||||
macro_rules! f_bench {
|
|
||||
// Use this for base fields
|
|
||||
($f:ident, $f_type:ty, $f_repr:ident, $f_repr_type:ty, $modname:ident) => {
|
|
||||
pub mod $modname {
|
|
||||
use super::*;
|
|
||||
field_common!($f, $f_type);
|
|
||||
sqrt!($f, $f_type);
|
|
||||
prime_field!($f, $f_type, $f_repr, $f_repr_type);
|
|
||||
$crate::benchmark_group!(
|
|
||||
$modname,
|
|
||||
// common stuff
|
|
||||
add_assign,
|
|
||||
sub_assign,
|
|
||||
double,
|
|
||||
negate,
|
|
||||
mul_assign,
|
|
||||
square,
|
|
||||
inverse,
|
|
||||
ser,
|
|
||||
deser,
|
|
||||
ser_unchecked,
|
|
||||
deser_unchecked,
|
|
||||
// sqrt field stuff
|
|
||||
sqrt,
|
|
||||
// prime field stuff
|
|
||||
repr_add_nocarry,
|
|
||||
repr_sub_noborrow,
|
|
||||
repr_num_bits,
|
|
||||
repr_mul2,
|
|
||||
repr_div2,
|
|
||||
into_repr,
|
|
||||
from_repr,
|
|
||||
);
|
|
||||
}
|
|
||||
use $modname::$modname;
|
|
||||
};
|
|
||||
// use this for intermediate fields
|
|
||||
(extension, $f:ident, $f_type:ty, $modname:ident) => {
|
|
||||
mod $modname {
|
|
||||
use super::*;
|
|
||||
field_common!($f, $f_type);
|
|
||||
sqrt!($f, $f_type);
|
|
||||
$crate::benchmark_group!(
|
|
||||
$modname,
|
|
||||
// common stuff
|
|
||||
add_assign,
|
|
||||
sub_assign,
|
|
||||
double,
|
|
||||
negate,
|
|
||||
mul_assign,
|
|
||||
square,
|
|
||||
inverse,
|
|
||||
ser,
|
|
||||
deser,
|
|
||||
ser_unchecked,
|
|
||||
deser_unchecked,
|
|
||||
// sqrt field stuff
|
|
||||
sqrt,
|
|
||||
);
|
|
||||
}
|
|
||||
use $modname::$modname;
|
|
||||
};
|
|
||||
// Use this for the full extension field Fqk
|
|
||||
(target, $f:ident, $f_type:ty, $modname:ident) => {
|
|
||||
mod $modname {
|
|
||||
use super::*;
|
|
||||
field_common!($f, $f_type);
|
|
||||
$crate::benchmark_group!(
|
|
||||
$modname,
|
|
||||
// common stuff
|
|
||||
add_assign,
|
|
||||
sub_assign,
|
|
||||
double,
|
|
||||
negate,
|
|
||||
mul_assign,
|
|
||||
square,
|
|
||||
inverse,
|
|
||||
ser,
|
|
||||
deser,
|
|
||||
ser_unchecked,
|
|
||||
deser_unchecked,
|
|
||||
);
|
|
||||
}
|
|
||||
use $modname::$modname;
|
|
||||
};
|
|
||||
}
|
|
||||
|
|
||||
#[macro_export]
|
|
||||
macro_rules! field_common {
|
|
||||
($f:ident, $f_type:ty) => {
|
|
||||
fn add_assign(b: &mut $crate::bencher::Bencher) {
|
|
||||
const SAMPLES: usize = 1000;
|
|
||||
|
|
||||
let mut rng = ark_std::test_rng();
|
|
||||
|
|
||||
let v: Vec<_> = (0..SAMPLES)
|
|
||||
.map(|_| ($f::rand(&mut rng), $f::rand(&mut rng)))
|
|
||||
.collect();
|
|
||||
|
|
||||
let mut count = 0;
|
|
||||
b.iter(|| {
|
|
||||
let mut tmp = v[count].0;
|
|
||||
n_fold!(tmp, v, add_assign, count);
|
|
||||
count = (count + 1) % SAMPLES;
|
|
||||
tmp
|
|
||||
});
|
|
||||
}
|
|
||||
|
|
||||
fn sub_assign(b: &mut $crate::bencher::Bencher) {
|
|
||||
const SAMPLES: usize = 1000;
|
|
||||
|
|
||||
let mut rng = ark_std::test_rng();
|
|
||||
|
|
||||
let v: Vec<_> = (0..SAMPLES)
|
|
||||
.map(|_| ($f::rand(&mut rng), $f::rand(&mut rng)))
|
|
||||
.collect();
|
|
||||
|
|
||||
let mut count = 0;
|
|
||||
b.iter(|| {
|
|
||||
let mut tmp = v[count].0;
|
|
||||
n_fold!(tmp, v, sub_assign, count);
|
|
||||
count = (count + 1) % SAMPLES;
|
|
||||
tmp
|
|
||||
});
|
|
||||
}
|
|
||||
|
|
||||
fn double(b: &mut $crate::bencher::Bencher) {
|
|
||||
const SAMPLES: usize = 1000;
|
|
||||
|
|
||||
let mut rng = ark_std::test_rng();
|
|
||||
|
|
||||
let v: Vec<$f_type> = (0..SAMPLES).map(|_| $f::rand(&mut rng)).collect();
|
|
||||
|
|
||||
let mut count = 0;
|
|
||||
b.iter(|| {
|
|
||||
let mut tmp = v[count];
|
|
||||
n_fold!(tmp, double_in_place);
|
|
||||
count = (count + 1) % SAMPLES;
|
|
||||
tmp
|
|
||||
});
|
|
||||
}
|
|
||||
|
|
||||
fn negate(b: &mut $crate::bencher::Bencher) {
|
|
||||
const SAMPLES: usize = 1000;
|
|
||||
|
|
||||
let mut rng = ark_std::test_rng();
|
|
||||
|
|
||||
let v: Vec<$f_type> = (0..SAMPLES).map(|_| $f::rand(&mut rng)).collect();
|
|
||||
|
|
||||
let mut count = 0;
|
|
||||
b.iter(|| {
|
|
||||
let mut tmp = v[count];
|
|
||||
tmp = -tmp;
|
|
||||
count = (count + 1) % SAMPLES;
|
|
||||
tmp
|
|
||||
});
|
|
||||
}
|
|
||||
|
|
||||
fn mul_assign(b: &mut $crate::bencher::Bencher) {
|
|
||||
const SAMPLES: usize = 1000;
|
|
||||
|
|
||||
let mut rng = ark_std::test_rng();
|
|
||||
|
|
||||
let v: Vec<_> = (0..SAMPLES)
|
|
||||
.map(|_| ($f::rand(&mut rng), $f::rand(&mut rng)))
|
|
||||
.collect();
|
|
||||
|
|
||||
let mut count = 0;
|
|
||||
b.iter(|| {
|
|
||||
let mut tmp = v[count].0;
|
|
||||
n_fold!(tmp, v, mul_assign, count);
|
|
||||
count = (count + 1) % SAMPLES;
|
|
||||
tmp
|
|
||||
});
|
|
||||
}
|
|
||||
|
|
||||
fn square(b: &mut $crate::bencher::Bencher) {
|
|
||||
const SAMPLES: usize = 1000;
|
|
||||
|
|
||||
let mut rng = ark_std::test_rng();
|
|
||||
|
|
||||
let v: Vec<$f_type> = (0..SAMPLES).map(|_| $f::rand(&mut rng)).collect();
|
|
||||
|
|
||||
let mut count = 0;
|
|
||||
b.iter(|| {
|
|
||||
let mut tmp = v[count];
|
|
||||
n_fold!(tmp, square_in_place);
|
|
||||
count = (count + 1) % SAMPLES;
|
|
||||
tmp
|
|
||||
});
|
|
||||
}
|
|
||||
|
|
||||
fn inverse(b: &mut $crate::bencher::Bencher) {
|
|
||||
const SAMPLES: usize = 1000;
|
|
||||
|
|
||||
let mut rng = ark_std::test_rng();
|
|
||||
|
|
||||
let v: Vec<$f_type> = (0..SAMPLES).map(|_| $f::rand(&mut rng)).collect();
|
|
||||
|
|
||||
let mut count = 0;
|
|
||||
b.iter(|| {
|
|
||||
let tmp = v[count].inverse();
|
|
||||
count = (count + 1) % SAMPLES;
|
|
||||
tmp
|
|
||||
});
|
|
||||
}
|
|
||||
|
|
||||
fn deser(b: &mut $crate::bencher::Bencher) {
|
|
||||
use ark_serialize::{CanonicalDeserialize, CanonicalSerialize};
|
|
||||
const SAMPLES: usize = 1000;
|
|
||||
|
|
||||
let mut rng = ark_std::test_rng();
|
|
||||
|
|
||||
let mut num_bytes = 0;
|
|
||||
let v: Vec<_> = (0..SAMPLES)
|
|
||||
.flat_map(|_| {
|
|
||||
let mut bytes = Vec::with_capacity(1000);
|
|
||||
let tmp = $f::rand(&mut rng);
|
|
||||
tmp.serialize(&mut bytes).unwrap();
|
|
||||
num_bytes = bytes.len();
|
|
||||
bytes
|
|
||||
})
|
|
||||
.collect();
|
|
||||
|
|
||||
let mut count = 0;
|
|
||||
b.iter(|| {
|
|
||||
count = (count + 1) % SAMPLES;
|
|
||||
let index = count * num_bytes;
|
|
||||
<$f_type>::deserialize(&v[index..(index + num_bytes)]).unwrap()
|
|
||||
});
|
|
||||
}
|
|
||||
|
|
||||
fn ser(b: &mut $crate::bencher::Bencher) {
|
|
||||
use ark_serialize::CanonicalSerialize;
|
|
||||
const SAMPLES: usize = 1000;
|
|
||||
|
|
||||
let mut rng = ark_std::test_rng();
|
|
||||
|
|
||||
let v: Vec<$f_type> = (0..SAMPLES).map(|_| $f::rand(&mut rng)).collect();
|
|
||||
let mut bytes = Vec::with_capacity(1000);
|
|
||||
|
|
||||
let mut count = 0;
|
|
||||
b.iter(|| {
|
|
||||
let tmp = v[count];
|
|
||||
count = (count + 1) % SAMPLES;
|
|
||||
bytes.clear();
|
|
||||
tmp.serialize(&mut bytes)
|
|
||||
});
|
|
||||
}
|
|
||||
|
|
||||
fn deser_unchecked(b: &mut $crate::bencher::Bencher) {
|
|
||||
use ark_serialize::{CanonicalDeserialize, CanonicalSerialize};
|
|
||||
const SAMPLES: usize = 1000;
|
|
||||
|
|
||||
let mut rng = ark_std::test_rng();
|
|
||||
|
|
||||
let mut num_bytes = 0;
|
|
||||
let v: Vec<_> = (0..SAMPLES)
|
|
||||
.flat_map(|_| {
|
|
||||
let mut bytes = Vec::with_capacity(1000);
|
|
||||
let tmp = $f::rand(&mut rng);
|
|
||||
tmp.serialize_unchecked(&mut bytes).unwrap();
|
|
||||
num_bytes = bytes.len();
|
|
||||
bytes
|
|
||||
})
|
|
||||
.collect();
|
|
||||
|
|
||||
let mut count = 0;
|
|
||||
b.iter(|| {
|
|
||||
count = (count + 1) % SAMPLES;
|
|
||||
let index = count * num_bytes;
|
|
||||
<$f_type>::deserialize_unchecked(&v[index..(index + num_bytes)]).unwrap()
|
|
||||
});
|
|
||||
}
|
|
||||
|
|
||||
fn ser_unchecked(b: &mut $crate::bencher::Bencher) {
|
|
||||
use ark_serialize::CanonicalSerialize;
|
|
||||
const SAMPLES: usize = 1000;
|
|
||||
|
|
||||
let mut rng = ark_std::test_rng();
|
|
||||
|
|
||||
let v: Vec<$f_type> = (0..SAMPLES).map(|_| $f::rand(&mut rng)).collect();
|
|
||||
let mut bytes = Vec::with_capacity(1000);
|
|
||||
|
|
||||
let mut count = 0;
|
|
||||
b.iter(|| {
|
|
||||
let tmp = v[count];
|
|
||||
count = (count + 1) % SAMPLES;
|
|
||||
bytes.clear();
|
|
||||
tmp.serialize_unchecked(&mut bytes)
|
|
||||
});
|
|
||||
}
|
|
||||
};
|
|
||||
}
|
|
||||
|
|
||||
#[macro_export]
|
|
||||
macro_rules! sqrt {
|
|
||||
($f:ident, $f_type:ty) => {
|
|
||||
pub fn sqrt(b: &mut $crate::bencher::Bencher) {
|
|
||||
const SAMPLES: usize = 1000;
|
|
||||
|
|
||||
let mut rng = ark_std::test_rng();
|
|
||||
|
|
||||
let v: Vec<$f_type> = (0..SAMPLES)
|
|
||||
.map(|_| {
|
|
||||
let mut tmp = $f::rand(&mut rng);
|
|
||||
tmp.square_in_place();
|
|
||||
tmp
|
|
||||
})
|
|
||||
.collect();
|
|
||||
|
|
||||
let mut count = 0;
|
|
||||
b.iter(|| {
|
|
||||
count = (count + 1) % SAMPLES;
|
|
||||
v[count].sqrt()
|
|
||||
});
|
|
||||
}
|
|
||||
};
|
|
||||
}
|
|
||||
|
|
||||
#[macro_export]
|
|
||||
macro_rules! prime_field {
|
|
||||
($f:ident, $f_type:ty, $f_repr:ident, $f_repr_type:ty) => {
|
|
||||
fn repr_add_nocarry(b: &mut $crate::bencher::Bencher) {
|
|
||||
const SAMPLES: usize = 1000;
|
|
||||
|
|
||||
let mut rng = ark_std::test_rng();
|
|
||||
|
|
||||
let v: Vec<_> = (0..SAMPLES)
|
|
||||
.map(|_| {
|
|
||||
let mut tmp1 = $f_repr::rand(&mut rng);
|
|
||||
let mut tmp2 = $f_repr::rand(&mut rng);
|
|
||||
// Shave a few bits off to avoid overflow.
|
|
||||
for _ in 0..3 {
|
|
||||
tmp1.div2();
|
|
||||
tmp2.div2();
|
|
||||
}
|
|
||||
(tmp1, tmp2)
|
|
||||
})
|
|
||||
.collect();
|
|
||||
|
|
||||
let mut count = 0;
|
|
||||
b.iter(|| {
|
|
||||
let mut tmp = v[count].0;
|
|
||||
n_fold!(tmp, v, add_with_carry, count);
|
|
||||
count = (count + 1) % SAMPLES;
|
|
||||
tmp
|
|
||||
});
|
|
||||
}
|
|
||||
|
|
||||
fn repr_sub_noborrow(b: &mut $crate::bencher::Bencher) {
|
|
||||
const SAMPLES: usize = 1000;
|
|
||||
|
|
||||
let mut rng = ark_std::test_rng();
|
|
||||
|
|
||||
let v: Vec<_> = (0..SAMPLES)
|
|
||||
.map(|_| {
|
|
||||
let tmp1 = $f_repr::rand(&mut rng);
|
|
||||
let mut tmp2 = tmp1;
|
|
||||
// Ensure tmp2 is smaller than tmp1.
|
|
||||
for _ in 0..10 {
|
|
||||
tmp2.div2();
|
|
||||
}
|
|
||||
(tmp1, tmp2)
|
|
||||
})
|
|
||||
.collect();
|
|
||||
|
|
||||
let mut count = 0;
|
|
||||
b.iter(|| {
|
|
||||
let mut tmp = v[count].0;
|
|
||||
n_fold!(tmp, v, sub_with_borrow, count);
|
|
||||
count = (count + 1) % SAMPLES;
|
|
||||
tmp;
|
|
||||
});
|
|
||||
}
|
|
||||
|
|
||||
fn repr_num_bits(b: &mut $crate::bencher::Bencher) {
|
|
||||
const SAMPLES: usize = 1000;
|
|
||||
|
|
||||
let mut rng = ark_std::test_rng();
|
|
||||
|
|
||||
let v: Vec<$f_repr_type> = (0..SAMPLES).map(|_| $f_repr::rand(&mut rng)).collect();
|
|
||||
|
|
||||
let mut count = 0;
|
|
||||
b.iter(|| {
|
|
||||
let tmp = v[count].num_bits();
|
|
||||
count = (count + 1) % SAMPLES;
|
|
||||
tmp;
|
|
||||
});
|
|
||||
}
|
|
||||
|
|
||||
fn repr_mul2(b: &mut $crate::bencher::Bencher) {
|
|
||||
const SAMPLES: usize = 1000;
|
|
||||
|
|
||||
let mut rng = ark_std::test_rng();
|
|
||||
|
|
||||
let v: Vec<$f_repr_type> = (0..SAMPLES).map(|_| $f_repr::rand(&mut rng)).collect();
|
|
||||
|
|
||||
let mut count = 0;
|
|
||||
b.iter(|| {
|
|
||||
let mut tmp = v[count];
|
|
||||
n_fold!(tmp, mul2);
|
|
||||
count = (count + 1) % SAMPLES;
|
|
||||
tmp;
|
|
||||
});
|
|
||||
}
|
|
||||
|
|
||||
fn repr_div2(b: &mut $crate::bencher::Bencher) {
|
|
||||
const SAMPLES: usize = 1000;
|
|
||||
|
|
||||
let mut rng = ark_std::test_rng();
|
|
||||
|
|
||||
let v: Vec<$f_repr_type> = (0..SAMPLES).map(|_| $f_repr::rand(&mut rng)).collect();
|
|
||||
|
|
||||
let mut count = 0;
|
|
||||
b.iter(|| {
|
|
||||
let mut tmp = v[count];
|
|
||||
n_fold!(tmp, div2);
|
|
||||
count = (count + 1) % SAMPLES;
|
|
||||
tmp;
|
|
||||
});
|
|
||||
}
|
|
||||
|
|
||||
fn into_repr(b: &mut $crate::bencher::Bencher) {
|
|
||||
const SAMPLES: usize = 1000;
|
|
||||
|
|
||||
let mut rng = ark_std::test_rng();
|
|
||||
|
|
||||
let v: Vec<$f_type> = (0..SAMPLES).map(|_| $f::rand(&mut rng)).collect();
|
|
||||
|
|
||||
let mut count = 0;
|
|
||||
b.iter(|| {
|
|
||||
count = (count + 1) % SAMPLES;
|
|
||||
v[count].into_bigint();
|
|
||||
});
|
|
||||
}
|
|
||||
|
|
||||
fn from_repr(b: &mut $crate::bencher::Bencher) {
|
|
||||
const SAMPLES: usize = 1000;
|
|
||||
|
|
||||
let mut rng = ark_std::test_rng();
|
|
||||
|
|
||||
let v: Vec<$f_repr_type> = (0..SAMPLES)
|
|
||||
.map(|_| $f::rand(&mut rng).into_bigint())
|
|
||||
.collect();
|
|
||||
|
|
||||
let mut count = 0;
|
|
||||
b.iter(|| {
|
|
||||
count = (count + 1) % SAMPLES;
|
|
||||
let _ = $f::from(v[count]);
|
|
||||
});
|
|
||||
}
|
|
||||
};
|
|
||||
}
|
|
@ -1,11 +0,0 @@ |
|||||
#[macro_use]
|
|
||||
mod utils;
|
|
||||
|
|
||||
#[macro_use]
|
|
||||
mod ec;
|
|
||||
|
|
||||
#[macro_use]
|
|
||||
mod field;
|
|
||||
|
|
||||
#[macro_use]
|
|
||||
mod pairing;
|
|
@ -1,72 +0,0 @@ |
|||||
#[macro_export]
|
|
||||
macro_rules! pairing_bench {
|
|
||||
($curve:ident, $pairing_field:ident) => {
|
|
||||
fn miller_loop(b: &mut $crate::bencher::Bencher) {
|
|
||||
const SAMPLES: usize = 1000;
|
|
||||
|
|
||||
let mut rng = ark_std::test_rng();
|
|
||||
|
|
||||
let g1s = (0..SAMPLES).map(|_| G1::rand(&mut rng)).collect::<Vec<_>>();
|
|
||||
let g2s = (0..SAMPLES).map(|_| G2::rand(&mut rng)).collect::<Vec<_>>();
|
|
||||
let g1s = G1::batch_normalization_into_affine(&g1s);
|
|
||||
let g2s = G2::batch_normalization_into_affine(&g2s);
|
|
||||
let prepared = g1s
|
|
||||
.into_iter()
|
|
||||
.zip(g2s)
|
|
||||
.map(|(g1, g2)| (g1.into(), g2.into()))
|
|
||||
.collect::<Vec<(
|
|
||||
<$curve as PairingEngine>::G1Prepared,
|
|
||||
<$curve as PairingEngine>::G2Prepared,
|
|
||||
)>>();
|
|
||||
let mut count = 0;
|
|
||||
b.iter(|| {
|
|
||||
let tmp =
|
|
||||
$curve::miller_loop(&[(prepared[count].0.clone(), prepared[count].1.clone())]);
|
|
||||
count = (count + 1) % SAMPLES;
|
|
||||
tmp
|
|
||||
});
|
|
||||
}
|
|
||||
|
|
||||
fn final_exponentiation(b: &mut $crate::bencher::Bencher) {
|
|
||||
const SAMPLES: usize = 1000;
|
|
||||
|
|
||||
let mut rng = ark_std::test_rng();
|
|
||||
|
|
||||
let v: Vec<_> = (0..SAMPLES)
|
|
||||
.map(|_| {
|
|
||||
(
|
|
||||
G1Affine::from(G1::rand(&mut rng)).into(),
|
|
||||
G2Affine::from(G2::rand(&mut rng)).into(),
|
|
||||
)
|
|
||||
})
|
|
||||
.map(|(p, q)| $curve::miller_loop(&[(p, q)]))
|
|
||||
.collect();
|
|
||||
|
|
||||
let mut count = 0;
|
|
||||
b.iter(|| {
|
|
||||
let tmp = $curve::final_exponentiation(&v[count]);
|
|
||||
count = (count + 1) % SAMPLES;
|
|
||||
tmp
|
|
||||
});
|
|
||||
}
|
|
||||
|
|
||||
fn full_pairing(b: &mut $crate::bencher::Bencher) {
|
|
||||
const SAMPLES: usize = 1000;
|
|
||||
|
|
||||
let mut rng = ark_std::test_rng();
|
|
||||
|
|
||||
let v: Vec<(G1, G2)> = (0..SAMPLES)
|
|
||||
.map(|_| (G1::rand(&mut rng), G2::rand(&mut rng)))
|
|
||||
.collect();
|
|
||||
|
|
||||
let mut count = 0;
|
|
||||
b.iter(|| {
|
|
||||
let tmp = $curve::pairing(v[count].0, v[count].1);
|
|
||||
count = (count + 1) % SAMPLES;
|
|
||||
tmp
|
|
||||
});
|
|
||||
}
|
|
||||
|
|
||||
$crate::benchmark_group!(pairing, miller_loop, final_exponentiation, full_pairing,);
|
|
||||
};
|
|
||||
}
|
|
@ -1,36 +0,0 @@ |
|||||
#[macro_export]
|
|
||||
macro_rules! n_fold {
|
|
||||
($tmp:ident, $v:ident, $func:ident, $count:ident) => {
|
|
||||
$tmp.$func(&$v[$count].1);
|
|
||||
};
|
|
||||
|
|
||||
($tmp:ident, $func:ident) => {
|
|
||||
$tmp.$func();
|
|
||||
};
|
|
||||
}
|
|
||||
|
|
||||
/// Defines a function called `$group_name` that returns the test description
|
|
||||
/// values for the listed functions `$function`.
|
|
||||
#[macro_export]
|
|
||||
macro_rules! benchmark_group {
|
|
||||
($group_name:ident, $($function:path),+) => {
|
|
||||
pub fn $group_name() -> ::std::vec::Vec<$crate::TestDescAndFn> {
|
|
||||
use $crate::{TestDescAndFn, TestFn, TestDesc};
|
|
||||
use std::borrow::Cow;
|
|
||||
let mut benches = ::std::vec::Vec::new();
|
|
||||
$(
|
|
||||
benches.push(TestDescAndFn {
|
|
||||
desc: TestDesc {
|
|
||||
name: Cow::from(module_path!().to_string() + "::" + stringify!($function)),
|
|
||||
ignore: false,
|
|
||||
},
|
|
||||
testfn: TestFn::StaticBenchFn($function),
|
|
||||
});
|
|
||||
)+
|
|
||||
benches
|
|
||||
}
|
|
||||
};
|
|
||||
($group_name:ident, $($function:path,)+) => {
|
|
||||
benchmark_group!($group_name, $($function),+);
|
|
||||
};
|
|
||||
}
|
|
@ -0,0 +1 @@ |
|||||
|
../LICENSE-APACHE |
@ -0,0 +1 @@ |
|||||
|
../LICENSE-MIT |
@ -0,0 +1 @@ |
|||||
|
../LICENSE-APACHE |
@ -0,0 +1 @@ |
|||||
|
../LICENSE-MIT |
@ -0,0 +1 @@ |
|||||
|
../LICENSE-APACHE |
@ -0,0 +1 @@ |
|||||
|
../LICENSE-MIT |
@ -0,0 +1 @@ |
|||||
|
../LICENSE-APACHE |
@ -0,0 +1 @@ |
|||||
|
../LICENSE-MIT |
@ -0,0 +1 @@ |
|||||
|
../LICENSE-APACHE |
@ -0,0 +1 @@ |
|||||
|
../LICENSE-MIT |
@ -0,0 +1 @@ |
|||||
|
../LICENSE-APACHE |
@ -0,0 +1 @@ |
|||||
|
../LICENSE-MIT |
@ -0,0 +1 @@ |
|||||
|
../LICENSE-APACHE |
@ -0,0 +1 @@ |
|||||
|
../LICENSE-MIT |
@ -0,0 +1 @@ |
|||||
|
../LICENSE-APACHE |
@ -0,0 +1 @@ |
|||||
|
../LICENSE-MIT |
@ -0,0 +1 @@ |
|||||
|
../LICENSE-APACHE |
@ -0,0 +1 @@ |
|||||
|
../LICENSE-MIT |
@ -0,0 +1 @@ |
|||||
|
../LICENSE-APACHE |
@ -0,0 +1 @@ |
|||||
|
../LICENSE-MIT |