diff --git a/benches/criterion_benches.rs b/benches/criterion_benches.rs index 018d5cdf..9b95c9c9 100644 --- a/benches/criterion_benches.rs +++ b/benches/criterion_benches.rs @@ -8,14 +8,14 @@ //! long (see large_input_benches.rs). use std::path::Path; +use std::str::FromStr; use criterion::measurement::Measurement; use criterion::{criterion_group, criterion_main}; use criterion::{BenchmarkId, Criterion, SamplingMode}; use statistical::*; -use dapol::accumulators::{NdmSmt, NdmSmtConfigBuilder}; -use dapol::{Accumulator, InclusionProof}; +use dapol::{DapolConfigBuilder, DapolTree, InclusionProof, Secret}; mod inputs; use inputs::{max_thread_counts_greater_than, num_entities_in_range, tree_heights_in_range}; @@ -43,6 +43,8 @@ pub fn bench_build_tree(c: &mut Criterion) { let epoch = jemalloc_ctl::epoch::mib().unwrap(); let allocated = jemalloc_ctl::stats::allocated::mib().unwrap(); + let master_secret = Secret::from_str("secret").unwrap(); + dapol::initialize_machine_parallelism(); dapol::utils::activate_logging(*LOG_VERBOSITY); @@ -103,7 +105,7 @@ pub fn bench_build_tree(c: &mut Criterion) { // Tree build. let mut memory_readings = vec![]; - let mut ndm_smt = Option::::None; + let mut dapol_tree = Option::::None; group.bench_with_input( BenchmarkId::new( @@ -119,17 +121,20 @@ pub fn bench_build_tree(c: &mut Criterion) { |bench, tup| { bench.iter(|| { // this is necessary for the memory readings to work - ndm_smt = None; + dapol_tree = None; epoch.advance().unwrap(); let before = allocated.read().unwrap(); - ndm_smt = Some( - NdmSmtConfigBuilder::default() + dapol_tree = Some( + DapolConfigBuilder::default() + .accumulator_type(dapol::AccumulatorType::NdmSmt) .height(tup.0) .max_thread_count(tup.1) .num_random_entities(tup.2) + .master_secret(master_secret.clone()) .build() + .expect("Unable to build DapolConfig") .parse() .expect("Unable to parse NdmSmtConfig"), ); @@ -160,8 +165,8 @@ pub fn bench_build_tree(c: &mut Criterion) { let src_dir = env!("CARGO_MANIFEST_DIR"); let target_dir = Path::new(&src_dir).join("target"); let dir = target_dir.join("serialized_trees"); - let path = Accumulator::parse_accumulator_serialization_path(dir).unwrap(); - let acc = Accumulator::NdmSmt(ndm_smt.expect("Tree should have been built")); + let path = DapolTree::parse_serialization_path(dir).unwrap(); + let tree = dapol_tree.expect("Tree should have been built"); group.bench_function( BenchmarkId::new( @@ -174,7 +179,7 @@ pub fn bench_build_tree(c: &mut Criterion) { ), ), |bench| { - bench.iter(|| acc.serialize(path.clone()).unwrap()); + bench.iter(|| tree.serialize(path.clone()).unwrap()); }, ); @@ -196,6 +201,8 @@ pub fn bench_build_tree(c: &mut Criterion) { pub fn bench_generate_proof(c: &mut Criterion) { let mut group = c.benchmark_group("proofs"); + let master_secret = Secret::from_str("secret").unwrap(); + dapol::initialize_machine_parallelism(); dapol::utils::activate_logging(*LOG_VERBOSITY); @@ -241,15 +248,19 @@ pub fn bench_generate_proof(c: &mut Criterion) { continue; } - let ndm_smt = NdmSmtConfigBuilder::default() + let dapol_tree = DapolConfigBuilder::default() + .accumulator_type(dapol::AccumulatorType::NdmSmt) + .master_secret(master_secret.clone()) .height(h) .num_random_entities(n) .build() + .expect("Unable to build DapolConfig") .parse() .expect("Unable to parse NdmSmtConfig"); - let entity_id = ndm_smt + let entity_id = dapol_tree .entity_mapping() + .unwrap() .keys() .next() .expect("Tree should have at least 1 entity"); @@ -264,7 +275,7 @@ pub fn bench_generate_proof(c: &mut Criterion) { |bench| { bench.iter(|| { proof = Some( - ndm_smt + dapol_tree .generate_inclusion_proof(entity_id) .expect("Proof should have been generated successfully"), ); @@ -299,6 +310,8 @@ pub fn bench_generate_proof(c: &mut Criterion) { pub fn bench_verify_proof(c: &mut Criterion) { let mut group = c.benchmark_group("proofs"); + let master_secret = Secret::from_str("secret").unwrap(); + dapol::initialize_machine_parallelism(); dapol::utils::activate_logging(*LOG_VERBOSITY); @@ -344,22 +357,26 @@ pub fn bench_verify_proof(c: &mut Criterion) { continue; } - let ndm_smt = NdmSmtConfigBuilder::default() + let dapol_tree = DapolConfigBuilder::default() + .accumulator_type(dapol::AccumulatorType::NdmSmt) + .master_secret(master_secret.clone()) .height(h) .num_random_entities(n) .build() + .expect("Unable to build DapolConfig") .parse() .expect("Unable to parse NdmSmtConfig"); - let root_hash = ndm_smt.root_hash(); + let root_hash = dapol_tree.root_hash(); - let entity_id = ndm_smt + let entity_id = dapol_tree .entity_mapping() + .unwrap() .keys() .next() .expect("Tree should have at least 1 entity"); - let proof = ndm_smt + let proof = dapol_tree .generate_inclusion_proof(entity_id) .expect("Proof should have been generated successfully"); diff --git a/benches/manual_benches.rs b/benches/manual_benches.rs index 6bd2bd11..34e15858 100644 --- a/benches/manual_benches.rs +++ b/benches/manual_benches.rs @@ -6,11 +6,12 @@ //! unfortunately, but this is the trade-off. use std::path::Path; +use std::str::FromStr; use std::time::Instant; use statistical::*; -use dapol::accumulators::{Accumulator, NdmSmt, NdmSmtConfigBuilder}; +use dapol::{DapolConfigBuilder, DapolTree, Secret}; mod inputs; use inputs::{max_thread_counts_greater_than, num_entities_in_range, tree_heights_in_range}; @@ -36,6 +37,8 @@ fn main() { let total_mem = system_total_memory_mb(); + let master_secret = Secret::from_str("secret").unwrap(); + dapol::initialize_machine_parallelism(); dapol::utils::activate_logging(*LOG_VERBOSITY); @@ -100,14 +103,14 @@ fn main() { // ============================================================== // Tree build. - let mut ndm_smt = Option::::None; + let mut dapol_tree = Option::::None; let mut memory_readings = vec![]; let mut timings = vec![]; // Do 3 readings (Criterion does 10 minimum). for _i in 0..3 { // this is necessary for the memory readings to work - ndm_smt = None; + dapol_tree = None; println!( "building tree i {} time {}", @@ -119,14 +122,17 @@ fn main() { let mem_before = allocated.read().unwrap(); let time_start = Instant::now(); - ndm_smt = Some( - NdmSmtConfigBuilder::default() + dapol_tree = Some( + DapolConfigBuilder::default() + .accumulator_type(dapol::AccumulatorType::NdmSmt) .height(h) .max_thread_count(t) + .master_secret(master_secret.clone()) .num_random_entities(n) .build() + .expect("Unable to build DapolConfig") .parse() - .expect("Unable to parse NdmSmtConfig"), + .expect("Unable to parse DapolConfig"), ); let tree_build_time = time_start.elapsed(); @@ -154,12 +160,13 @@ fn main() { let src_dir = env!("CARGO_MANIFEST_DIR"); let target_dir = Path::new(&src_dir).join("target"); let dir = target_dir.join("serialized_trees"); - let path = Accumulator::parse_accumulator_serialization_path(dir).unwrap(); - let acc = - Accumulator::NdmSmt(ndm_smt.expect("NDM SMT should have been set in loop")); + let path = DapolTree::parse_serialization_path(dir).unwrap(); let time_start = Instant::now(); - acc.serialize(path.clone()).unwrap(); + dapol_tree + .expect("DapolTree should have been set in loop") + .serialize(path.clone()) + .unwrap(); let serialization_time = time_start.elapsed(); let file_size = std::fs::metadata(path)