-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a wrapper for prove, verify and param derivation. (#73)
## 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
1 parent
0a9bb44
commit 07db4a9
Showing
3 changed files
with
46 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} | ||
} |