Skip to content

Commit

Permalink
Adding from_unsafe, checking in from
Browse files Browse the repository at this point in the history
  • Loading branch information
rrtoledo committed Nov 26, 2024
1 parent 34b75fc commit 757e4ac
Showing 1 changed file with 166 additions and 2 deletions.
168 changes: 166 additions & 2 deletions src/centralized_telescope/telescope.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//! Customer facing Telescope structure
use super::params::Params;
use super::params::{Case, Cases, High, Mid, Params, Small};
use super::proof::Proof;
use super::round::Round;

Expand Down Expand Up @@ -56,7 +56,9 @@ impl Telescope {
}
}

/// Returns a Telescope structure from input and internal parameters, to use for backward compability
/// Returns a Telescope structure from input and internal parameters, to
/// use for backward compability if the parameters verifies the paper
/// bounds, otherwise None
///
/// # Arguments
///
Expand Down Expand Up @@ -84,6 +86,168 @@ impl Telescope {
set_size: u64,
lower_bound: u64,
params: Params,
) -> Option<Self> {
let proof_size_f64 = params.proof_size as f64;

let bool = match Cases::which(completeness_param, set_size, proof_size_f64 as u64) {
Cases::Small => {
let small = Small::new(completeness_param, set_size, proof_size_f64);
Self::check_from(
soundness_param,
completeness_param,
set_size,
lower_bound,
params,
&small,
)
}
Cases::Mid => {
let mid = Mid::new(completeness_param, set_size, proof_size_f64);
Self::check_from(
soundness_param,
completeness_param,
set_size,
lower_bound,
params,
&mid,
)
}
Cases::High => {
let high = High::new(completeness_param, set_size, proof_size_f64);
Self::check_from(
soundness_param,
completeness_param,
set_size,
lower_bound,
params,
&high,
)
}
};

bool.then_some(Telescope {
soundness_param,
completeness_param,
set_size,
lower_bound,
params,
})
}

fn check_from(
soundness_param: f64,
completeness_param: f64,
set_size: u64,
lower_bound: u64,
params: Params,
case: &impl Case,
) -> bool {
fn completeness_error(u: f64, d: u64, q: f64) -> f64 {
(-(q - u * q * q / 2.0) * d as f64).exp()
}
fn soundness_error(np: u64, nf: u64, u: f64, d: u64, q: f64) -> f64 {
(nf as f64 / np as f64).powf(u) * d as f64 * q
}
let mut bool = true;

// Checks the proof size given is at least as big as one computed from user parameters
let proof_size = params.proof_size as f64;
if Params::proof_size(
soundness_param,
completeness_param,
set_size as f64,
lower_bound as f64,
) > proof_size
{
bool = false;
}

// Check that the number of max retries is at least as big as one
// computed from given user parameters
if case.max_retries() > params.max_retries {
bool = false;
}

// Check that the search width is at least as big as the one computed
// from given user parameters and given proof size
let search_width = case.search_width(proof_size);
if search_width > params.search_width {
bool = false;
};

// Check that the valid proof probability is close enough from the one
// computed from the given user and internal parameters
let error = 8f64.recip();
let valid_proof_probability = case.valid_proof_probability(params.search_width);
// Checking the completness error difference is bounded by the error
if (completeness_error(proof_size, params.search_width, valid_proof_probability)
/ completeness_error( proof_size, search_width, params.valid_proof_probability))
.log2() // Computes log2(2^-l1 / 2^-l2) = (-l1) - (-l2)
.abs() // Computes |l1 - l2|
> error
{
bool = false;
};
// Checking the soundness error difference is bounded by the error
if (soundness_error(
set_size,
lower_bound,
proof_size,
params.search_width,
params.valid_proof_probability,
) / soundness_error(
set_size,
lower_bound,
proof_size,
params.search_width,
valid_proof_probability,
))
.log2()// Computes log2(2^-l1 / 2^-l2) = (-l1) - (-l2)
.abs() // Computes |l1 - l2|
> error
{
bool = false;
}

// Check that the DFS bound is at least as big as the one given by the user and internal parametesr.
let dfs_bound = case.dfs_bound(proof_size, search_width);
if dfs_bound > params.dfs_bound {
bool = false;
};

bool
}

/// Use with caution. Returns a Telescope structure from input and internal
/// parameters, to use for backward compability without checking the
/// consistency between input and internal parameters.
///
/// # Arguments
///
/// * `soundness_param` - the protocol soundness parameter, typically set at 128
/// * `completeness_param` - the protocol completeness parameter, typically set at 128
/// * `set_size` - the size of the prover set to lower bound
/// * `lower_bound` - the lower bound to prove
/// * `params` - some centralized Telescope internal parameters
///
/// # Returns
///
/// A Telescope structure
///
/// # Example
///
/// ```
/// use alba::centralized_telescope::telescope::Telescope;
/// use alba::centralized_telescope::params::Params;
/// let params = Params {proof_size : 200, max_retries: 128, search_width: 10, valid_proof_probability: 0.001, dfs_bound: 40_000};
/// let telescope = Telescope::from(128.0, 128.0, 1_000, 750, params);
/// ```
pub fn from_unsafe(
soundness_param: f64,
completeness_param: f64,
set_size: u64,
lower_bound: u64,
params: Params,
) -> Self {
Telescope {
soundness_param,
Expand Down

0 comments on commit 757e4ac

Please sign in to comment.