Procházet zdrojové kódy

added prove.out file to debug proof and verify

ada před 5 roky
rodič
revize
cc42e9097d
2 změnil soubory, kde provedl 9 přidání a 10 odebrání
  1. 6 4
      lisp/lisp.rs
  2. 3 6
      lisp/types.rs

+ 6 - 4
lisp/lisp.rs

@@ -4,7 +4,10 @@ use crate::types::LispCircuit;
 use bellman::groth16::PreparedVerifyingKey;
 
 use simplelog::*;
+use sapvi::{BlsStringConversion, Decodable, Encodable, ZKContract, ZKProof};
 
+use std::fs;
+use std::fs::File;
 use bellman::{groth16};
 use bls12_381::Bls12;
 use fnv::FnvHashMap;
@@ -540,9 +543,6 @@ pub fn setup(_ast: MalVal, env: Env) -> Result<PreparedVerifyingKey<Bls12>, MalE
 }
 
 pub fn prove(_ast: MalVal, env: Env) -> MalRet {
-    // TODO remove it
-    let _quantity = bls12_381::Scalar::from(3);
-
     let allocs_input = get_allocations(&env, "AllocationsInput");
     let allocs = get_allocations(&env, "Allocations");
     let enforce_allocs = get_enforce_allocs(&env);
@@ -563,8 +563,10 @@ pub fn prove(_ast: MalVal, env: Env) -> MalRet {
     };
     let start = Instant::now();
     // Create a Groth16 proof with our parameters.
-    let _proof = groth16::create_random_proof(circuit, &params, &mut OsRng).unwrap();
+    let proof = groth16::create_random_proof(circuit, &params, &mut OsRng).unwrap();
     println!("Prove: [{:?}]", start.elapsed());
+    let mut file = File::create("prove.out").unwrap();
+    proof.write(file);
     Ok(MalVal::Nil)
 }
 

+ 3 - 6
lisp/types.rs

@@ -44,7 +44,7 @@ impl Circuit<bls12_381::Scalar> for LispCircuit {
 
         println!("Allocations\n");
         for (k, v) in &self.allocs {
-            // match str
+            println!("k {:?} v {:?}", k, v);
             match v {
                 MalVal::ZKScalar(val) => {
                     let var = cs.alloc(|| "alloc", || Ok(*val))?;
@@ -63,15 +63,15 @@ impl Circuit<bls12_381::Scalar> for LispCircuit {
 
         println!("Allocations Input\n");
         for (k, v) in &self.alloc_inputs {
+            println!("k {:?} v {:?}", k, v);
             match v {
                 MalVal::ZKScalar(val) => {
-                    println!("val {:?}", val);
                     let var = cs.alloc_input(|| "alloc", || Ok(*val))?;
                     variables.insert(k.to_string(), var);
                 }
                 MalVal::Str(val) => {
                     let val_scalar = bls12_381::Scalar::from_string(&*val);
-                    let var = cs.alloc(|| "alloc", || Ok(val_scalar))?;
+                    let var = cs.alloc_input(|| "alloc", || Ok(val_scalar))?;
                     variables.insert(k.to_string(), var);
                 }
                 _ => {
@@ -82,13 +82,11 @@ impl Circuit<bls12_381::Scalar> for LispCircuit {
 
         println!("Enforce Allocations\n");
         for alloc_value in &self.constraints {
-            println!("{:?}", alloc_value);
             let coeff = bls12_381::Scalar::one();
             let mut left = bellman::LinearCombination::<Scalar>::zero();
             let mut right = bellman::LinearCombination::<Scalar>::zero();
             let mut output = bellman::LinearCombination::<Scalar>::zero();
             for values in alloc_value.left.iter() {
-                println!("values {:?}", values);
                 let (a, b) = values;
                 let mut val_b = CS::one();
                 if b != "cs::one" {
@@ -108,7 +106,6 @@ impl Circuit<bls12_381::Scalar> for LispCircuit {
             }
 
             for values in alloc_value.right.iter() {
-                println!("{:?}", values);
                 let (a, b) = values;
                 let mut val_b = CS::one();
                 if b != "cs::one" {