Skip to content

Commit

Permalink
Add a wrapper for prove, verify and param derivation. (#73)
Browse files Browse the repository at this point in the history
## Content

A simple wrapper struct around `prove()` and `verify()` functions and
parameter derivation.

## Pre-submit checklist

- Branch
    - [x] Tests are provided (if possible)
    - [x] Commit sequence broadly makes sense
    - [x] Key commits have useful messages
- PR
    - [x] No clippy warnings in the CI
    - [x] Self-reviewed the diff
    - [x] Useful pull request description
    - [x] Reviewer requested
- Documentation
    - [x] Update README file (if relevant)
    - [x] Update documentation website (if relevant)

## Issue(s)

Relates to #66
  • Loading branch information
tolikzinovyev authored Dec 5, 2024
1 parent 0a9bb44 commit 07db4a9
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 3 deletions.
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 {
/// 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 }
}

/// 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)
}
}

0 comments on commit 07db4a9

Please sign in to comment.