Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement parameter derivation for simple lottery. #63

Merged
merged 8 commits into from
Dec 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ rand_core = "0.6.4"

[dev-dependencies]
rand_chacha = "0.3.1"
test-case = "3.3.1"

[lints.rust]
missing-copy-implementations = "warn"
Expand Down
137 changes: 137 additions & 0 deletions src/simple_lottery/init.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
//! Parameter derivation for simple lottery.

use super::params::Params;
use super::setup::Setup;

use std::f64::consts::LN_2;

/// Calculates Setup parameters.
pub fn make_setup(params: &Params) -> Setup {
tolikzinovyev marked this conversation as resolved.
Show resolved Hide resolved
// The following follows section 4.1 of the ALBA paper. https://eprint.iacr.org/2023/1655

let ratio = params.set_size as f64 / params.lower_bound as f64;

// Execute binary search for the optimal value of `rs` in the interval
// ]1.0, ratio[.

let mut left: f64 = 1.0;
let mut right: f64 = ratio;

loop {
tolikzinovyev marked this conversation as resolved.
Show resolved Hide resolved
let middle = (left + right) / 2.0;
let ratio_soundness = middle; // rs
let ratio_completeness = ratio / ratio_soundness; // rc

let bound_soundness =
params.soundness_param * LN_2 / (ratio_soundness.ln() - 1.0 + 1.0 / ratio_soundness);
let bound_completess =
params.completeness_param * LN_2 / (ratio_completeness - 1.0 - ratio_completeness.ln());

rrtoledo marked this conversation as resolved.
Show resolved Hide resolved
if (middle <= left) || (middle >= right) {
let u = bound_soundness.max(bound_completess).ceil();
let mu = u * ratio_completeness;
return Setup {
proof_size: u as u64,
lottery_probability: mu / params.set_size as f64,
};
}

if bound_soundness > bound_completess {
left = middle;
} else {
right = middle;
}
}
}

#[cfg(test)]
mod tests {
use super::super::params::Params;
use super::make_setup;
use test_case::test_case;

#[derive(Debug, Clone, Copy)]
struct Expected {
u: u64, // proof size
mu_lb: f64, // average communication lower bound
mu_ub: f64, // average communication upper bound
}

#[test_case(
Params {
soundness_param: 128.0,
completeness_param: 128.0,
set_size: 200,
lower_bound: 100,
},
Expected {
u: 1488,
mu_lb: 2062.806,
mu_ub: 2062.807,
};
"basic"
)]
#[test_case(
Params {
soundness_param: 128.0,
completeness_param: 64.0,
set_size: 200,
lower_bound: 100,
},
Expected {
u: 1127,
mu_lb: 1473.574,
mu_ub: 1473.575,
};
"different_lambdas"
)]
#[test_case(
Params {
soundness_param: 128.0,
completeness_param: 128.0,
set_size: 150,
lower_bound: 100,
},
Expected {
u: 4328,
mu_lb: 5264.558,
mu_ub: 5264.559,
};
"fractional_ratio"
)]
#[test_case(
Params {
soundness_param: 128.0,
completeness_param: 1.0,
set_size: 200,
lower_bound: 100,
},
Expected {
u: 527,
mu_lb: 554.495,
mu_ub: 554.496,
};
"small_lambda_reliability"
)]
#[test_case(
Params {
soundness_param: 1.0,
completeness_param: 128.0,
set_size: 200,
lower_bound: 100,
},
Expected {
u: 358,
mu_lb: 672.362,
mu_ub: 672.363,
};
"small_lambda_security"
)]
fn all(params: Params, expected: Expected) {
let setup = make_setup(&params);
assert_eq!(expected.u, setup.proof_size);
let mu = setup.lottery_probability * params.set_size as f64;
tolikzinovyev marked this conversation as resolved.
Show resolved Hide resolved
assert!(mu > expected.mu_lb);
assert!(mu < expected.mu_ub);
}
}
4 changes: 4 additions & 0 deletions src/simple_lottery/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
//! Simple lottery construction for the Telescope ALBA scheme.
//! Covering the Section 4.1 of the paper.

pub mod init;

pub mod params;

pub mod setup;
14 changes: 14 additions & 0 deletions src/simple_lottery/params.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
//! Simple lottery Params struct

/// Setup input parameters
#[derive(Debug, Clone, Copy)]
pub struct Params {
/// Soundness security parameter
pub soundness_param: f64,
/// Completeness security parameter
pub completeness_param: f64,
/// Approximate size of the prover set to lower bound
pub set_size: u64,
/// Lower bound to prove on prover set
pub lower_bound: u64,
}
Loading