Skip to content

Commit

Permalink
Merge branch 'main' into curiecrypt/doc-centralized-param
Browse files Browse the repository at this point in the history
  • Loading branch information
curiecrypt authored Dec 13, 2024
2 parents 44243fb + cb8e08f commit 747148f
Show file tree
Hide file tree
Showing 8 changed files with 106 additions and 4 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ ALBA is an ideal choice for applications that require:
- *Fast proof generation and verification*, such as in blockchain systems or multisignature schemes.
- *Efficient decentralized collaboration*, enabling multiple participants to jointly prove knowledge.
- *Flexibility in tradeoffs*, balancing proof size and communication overhead.

Whether it is for multisignatures, proof-of-stake systems, or secure voting protocols, ALBA provides a robust, scalable, and efficient solution for proving knowledge across diverse use cases.

## Implementation
Expand Down
6 changes: 3 additions & 3 deletions src/centralized_telescope/proof.rs
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
//! ALBA's Proof structure
//! Centralized Telescope Proof structure
#![doc = include_str!("../../docs/centralized_telescope/proof.md")]

use crate::utils::types::Element;

/// Alba proof
/// Centralized Telescope proof
#[derive(Debug, Clone)]
pub struct Proof {
/// Numbers of retries done to find the proof
pub retry_counter: u64,
/// Index of the searched subtree to find the proof
pub search_counter: u64,
/// Sequence of elements from prover set
/// Sequence of elements from prover's set
pub element_sequence: Vec<Element>,
}
2 changes: 1 addition & 1 deletion src/centralized_telescope/wrapper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use super::proof::Proof;
use super::setup::Setup;
use crate::utils::types::Element;

/// The main ALBA struct with prove and verify functions.
/// The main centralized Telescope struct with prove and verify functions.
#[derive(Debug, Clone, Copy)]
pub struct Wrapper {
setup: Setup,
Expand Down
37 changes: 37 additions & 0 deletions src/simple_lottery/algorithm.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
//! Simple lottery prove and verify functions
use super::proof::Proof;
use super::setup::Setup;
use super::types::Hash;
use crate::utils::sample;
use crate::utils::types::Element;
use blake2::{Blake2s256, Digest};

pub(super) fn prove(setup: &Setup, prover_set: &[Element]) -> Option<Proof> {
let mut element_sequence = Vec::with_capacity(setup.proof_size as usize);
for &element in prover_set {
if lottery_hash(setup, element) {
element_sequence.push(element);
}
if prover_set.len() as u64 >= setup.proof_size {
return Some(Proof { element_sequence });
}
}

None
}

pub(super) fn verify(setup: &Setup, proof: &Proof) -> bool {
(proof.element_sequence.len() as u64 == setup.proof_size)
&& proof
.element_sequence
.iter()
.all(|&element| lottery_hash(setup, element))
}

fn lottery_hash(setup: &Setup, element: Element) -> bool {
let mut hasher = Blake2s256::new();
hasher.update(element);
let digest: Hash = hasher.finalize().into();
sample::sample_bernoulli(&digest, setup.lottery_probability)
}
11 changes: 11 additions & 0 deletions src/simple_lottery/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,14 @@ pub mod init;
pub mod params;

pub mod setup;

pub mod proof;

mod types;

mod algorithm;

mod wrapper;

// Re-exports
pub use wrapper::Wrapper as SimpleLottery;
10 changes: 10 additions & 0 deletions src/simple_lottery/proof.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
//! Simple lottery Proof structure
use crate::utils::types::Element;

/// Simple lottery proof
#[derive(Debug, Clone)]
pub struct Proof {
/// Sequence of elements from prover's set
pub element_sequence: Vec<Element>,
}
7 changes: 7 additions & 0 deletions src/simple_lottery/types.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
//! Types specific to simple lottery
/// Digest size for internal hashes
pub(super) const DIGEST_SIZE: usize = 32;

/// Hash type for internal hashes
pub(super) type Hash = [u8; DIGEST_SIZE];
36 changes: 36 additions & 0 deletions src/simple_lottery/wrapper.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
use super::algorithm;
use super::init::make_setup;
use super::params::Params;
use super::proof::Proof;
use super::setup::Setup;
use crate::utils::types::Element;

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

impl Wrapper {
/// Initialize ALBA with `Params`.
pub fn create(params: &Params) -> Self {
let setup = make_setup(params);
Self::create_unsafe(&setup)
}

/// This function is unsafe to use and should be avoided.
/// Initialize ALBA with `Setup`.
pub fn create_unsafe(setup: &Setup) -> Self {
Self { setup: *setup }
}

/// Returns either a `Proof` or `None` if no proof is found.
pub fn prove(&self, prover_set: &[Element]) -> Option<Proof> {
algorithm::prove(&self.setup, prover_set)
}

/// Returns true if and only if the proof is successfully verified.
pub fn verify(&self, proof: &Proof) -> bool {
algorithm::verify(&self.setup, proof)
}
}

0 comments on commit 747148f

Please sign in to comment.