Skip to content
Snippets Groups Projects
Commit 4b193d97 authored by STEVAN Antoine's avatar STEVAN Antoine :crab:
Browse files

bump PLNK to 0.6.0 (dragoon/komodo!85)

this MR
- bumps PLNK to 0.6.0
- update all existing code
- uses the PLNK lib in `examples/benches/commit.rs`
- fixes the y label of the plot in `scripts/plot/bench_commit.py`: was _ns_, should be _ms_
parent a4ef3e2a
No related branches found
No related tags found
No related merge requests found
...@@ -14,7 +14,7 @@ ark-poly = "0.4.2" ...@@ -14,7 +14,7 @@ ark-poly = "0.4.2"
ark-serialize = "0.4.2" ark-serialize = "0.4.2"
ark-std = "0.4.0" ark-std = "0.4.0"
clap = { version = "4.5.4", features = ["derive"] } clap = { version = "4.5.4", features = ["derive"] }
plnk = { git = "https://gitlab.isae-supaero.fr/a.stevan/plnk", tag = "0.3.0", version = "0.3.0" } plnk = { git = "https://gitlab.isae-supaero.fr/a.stevan/plnk", tag = "0.6.0", version = "0.6.0" }
rand = "0.8.5" rand = "0.8.5"
rs_merkle = "1.4.1" rs_merkle = "1.4.1"
thiserror = "1.0.50" thiserror = "1.0.50"
......
...@@ -87,6 +87,8 @@ let res = cargo run --example bench_commit -- --nb-measurements 10 ...$degrees ...@@ -87,6 +87,8 @@ let res = cargo run --example bench_commit -- --nb-measurements 10 ...$degrees
| update times { into duration } | update times { into duration }
| insert mean {|it| $it.times | math avg} | insert mean {|it| $it.times | math avg}
| insert stddev {|it| $it.times | into int | into float | math stddev | into int | into duration} | insert stddev {|it| $it.times | into int | into float | math stddev | into int | into duration}
| update label { parse "degree {d}" | into record | get d | into int }
| rename --column { label: "degree", name: "curve" }
python scripts/plot/bench_commit.py ( python scripts/plot/bench_commit.py (
$res | group-by curve --to-table | update items { reject curve } | to json $res | group-by curve --to-table | update items { reject curve } | to json
......
// see `benches/README.md` // see `benches/README.md`
use std::time::Instant;
use ark_ec::{pairing::Pairing, CurveGroup}; use ark_ec::{pairing::Pairing, CurveGroup};
use ark_ff::PrimeField; use ark_ff::PrimeField;
use ark_poly::{univariate::DensePolynomial, DenseUVPolynomial}; use ark_poly::{univariate::DensePolynomial, DenseUVPolynomial};
...@@ -19,6 +17,7 @@ where ...@@ -19,6 +17,7 @@ where
{ {
eprintln!("curve: {}", curve); eprintln!("curve: {}", curve);
let rng = &mut rand::thread_rng(); let rng = &mut rand::thread_rng();
let b = plnk::Bencher::new(nb_measurements).with_name(curve);
let max_degree = *degrees.iter().max().unwrap_or(&0); let max_degree = *degrees.iter().max().unwrap_or(&0);
...@@ -26,32 +25,12 @@ where ...@@ -26,32 +25,12 @@ where
let setup = zk::setup::<F, G>(max_degree, rng).unwrap(); let setup = zk::setup::<F, G>(max_degree, rng).unwrap();
eprintln!("done"); eprintln!("done");
for (i, degree) in degrees.iter().enumerate() { for degree in degrees {
let mut times = vec![]; plnk::bench(&b, &format!("degree {}", degree), || {
for j in 0..nb_measurements {
eprint!(
" d: {} [{}/{}:{:>5}/{}] \r",
degree,
i + 1,
degrees.len(),
j + 1,
nb_measurements
);
let polynomial = P::rand(*degree, rng); let polynomial = P::rand(*degree, rng);
plnk::timeit(|| zk::commit(&setup, &polynomial))
let start_time = Instant::now(); });
let _ = zk::commit(&setup, &polynomial);
let end_time = Instant::now();
times.push(end_time.duration_since(start_time).as_nanos());
}
println!(
"{{curve: {}, degree: {}, times: {:?}}}",
curve, degree, times,
);
} }
eprintln!();
} }
fn ark_run<E, P>(degrees: &Vec<usize>, curve: &str, nb_measurements: usize) fn ark_run<E, P>(degrees: &Vec<usize>, curve: &str, nb_measurements: usize)
...@@ -62,6 +41,7 @@ where ...@@ -62,6 +41,7 @@ where
{ {
eprintln!("curve: {}", curve); eprintln!("curve: {}", curve);
let rng = &mut rand::thread_rng(); let rng = &mut rand::thread_rng();
let b = plnk::Bencher::new(nb_measurements).with_name(curve);
let max_degree = *degrees.iter().max().unwrap_or(&0); let max_degree = *degrees.iter().max().unwrap_or(&0);
...@@ -79,32 +59,12 @@ where ...@@ -79,32 +59,12 @@ where
}; };
eprintln!("done"); eprintln!("done");
for (i, degree) in degrees.iter().enumerate() { for degree in degrees {
let mut times = vec![]; plnk::bench(&b, &format!("degree {}", degree), || {
for j in 0..nb_measurements {
eprint!(
" d: {} [{}/{}:{:>5}/{}] \r",
degree,
i + 1,
degrees.len(),
j + 1,
nb_measurements
);
let polynomial = P::rand(*degree, rng); let polynomial = P::rand(*degree, rng);
plnk::timeit(|| KZG10::commit(&setup, &polynomial, None, None))
let start_time = Instant::now(); })
let _ = KZG10::commit(&setup, &polynomial, None, None);
let end_time = Instant::now();
times.push(end_time.duration_since(start_time).as_nanos());
}
println!(
"{{curve: {}, degree: {}, times: {:?}}}",
curve, degree, times,
);
} }
eprintln!();
} }
/// ## example /// ## example
......
// see `benches/README.md` // see `benches/README.md`
use std::time::Instant;
use ark_ec::CurveGroup; use ark_ec::CurveGroup;
use ark_ff::PrimeField; use ark_ff::PrimeField;
use clap::{command, Parser}; use clap::{command, Parser};
fn bench_template<F: PrimeField, G: CurveGroup<ScalarField = F>>(b: &mut plnk::Bencher) { fn bench_template<F: PrimeField, G: CurveGroup<ScalarField = F>>(b: &plnk::Bencher) {
plnk::bench(b, "random sampling", |rng| plnk::timeit!((|| G::rand(rng)))); let rng = &mut ark_std::rand::thread_rng();
plnk::bench(b, "random sampling", || plnk::timeit(|| G::rand(rng)));
plnk::bench(b, "addition", |rng| { plnk::bench(b, "addition", || {
let g1 = G::rand(rng); let g1 = G::rand(rng);
let g2 = G::rand(rng); let g2 = G::rand(rng);
plnk::timeit!((|| g1 + g2)) plnk::timeit(|| g1 + g2)
}); });
plnk::bench(b, "substraction", |rng| { plnk::bench(b, "substraction", || {
let g1 = G::rand(rng); let g1 = G::rand(rng);
let g2 = G::rand(rng); let g2 = G::rand(rng);
plnk::timeit!((|| g1 - g2)) plnk::timeit(|| g1 - g2)
}); });
plnk::bench(b, "double", |rng| { plnk::bench(b, "double", || {
let g1 = G::rand(rng); let g1 = G::rand(rng);
plnk::timeit!((|| g1.double())) plnk::timeit(|| g1.double())
}); });
plnk::bench(b, "scalar multiplication", |rng| { plnk::bench(b, "scalar multiplication", || {
let g1 = G::rand(rng); let g1 = G::rand(rng);
let f1 = F::rand(rng); let f1 = F::rand(rng);
plnk::timeit!((|| g1.mul(f1))) plnk::timeit(|| g1.mul(f1))
}); });
plnk::bench(b, "into affine", |rng| { plnk::bench(b, "into affine", || {
let g1 = G::rand(rng); let g1 = G::rand(rng);
plnk::timeit!((|| g1.into_affine())) plnk::timeit(|| g1.into_affine())
}); });
plnk::bench(b, "from affine", |rng| { plnk::bench(b, "from affine", || {
let g1_affine = G::rand(rng).into_affine(); let g1_affine = G::rand(rng).into_affine();
plnk::timeit!((|| Into::<G>::into(g1_affine))) plnk::timeit(|| Into::<G>::into(g1_affine))
}); });
plnk::bench(b, "affine addition", |rng| { plnk::bench(b, "affine addition", || {
let g1_affine = G::rand(rng).into_affine(); let g1_affine = G::rand(rng).into_affine();
let g2_affine = G::rand(rng).into_affine(); let g2_affine = G::rand(rng).into_affine();
plnk::timeit!((|| g1_affine + g2_affine)) plnk::timeit(|| g1_affine + g2_affine)
}); });
plnk::bench(b, "affine scalar multiplication", |rng| { plnk::bench(b, "affine scalar multiplication", || {
let g1_affine = G::rand(rng).into_affine(); let g1_affine = G::rand(rng).into_affine();
let f1 = F::rand(rng); let f1 = F::rand(rng);
plnk::timeit!((|| g1_affine * f1)) plnk::timeit(|| g1_affine * f1)
}); });
} }
...@@ -74,11 +74,11 @@ struct Cli { ...@@ -74,11 +74,11 @@ struct Cli {
fn main() { fn main() {
let cli = Cli::parse(); let cli = Cli::parse();
let bencher = plnk::Bencher::new(cli.nb_measurements, ark_std::rand::thread_rng()); let bencher = plnk::Bencher::new(cli.nb_measurements);
bench_template::<ark_bls12_381::Fr, ark_bls12_381::G1Projective>( bench_template::<ark_bls12_381::Fr, ark_bls12_381::G1Projective>(
&mut bencher.with_name("BLS12-381"), &bencher.with_name("BLS12-381"),
); );
bench_template::<ark_bn254::Fr, ark_bn254::G1Projective>(&mut bencher.with_name("BN-254")); bench_template::<ark_bn254::Fr, ark_bn254::G1Projective>(&bencher.with_name("BN-254"));
bench_template::<ark_pallas::Fr, ark_pallas::Projective>(&mut bencher.with_name("PALLAS")); bench_template::<ark_pallas::Fr, ark_pallas::Projective>(&bencher.with_name("PALLAS"));
} }
// see `benches/README.md` // see `benches/README.md`
use std::time::{Duration, Instant}; use std::time::Duration;
use ark_ff::PrimeField; use ark_ff::PrimeField;
use clap::{arg, command, Parser}; use clap::{arg, command, Parser};
fn bench_template<F: PrimeField>(b: &mut plnk::Bencher) { fn bench_template<F: PrimeField>(b: &plnk::Bencher) {
plnk::bench(b, "random sampling", |rng| plnk::timeit!((|| F::rand(rng)))); let rng = &mut ark_std::rand::thread_rng();
plnk::bench(b, "addition", |rng| { plnk::bench(b, "random sampling", || plnk::timeit(|| F::rand(rng)));
plnk::bench(b, "addition", || {
let f1 = F::rand(rng); let f1 = F::rand(rng);
let f2 = F::rand(rng); let f2 = F::rand(rng);
plnk::timeit!((|| f1 + f2)) plnk::timeit(|| f1 + f2)
}); });
plnk::bench(b, "substraction", |rng| { plnk::bench(b, "substraction", || {
let f1 = F::rand(rng); let f1 = F::rand(rng);
let f2 = F::rand(rng); let f2 = F::rand(rng);
plnk::timeit!((|| f1 - f2)) plnk::timeit(|| f1 - f2)
}); });
plnk::bench(b, "double", |rng| { plnk::bench(b, "double", || {
let f1 = F::rand(rng); let f1 = F::rand(rng);
plnk::timeit!((|| f1.double())) plnk::timeit(|| f1.double())
}); });
plnk::bench(b, "multiplication", |rng| { plnk::bench(b, "multiplication", || {
let f1 = F::rand(rng); let f1 = F::rand(rng);
let f2 = F::rand(rng); let f2 = F::rand(rng);
plnk::timeit!((|| f1 * f2)) plnk::timeit(|| f1 * f2)
}); });
plnk::bench(b, "square", |rng| { plnk::bench(b, "square", || {
let f1 = F::rand(rng); let f1 = F::rand(rng);
plnk::timeit!((|| f1.square())) plnk::timeit(|| f1.square())
}); });
plnk::bench(b, "inverse", |rng| { plnk::bench(b, "inverse", || {
let f1 = F::rand(rng); let f1 = F::rand(rng);
plnk::timeit!((|| f1.inverse())) plnk::timeit(|| f1.inverse())
}); });
plnk::bench(b, "legendre", |rng| { plnk::bench(b, "legendre", || {
let f1 = F::rand(rng); let f1 = F::rand(rng);
plnk::timeit!((|| f1.legendre())) plnk::timeit(|| f1.legendre())
}); });
plnk::bench(b, "sqrt", |rng| { plnk::bench(b, "sqrt", || {
let f1 = F::rand(rng); let f1 = F::rand(rng);
if f1.legendre().is_qr() { if f1.legendre().is_qr() {
plnk::timeit!((|| f1.sqrt())) plnk::timeit(|| f1.sqrt())
} else { } else {
Duration::default() Duration::default()
} }
}); });
plnk::bench(b, "exponentiation", |rng| { plnk::bench(b, "exponentiation", || {
let f1 = F::rand(rng); let f1 = F::rand(rng);
plnk::timeit!((|| f1.pow(F::MODULUS))) plnk::timeit(|| f1.pow(F::MODULUS))
}); });
plnk::bench(b, "into bigint", |rng| { plnk::bench(b, "into bigint", || {
let f1 = F::rand(rng); let f1 = F::rand(rng);
plnk::timeit!((|| f1.into_bigint())) plnk::timeit(|| f1.into_bigint())
}); });
} }
...@@ -86,9 +88,9 @@ struct Cli { ...@@ -86,9 +88,9 @@ struct Cli {
fn main() { fn main() {
let cli = Cli::parse(); let cli = Cli::parse();
let bencher = plnk::Bencher::new(cli.nb_measurements, ark_std::rand::thread_rng()); let bencher = plnk::Bencher::new(cli.nb_measurements);
bench_template::<ark_bls12_381::Fr>(&mut bencher.with_name("BLS12-381")); bench_template::<ark_bls12_381::Fr>(&bencher.with_name("BLS12-381"));
bench_template::<ark_bn254::Fr>(&mut bencher.with_name("BN-254")); bench_template::<ark_bn254::Fr>(&bencher.with_name("BN-254"));
bench_template::<ark_pallas::Fr>(&mut bencher.with_name("PALLAS")); bench_template::<ark_pallas::Fr>(&bencher.with_name("PALLAS"));
} }
...@@ -22,7 +22,7 @@ if __name__ == "__main__": ...@@ -22,7 +22,7 @@ if __name__ == "__main__":
plt.fill_between(xs, down, up, alpha=0.3) plt.fill_between(xs, down, up, alpha=0.3)
plt.xlabel("degree") plt.xlabel("degree")
plt.ylabel("time (in ns)") plt.ylabel("time (in ms)")
plt.title("time to commit polynomials for certain curves") plt.title("time to commit polynomials for certain curves")
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment