You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

90 lines
2.5 KiB

4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
  1. extern crate byteorder;
  2. extern crate core;
  3. extern crate criterion;
  4. extern crate digest;
  5. extern crate libspartan;
  6. extern crate merlin;
  7. extern crate sha3;
  8. use libspartan::{Instance, NIZKGens, NIZK};
  9. use merlin::Transcript;
  10. use criterion::*;
  11. fn nizk_prove_benchmark(c: &mut Criterion) {
  12. for &s in [10, 12, 16].iter() {
  13. let plot_config = PlotConfiguration::default().summary_scale(AxisScale::Logarithmic);
  14. let mut group = c.benchmark_group("NIZK_prove_benchmark");
  15. group.plot_config(plot_config);
  16. let num_vars = (2_usize).pow(s as u32);
  17. let num_cons = num_vars;
  18. let num_inputs = 10;
  19. let (inst, vars, inputs) = Instance::produce_synthetic_r1cs(num_cons, num_vars, num_inputs);
  20. let gens = NIZKGens::new(num_cons, num_vars, num_inputs);
  21. let name = format!("NIZK_prove_{}", num_vars);
  22. group.bench_function(&name, move |b| {
  23. b.iter(|| {
  24. let mut prover_transcript = Transcript::new(b"example");
  25. NIZK::prove(
  26. black_box(&inst),
  27. black_box(vars.clone()),
  28. black_box(&inputs),
  29. black_box(&gens),
  30. black_box(&mut prover_transcript),
  31. );
  32. });
  33. });
  34. group.finish();
  35. }
  36. }
  37. fn nizk_verify_benchmark(c: &mut Criterion) {
  38. for &s in [10, 12, 16].iter() {
  39. let plot_config = PlotConfiguration::default().summary_scale(AxisScale::Logarithmic);
  40. let mut group = c.benchmark_group("NIZK_verify_benchmark");
  41. group.plot_config(plot_config);
  42. let num_vars = (2_usize).pow(s as u32);
  43. let num_cons = num_vars;
  44. let num_inputs = 10;
  45. let (inst, vars, inputs) = Instance::produce_synthetic_r1cs(num_cons, num_vars, num_inputs);
  46. let gens = NIZKGens::new(num_cons, num_vars, num_inputs);
  47. // produce a proof of satisfiability
  48. let mut prover_transcript = Transcript::new(b"example");
  49. let proof = NIZK::prove(&inst, vars, &inputs, &gens, &mut prover_transcript);
  50. let name = format!("NIZK_verify_{}", num_cons);
  51. group.bench_function(&name, move |b| {
  52. b.iter(|| {
  53. let mut verifier_transcript = Transcript::new(b"example");
  54. assert!(proof
  55. .verify(
  56. black_box(&inst),
  57. black_box(&inputs),
  58. black_box(&mut verifier_transcript),
  59. black_box(&gens)
  60. )
  61. .is_ok());
  62. });
  63. });
  64. group.finish();
  65. }
  66. }
  67. fn set_duration() -> Criterion {
  68. Criterion::default().sample_size(10)
  69. }
  70. criterion_group! {
  71. name = benches_nizk;
  72. config = set_duration();
  73. targets = nizk_prove_benchmark, nizk_verify_benchmark
  74. }
  75. criterion_main!(benches_nizk);