Просмотр исходного кода

lisp circuit print allocs and enforce

ada 5 лет назад
Родитель
Сommit
bc31a6e538
3 измененных файлов с 27 добавлено и 19 удалено
  1. 14 16
      lisp/lisp.rs
  2. 2 2
      lisp/new-cs.lisp
  3. 11 1
      lisp/types.rs

+ 14 - 16
lisp/lisp.rs

@@ -307,8 +307,8 @@ fn eval(mut ast: MalVal, mut env: Env) -> MalRet {
                         continue 'tco;
                         continue 'tco;
                     }
                     }
                     Sym(ref a0sym) if a0sym == "prove" => {
                     Sym(ref a0sym) if a0sym == "prove" => {
-                        let a1 = l[0].clone();
-                        println!("prove {:?}", a1);
+                        let a1 = l[1].clone();
+                        ast = eval(a1.clone(), env.clone())?;
                         prove(a1.clone(), env.clone())
                         prove(a1.clone(), env.clone())
                     }
                     }
                     Sym(ref a0sym) if a0sym == "alloc-input" => {
                     Sym(ref a0sym) if a0sym == "alloc-input" => {
@@ -534,25 +534,23 @@ pub fn prove(_ast: MalVal, env: Env) -> MalRet {
     // TODO remove it
     // TODO remove it
     let _quantity = bls12_381::Scalar::from(3);
     let _quantity = bls12_381::Scalar::from(3);
 
 
-    // Create an instance of our circuit (with the preimage as a witness).
-    let params = {
-        let c = LispCircuit {
-            params: vec![],
-            allocs: FnvHashMap::default(),
-            alloc_inputs: FnvHashMap::default(),
-            constraints: vec![],
-            env: env.clone(),
-        };
-        groth16::generate_random_parameters::<Bls12, _, _>(c, &mut OsRng).unwrap()
-    };
+    let allocs_input = get_allocations(&env, "AllocationsInput");
+    let allocs = get_allocations(&env, "Allocations");
+    let enforce_allocs = get_enforce_allocs(&env);
 
 
     let circuit = LispCircuit {
     let circuit = LispCircuit {
         params: vec![],
         params: vec![],
-        allocs: FnvHashMap::default(),
-        alloc_inputs: FnvHashMap::default(),
-        constraints: vec![],
+        allocs: allocs.as_ref().clone(),
+        alloc_inputs: allocs_input.as_ref().clone(),
+        constraints: enforce_allocs,
         env: env.clone(),
         env: env.clone(),
     };
     };
+    // Create an instance of our circuit (with the preimage as a witness).
+    // todo check if circuit.clone is valid
+    let params = {
+        let c = circuit.clone();
+        groth16::generate_random_parameters::<Bls12, _, _>(c, &mut OsRng).unwrap()
+    };
     let start = Instant::now();
     let start = Instant::now();
     // Create a Groth16 proof with our parameters.
     // 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();

+ 2 - 2
lisp/new-cs.lisp

@@ -6,8 +6,8 @@
       x3 (alloc "x3" (* aux (* aux aux)))
       x3 (alloc "x3" (* aux (* aux aux)))
       input (alloc-input "input" aux)
       input (alloc-input "input" aux)
       ]
       ]
+(prove
  (setup 
  (setup 
-   ;; (enforce left right output)
   (
   (
   (enforce  
   (enforce  
     (
     (
@@ -33,6 +33,6 @@
   )
   )
   )
   )
  )
  )
-(prove)
+)
 )
 )
 ;; (println 'verify  (MyCircuit (scalar 27)))
 ;; (println 'verify  (MyCircuit (scalar 27)))

+ 11 - 1
lisp/types.rs

@@ -39,11 +39,21 @@ impl Circuit<bls12_381::Scalar> for LispCircuit {
         self,
         self,
         _cs: &mut CS,
         _cs: &mut CS,
     ) -> Result<(), SynthesisError> {
     ) -> Result<(), SynthesisError> {
-        println!("something called this");
+        println!("Allocations\n");
         for alloc_value in &self.allocs {
         for alloc_value in &self.allocs {
             println!("{:?}", alloc_value);
             println!("{:?}", alloc_value);
         }
         }
 
 
+        println!("Allocations Input\n");
+        for alloc_value in &self.alloc_inputs {
+            println!("{:?}", alloc_value);
+        }
+
+        println!("Enforce Allocations\n");
+        for alloc_value in &self.constraints {
+            println!("{:?}", alloc_value);
+        }
+
         Ok(())
         Ok(())
     }
     }
 }
 }