Skip to content

Commit

Permalink
Bench: not using percentages for np & nf
Browse files Browse the repository at this point in the history
  • Loading branch information
rrtoledo committed Jan 17, 2025
1 parent 4b052e7 commit 4747de0
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 43 deletions.
10 changes: 3 additions & 7 deletions benches/centralized_telescope/proof_size.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,13 @@ fn proof_bench(params: &[BenchParam]) {
let params = Params {
soundness_param: param.lambda_sec,
completeness_param: param.lambda_rel,
set_size: param.set_size_percentage,
lower_bound: param.lower_bound_percentage,
set_size: param.set_size,
lower_bound: param.lower_bound,
};
let setup = init::make_setup(&params);
println!(
"{0: <23} | {1: <26} | {2: <14} | {3: <17} | {4: <14}",
param.lambda_sec,
param.lambda_rel,
param.set_size_percentage,
param.lower_bound_percentage,
setup.proof_size
param.lambda_sec, param.lambda_rel, param.set_size, param.lower_bound, setup.proof_size
);
}
}
Expand Down
10 changes: 2 additions & 8 deletions benches/centralized_telescope/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,8 @@ pub fn setup(rng: &mut ChaCha20Rng, params: &BenchParam) -> (Vec<[u8; 32]>, Cent
let params = Params {
soundness_param: params.lambda_sec,
completeness_param: params.lambda_rel,
set_size: params
.set_size_percentage
.saturating_mul(params.total_num_elements)
.div_ceil(100),
lower_bound: params
.lower_bound_percentage
.saturating_mul(params.total_num_elements)
.div_ceil(100),
set_size: params.set_size,
lower_bound: params.lower_bound,
};
let telescope = CentralizedTelescope::create(&params);
(dataset, telescope)
Expand Down
46 changes: 24 additions & 22 deletions benches/common/criterion_helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,25 +21,35 @@ pub mod centralized {
pub total_num_elements: u64,
/// Alba's set_size (np) parameter in percentage of total number of
/// elements of the dataset
pub set_size_percentage: u64,
pub set_size: u64,
/// Alba's lower bound (nf) parameter in percentage of total number of
/// elements of the dataset
pub lower_bound_percentage: u64,
pub lower_bound: u64,
}

impl BenchParam {
/// Helper function creating a Benchmark ID
pub fn bench_id(&self, bench_name: &str, percentage: u64) -> BenchmarkId {
pub fn bench_id(&self, bench_name: &str, truncate: u64) -> BenchmarkId {
let set_size_percentage =
(self.set_size as f32 / self.total_num_elements as f32 * 100.0).round() as u32;
let lower_bound_percentage =
(self.lower_bound as f32 / self.total_num_elements as f32 * 100.0).round() as u32;

// Percentage of |Sp| sent to prover when generating proof
let truncate_percentage =
(truncate as f32 / self.total_num_elements as f32 * 100.0).round() as u32;

BenchmarkId::new(
bench_name,
format!(
"params={{λsec: {}, λrel: {}, |Sp|: {} ({}% sent to prover), n_p: {}, n_f: {}}}",
"\n\tParams{{λsec: {}, λrel: {}, n_p: {} ({}%), n_f: {} ({}%), {}% sent}}",
self.lambda_sec,
self.lambda_rel,
self.total_num_elements,
percentage,
self.set_size_percentage,
self.lower_bound_percentage
self.set_size,
set_size_percentage,
self.lower_bound,
lower_bound_percentage,
truncate_percentage
),
)
}
Expand All @@ -59,16 +69,9 @@ pub mod centralized {
for param in params {
// Benchmark where the prover only has access to np percent elements of Sp,
// i.e. the minimum number of elements such that the soundness is lower than 2^-λ
let low = param
.total_num_elements
.saturating_mul(param.set_size_percentage)
.div_ceil(100);
group.bench_function(
param.bench_id(bench_name, param.set_size_percentage),
move |b| {
b.iter_custom(|n| f(param, low, n));
},
);
group.bench_function(param.bench_id(bench_name, param.set_size), move |b| {
b.iter_custom(|n| f(param, param.set_size, n));
});

// Extra benchmarks to show the proving time and number of steps
// when giving more than set_size_percentage elements to the prover.
Expand All @@ -77,14 +80,13 @@ pub mod centralized {
// Uncomment the following lines to run these extra benchmarks.

// // Benchmark where the prover only has access to (np+100)/2 percent elements of Sp
// let mean = param.set_size_percentage.saturating_add(100).div_ceil(2);
// let mid: u64 = param.total_num_elements.saturating_add(low).div_ceil(2);
// group.bench_function(param.bench_id(bench_name, mean), move |b| {
// let mid: u64 = param.total_num_elements.saturating_add(param.set_size).div_ceil(2);
// group.bench_function(param.bench_id(bench_name, mid), move |b| {
// b.iter_custom(|n| f(param, mid, n));
// });

// // Benchmark where the prover only has access to all elements of Sp
// group.bench_function(param.bench_id(bench_name, 100), move |b| {
// group.bench_function(param.bench_id(bench_name, param.total_num_elements), move |b| {
// b.iter_custom(|n| f(param, param.total_num_elements, n));
// });
}
Expand Down
12 changes: 6 additions & 6 deletions benches/common/test_vectors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,26 +9,26 @@ pub mod centralized {
lambda_sec: 64.0,
lambda_rel: 64.0,
total_num_elements: 1_000,
set_size_percentage: 90,
lower_bound_percentage: 60,
set_size: 900,
lower_bound: 600,
};

/// This case corresponds to medium security requirements with more realistic set_size
const MID_PARAM: BenchParam = BenchParam {
lambda_sec: 80.0,
lambda_rel: 80.0,
total_num_elements: 1_000,
set_size_percentage: 80,
lower_bound_percentage: 60,
set_size: 800,
lower_bound: 600,
};

/// This case corresponds to high security requirements with more realistic set_size
const HIGH_PARAM: BenchParam = BenchParam {
lambda_sec: 128.0,
lambda_rel: 128.0,
total_num_elements: 1_000,
set_size_percentage: 80,
lower_bound_percentage: 67,
set_size: 800,
lower_bound: 670,
};

pub const SHORT_TESTS: &[BenchParam; 2] = &[LOW_PARAM, MID_PARAM];
Expand Down

0 comments on commit 4747de0

Please sign in to comment.