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

Add a wrapper for prove, verify and param derivation. #73

Merged
merged 4 commits into from
Dec 5, 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
4 changes: 2 additions & 2 deletions src/centralized_telescope/algorithm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@ use blake2::{Blake2s256, Digest};
/// Alba's proving algorithm, based on a depth-first search algorithm.
/// Calls up to setup.max_retries times the prove_index function and returns an empty
/// proof if no suitable candidate is found.
pub fn prove(setup: &Setup, prover_set: &[Element]) -> Option<Proof> {
pub(super) fn prove(setup: &Setup, prover_set: &[Element]) -> Option<Proof> {
// Run prove_index up to max_retries times
(0..setup.max_retries).find_map(|retry_counter| prove_index(setup, prover_set, retry_counter).1)
}

/// Alba's verification algorithm, returns true if the proof is
/// successfully verified, following the DFS verification, false otherwise.
pub fn verify(setup: &Setup, proof: &Proof) -> bool {
pub(super) fn verify(setup: &Setup, proof: &Proof) -> bool {
if proof.search_counter >= setup.search_width
|| proof.retry_counter >= setup.max_retries
|| proof.element_sequence.len() as u64 != setup.proof_size
Expand Down
7 changes: 6 additions & 1 deletion src/centralized_telescope/mod.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//! ALBA's bounded DFS scheme using Blake2b as hash function.
//! (c.f. Section 3.2.2 of Alba paper)

pub mod algorithm;
mod algorithm;

pub mod init;

Expand All @@ -14,3 +14,8 @@ mod round;
pub mod setup;

mod types;

mod wrapper;

// Re-exports
pub use wrapper::Wrapper as CentralizedTelescope;
38 changes: 38 additions & 0 deletions src/centralized_telescope/wrapper.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
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 ALBA struct with prove and verify functions.
#[derive(Debug, Clone, Copy)]
pub struct Wrapper {
setup: Setup,
}

impl Wrapper {
tolikzinovyev marked this conversation as resolved.
Show resolved Hide resolved
/// Initialize ALBA with `Params`.
tolikzinovyev marked this conversation as resolved.
Show resolved Hide resolved
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 }
}

/// Alba's proving algorithm, based on a depth-first search algorithm.
/// 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)
}

/// Alba's verification algorithm.
/// Returns true if and only if the proof is successfully verified.
pub fn verify(&self, proof: &Proof) -> bool {
algorithm::verify(&self.setup, proof)
}
}
tolikzinovyev marked this conversation as resolved.
Show resolved Hide resolved
Loading