Created
October 10, 2019 01:45
-
-
Save aleph-v/49166c14dd8304bed6f9809405383d9a to your computer and use it in GitHub Desktop.
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
use zkp_stark::{*, primefield::*}; | |
#[derive(Clone, Debug)] | |
struct Claim { | |
index: usize, | |
value: FieldElement, | |
} | |
#[derive(Clone, Debug)] | |
struct Witness { | |
secret: FieldElement, | |
} | |
impl Verifiable for Claim { | |
fn constraints(&self) -> Constraints { | |
use RationalExpression::*; | |
// Seed | |
let mut seed = self.index.to_be_bytes().to_vec(); | |
seed.extend_from_slice(&self.value.as_montgomery().to_bytes_be()); | |
// Constraint repetitions | |
let trace_length = self.index.next_power_of_two(); | |
let trace_generator = FieldElement::root(trace_length).unwrap(); | |
let g = Constant(trace_generator); | |
let on_row = |index| (X - g.pow(index)).inv(); | |
let every_row = || (X - g.pow(trace_length - 1)) / (X.pow(trace_length) - 1.into()); | |
Constraints::from_expressions((trace_length, 2), seed, vec![ | |
]) | |
.unwrap() | |
} | |
} | |
impl Provable<&Witness> for Claim { | |
fn trace(&self, witness: &Witness) -> TraceTable { | |
let trace_length = self.index.next_power_of_two(); | |
let mut trace = TraceTable::new(trace_length, 2); | |
trace | |
} | |
} | |
fn main() { | |
env_logger::init(); | |
info!("Constructing claim"); | |
let claim = Claim { | |
index: 1000, | |
value: field_element!("0142c45e5d743d10eae7ebb70f1526c65de7dbcdb65b322b6ddc36a812591e8f"), | |
}; | |
info!("Claim: {:?}", claim); | |
info!("Constructing witness"); | |
let witness = Witness { | |
secret: field_element!("cafebabe"), | |
}; | |
info!("Witness: {:?}", witness); | |
// Start timer | |
let start = Instant::now(); | |
info!("Constructing proof..."); | |
let _proof = claim.prove(&witness).unwrap(); | |
// Measure time | |
let duration = start.elapsed(); | |
info!("Time elapsed in proof function is: {:?}", duration); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment