-
Notifications
You must be signed in to change notification settings - Fork 47
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
147 additions
and
132 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,72 @@ | ||
//! Interpreter with enhanced functionality to prove statements. | ||
|
||
#![allow(dead_code)] | ||
#![allow(unused_variables)] | ||
|
||
use super::{serialize_sig, SigmaBoolean, UncheckedSigmaTree, UncheckedTree, UnprovenTree}; | ||
use crate::{ | ||
chain::{ContextExtension, ProverResult}, | ||
eval::{Env, EvalError, Evaluator}, | ||
ErgoTree, ErgoTreeParsingError, | ||
}; | ||
|
||
pub struct TestProver {} | ||
|
||
impl Evaluator for TestProver {} | ||
impl Prover for TestProver {} | ||
|
||
pub enum ProverError { | ||
ErgoTreeError(ErgoTreeParsingError), | ||
EvalError(EvalError), | ||
ReducedToFalse, | ||
} | ||
|
||
impl From<ErgoTreeParsingError> for ProverError { | ||
fn from(err: ErgoTreeParsingError) -> Self { | ||
ProverError::ErgoTreeError(err) | ||
} | ||
} | ||
|
||
pub struct ReductionResult { | ||
sigma_prop: SigmaBoolean, | ||
cost: u64, | ||
} | ||
|
||
pub trait Prover: Evaluator { | ||
fn prove( | ||
&self, | ||
tree: &ErgoTree, | ||
env: &Env, | ||
message: &[u8], | ||
) -> Result<ProverResult, ProverError> { | ||
let expr = tree.proposition()?; | ||
let proof = self | ||
.reduce_to_crypto(expr.as_ref(), env) | ||
.map_err(ProverError::EvalError) | ||
.and_then(|v| match v { | ||
SigmaBoolean::TrivialProp(true) => Ok(UncheckedTree::NoProof), | ||
SigmaBoolean::TrivialProp(false) => Err(ProverError::ReducedToFalse), | ||
sb => { | ||
let tree = self.convert_to_unproven(sb); | ||
let unchecked_tree = self.prove_to_unchecked(tree, message); | ||
Ok(UncheckedTree::UncheckedSigmaTree(unchecked_tree)) | ||
} | ||
}); | ||
proof.map(|v| ProverResult { | ||
proof: serialize_sig(v), | ||
extension: ContextExtension::empty(), | ||
}) | ||
} | ||
|
||
fn convert_to_unproven(&self, sigma_tree: SigmaBoolean) -> UnprovenTree { | ||
todo!() | ||
} | ||
|
||
fn prove_to_unchecked( | ||
&self, | ||
unproven_tree: UnprovenTree, | ||
message: &[u8], | ||
) -> UncheckedSigmaTree { | ||
todo!() | ||
} | ||
} |
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,53 @@ | ||
//! Verifier | ||
|
||
#![allow(dead_code)] | ||
#![allow(unused_variables)] | ||
|
||
use super::SigmaBoolean; | ||
use crate::{ | ||
eval::{Env, EvalError, Evaluator}, | ||
ErgoTree, ErgoTreeParsingError, | ||
}; | ||
|
||
pub enum VerifierError { | ||
ErgoTreeError(ErgoTreeParsingError), | ||
EvalError(EvalError), | ||
} | ||
|
||
impl From<ErgoTreeParsingError> for VerifierError { | ||
fn from(err: ErgoTreeParsingError) -> Self { | ||
VerifierError::ErgoTreeError(err) | ||
} | ||
} | ||
|
||
impl From<EvalError> for VerifierError { | ||
fn from(err: EvalError) -> Self { | ||
VerifierError::EvalError(err) | ||
} | ||
} | ||
|
||
pub struct VerificationResult { | ||
result: bool, | ||
cost: u64, | ||
} | ||
|
||
pub trait Verifier: Evaluator { | ||
fn verify( | ||
&mut self, | ||
tree: &ErgoTree, | ||
env: &Env, | ||
proof: &[u8], | ||
message: &[u8], | ||
) -> Result<VerificationResult, VerifierError> { | ||
let expr = tree.proposition()?; | ||
let cprop = self.reduce_to_crypto(expr.as_ref(), env)?; | ||
let res: bool = match cprop { | ||
SigmaBoolean::TrivialProp(b) => b, | ||
sb => todo!(), | ||
}; | ||
Ok(VerificationResult { | ||
result: res, | ||
cost: 0, | ||
}) | ||
} | ||
} |