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

Restruct simple lottery #118

Merged
merged 13 commits into from
Jan 21, 2025
42 changes: 0 additions & 42 deletions src/simple_lottery/algorithm.rs

This file was deleted.

159 changes: 0 additions & 159 deletions src/simple_lottery/init.rs

This file was deleted.

141 changes: 141 additions & 0 deletions src/simple_lottery/lottery.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,141 @@
//! Customer facing Lottery structure
use super::params::Params;
use super::proof::Proof;
use crate::utils::types::Element;

/// The main simple lottery struct with prove and verify functions.
#[derive(Debug, Clone, Copy)]
pub struct Lottery {
params: Params,
}

impl Lottery {
/// Returns a `Lottery` structure from input 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
///
/// # Returns
///
/// A `Lottery` structure
///
/// # Example
///
/// ```
/// use alba::simple_lottery::Lottery;
/// let lottery = Lottery::create(128.0, 128.0, 1_000, 750);
/// ```
pub fn create(
soundness_param: f64,
completeness_param: f64,
set_size: u64,
lower_bound: u64,
) -> Self {
let params = Params::new(soundness_param, completeness_param, set_size, lower_bound);
Self::setup_unsafe(&params)
}

/// Use with caution. Returns a `Lottery` structure from internal
/// parameters without checking
///
/// # Arguments
///
/// * `params` - some Lottery internal parameters
///
/// # Returns
///
/// A `Lottery` structure
///
/// # Example
///
/// ```
/// use alba::simple_lottery::Lottery;
/// use alba::simple_lottery::params::Params;
/// let params = Params {proof_size : 200, lottery_probability: 0.001};
/// let lottery = Lottery::setup_unsafe(&params);
/// ```
pub fn setup_unsafe(params: &Params) -> Self {
Self { params: *params }
}

/// Returns the `Params` structure from the `Lottery` structure
///
/// # Arguments
///
/// * `self` - the current `Lottery` structure
///
/// # Returns
///
/// A `Params` structure
///
/// # Example
///
/// ```
/// use alba::simple_lottery::Lottery;
/// use alba::simple_lottery::params::Params;
/// let lottery = Lottery::create(128.0, 128.0, 1_000, 750);
/// let params = lottery.get_params();
/// ```
pub fn get_params(&self) -> Params {
self.params
}

/// Generates a Lottery proof.
///
/// # Arguments
///
/// * `self` - the current `Lottery` structure
/// * `prover_set` - an array of elements to generate an Alba proof on
///
/// # Returns
///
/// A `Proof` if found, `None` otherwise
///
/// # Example
///
/// ```
/// use alba::simple_lottery::Lottery;
/// let set_size = 200;
/// let lottery = Lottery::create(64.0, 64.0, set_size, 100);
/// let mut prover_set = Vec::new();
/// for i in 0..set_size {
/// prover_set.push([(i % 256) as u8 ;48]);
/// }
/// let proof = lottery.prove(&prover_set).unwrap();
/// ```
pub fn prove(&self, prover_set: &[Element]) -> Option<Proof> {
Proof::new(&self.params, prover_set)
}

/// Verifies a Lottery proof.
///
/// # Arguments
///
/// * `self` - the current `Lottery` structure
/// * `proof` - a Lottery proof
///
/// # Returns
///
/// True if the verification is successful, false otherwise
///
/// # Example
///
/// ```
/// use alba::simple_lottery::Lottery;
/// let set_size = 200;
/// let lottery = Lottery::create(64.0, 64.0, set_size, 100);
/// let mut prover_set = Vec::new();
/// for i in 0..set_size {
/// prover_set.push([(i % 256) as u8 ;48]);
/// }
/// let proof = lottery.prove(&prover_set).unwrap();
/// assert!(lottery.verify(&proof));
/// ```
pub fn verify(&self, proof: &Proof) -> bool {
proof.verify(&self.params)
}
}
10 changes: 2 additions & 8 deletions src/simple_lottery/mod.rs
Original file line number Diff line number Diff line change
@@ -1,17 +1,11 @@
//! 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;

pub mod proof;

mod algorithm;

mod wrapper;
mod lottery;

// Re-exports
pub use wrapper::Wrapper as SimpleLottery;
pub use lottery::Lottery;
Loading
Loading