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.

94 lines
2.6 KiB

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