Skip to content

Commit

Permalink
Run cube proof in main
Browse files Browse the repository at this point in the history
  • Loading branch information
Jay Graber committed Oct 24, 2018
1 parent a7a9468 commit 12b1746
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 18 deletions.
4 changes: 2 additions & 2 deletions src/cube.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ use self::bellman::groth16::{

// proving that I know x such that x^3 + x + 5 == 35
// Generalized: x^3 + x + 5 == out
struct CubeDemo<E: Engine> {
x: Option<E::Fr>,
pub struct CubeDemo<E: Engine> {
pub x: Option<E::Fr>,
}

impl <E: Engine> Circuit<E> for CubeDemo<E> {
Expand Down
23 changes: 7 additions & 16 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,16 @@ fn main(){
create_random_proof, generate_random_parameters, prepare_verifying_key, verify_proof, Proof,
};

println!("Hello world");
println!("Prove that I know x such that x^3 + x + 5 == 35.");

let rng = &mut thread_rng();

println!("Creating parameters...");

// Create parameters for our circuit
let params = {
let c = multiply::MultiplyDemo::<Bls12> {
a: None,
// make option values as None for these variables, for paramgen
// don't want to bake these nums into parameters
b: None,
c: None
let c = cube::CubeDemo::<Bls12> {
x: None
};

generate_random_parameters(c, rng).unwrap()
Expand All @@ -38,22 +34,17 @@ fn main(){

println!("Creating proofs...");

let public_input = Fr::from_str("21");

// Create an instance of circuit
let c = multiply::MultiplyDemo::<Bls12> {
a: Fr::from_str("7"),
// when creating instance here, pass in Some of actual variables you're using
b: Fr::from_str("3"),
c: public_input
let c = cube::CubeDemo::<Bls12> {
x: Fr::from_str("3")
};

// Create a groth16 proof with our parameters.
let proof = create_random_proof(c, &params, rng).unwrap();

assert!(verify_proof(
&pvk,
&proof,
&[public_input.unwrap()]
&[Fr::from_str("35").unwrap()]
).unwrap());
}

0 comments on commit 12b1746

Please sign in to comment.