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.

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