فهرست منبع

jj mul + double same circuit 1

ada 5 سال پیش
والد
کامیت
f1d5b4d632
3فایلهای تغییر یافته به همراه23 افزوده شده و 19 حذف شده
  1. 20 16
      lisp/lisp.rs
  2. 1 1
      lisp/run.sh
  3. 2 2
      lisp/types.rs

+ 20 - 16
lisp/lisp.rs

@@ -168,7 +168,9 @@ fn eval(mut ast: MalVal, mut env: Env) -> MalRet {
                         env_set(&env, l[1].clone(), eval(l[2].clone(), env.clone())?)
                         env_set(&env, l[1].clone(), eval(l[2].clone(), env.clone())?)
                     }
                     }
                     Sym(ref a0sym) if a0sym == "let*" => {
                     Sym(ref a0sym) if a0sym == "let*" => {
-                        env = env_new(Some(env.clone()));
+                        // TODO let should be restored to the first purpose
+                        // and the new let* without an env creation should be availaable
+                        //                        env = env_new(Some(env.clone()));
                         let (a1, a2) = (l[1].clone(), l[2].clone());
                         let (a1, a2) = (l[1].clone(), l[2].clone());
                         match a1 {
                         match a1 {
                             List(ref binds, _) | Vector(ref binds, _) => {
                             List(ref binds, _) | Vector(ref binds, _) => {
@@ -427,7 +429,7 @@ fn eval(mut ast: MalVal, mut env: Env) -> MalRet {
                             output: out_vec,
                             output: out_vec,
                         };
                         };
                         let mut new_vec: Vec<EnforceAllocation> = vec![enforce];
                         let mut new_vec: Vec<EnforceAllocation> = vec![enforce];
-                        for value in enforce_vec.iter() { 
+                        for value in enforce_vec.iter() {
                             new_vec.push(value.clone());
                             new_vec.push(value.clone());
                         }
                         }
                         env_set(
                         env_set(
@@ -547,12 +549,12 @@ pub fn prove(_ast: MalVal, env: Env) -> MalRet {
     let allocs_const = get_allocations(&env, "AllocationsConst");
     let allocs_const = get_allocations(&env, "AllocationsConst");
     //setup
     //setup
     let params = Some({
     let params = Some({
-    let circuit = LispCircuit {
-        params: allocs_const.as_ref().clone(),
-        allocs: allocs.as_ref().clone(),
-        alloc_inputs: allocs_input.as_ref().clone(),
-        constraints: enforce_allocs.clone(),
-    };
+        let circuit = LispCircuit {
+            params: allocs_const.as_ref().clone(),
+            allocs: allocs.as_ref().clone(),
+            alloc_inputs: allocs_input.as_ref().clone(),
+            constraints: enforce_allocs.clone(),
+        };
         groth16::generate_random_parameters::<Bls12, _, _>(circuit, &mut OsRng)?
         groth16::generate_random_parameters::<Bls12, _, _>(circuit, &mut OsRng)?
     });
     });
     let verifying_key = Some(groth16::prepare_verifying_key(&params.as_ref().unwrap().vk));
     let verifying_key = Some(groth16::prepare_verifying_key(&params.as_ref().unwrap().vk));
@@ -568,15 +570,17 @@ pub fn prove(_ast: MalVal, env: Env) -> MalRet {
     let mut vec_input = vec![];
     let mut vec_input = vec![];
     for (k, val) in allocs_input.iter() {
     for (k, val) in allocs_input.iter() {
         println!("{:?}", val);
         println!("{:?}", val);
-        if let MalVal::Str(v) = val {
-            vec_input.push(bls12_381::Scalar::from_string(&v.to_string()));
-        }
+        match val {
+            MalVal::Str(v) => {
+                vec_input.push(bls12_381::Scalar::from_string(&v.to_string()));
+            }
+            MalVal::ZKScalar(v) => {
+                vec_input.push(bls12_381::Scalar::from(*v));
+            }
+            _ => {}
+        };
     }
     }
-    let result = groth16::verify_proof(
-        verifying_key.as_ref().unwrap(),
-        &proof,
-        &vec_input,
-    );
+    let result = groth16::verify_proof(verifying_key.as_ref().unwrap(), &proof, &vec_input);
     println!("{:?}", result);
     println!("{:?}", result);
     println!("vec public {:?}", vec_input);
     println!("vec public {:?}", vec_input);
 
 

+ 1 - 1
lisp/run.sh

@@ -1,3 +1,3 @@
 export RUST_BACKTRACE=full
 export RUST_BACKTRACE=full
-cargo run --bin lisp load jubjub-add.lisp
+cargo run --bin lisp load jubjub-mul.lisp
 #cargo run --bin lisp load new-cs.lisp
 #cargo run --bin lisp load new-cs.lisp

+ 2 - 2
lisp/types.rs

@@ -38,7 +38,7 @@ pub struct LispCircuit {
     pub params: FnvHashMap<String, MalVal>,
     pub params: FnvHashMap<String, MalVal>,
     pub allocs: FnvHashMap<String, MalVal>,
     pub allocs: FnvHashMap<String, MalVal>,
     pub alloc_inputs: FnvHashMap<String, MalVal>,
     pub alloc_inputs: FnvHashMap<String, MalVal>,
-//    todo change this for a ordered data structure so enforce 
+    //    todo change this for a ordered data structure so enforce
     pub constraints: Vec<EnforceAllocation>,
     pub constraints: Vec<EnforceAllocation>,
 }
 }
 
 
@@ -118,7 +118,7 @@ impl Circuit<bls12_381::Scalar> for LispCircuit {
 
 
         println!("Enforce Allocations\n");
         println!("Enforce Allocations\n");
         let mut enforce_sorted = self.constraints.clone();
         let mut enforce_sorted = self.constraints.clone();
-        enforce_sorted.sort_by(|a, b| a.idx.cmp(&b.idx)); 
+        enforce_sorted.sort_by(|a, b| a.idx.cmp(&b.idx));
         for alloc_value in enforce_sorted.iter() {
         for alloc_value in enforce_sorted.iter() {
             println!("Enforce -> {:?}", alloc_value);
             println!("Enforce -> {:?}", alloc_value);
             let coeff = bls12_381::Scalar::one();
             let coeff = bls12_381::Scalar::one();