ada 5 lat temu
rodzic
commit
b7b426e657
3 zmienionych plików z 16 dodań i 18 usunięć
  1. 10 14
      lisp/lisp.rs
  2. 3 2
      lisp/new-cs.lisp
  3. 3 2
      lisp/types.rs

+ 10 - 14
lisp/lisp.rs

@@ -1,5 +1,6 @@
 #![allow(non_snake_case)]
 
+use bellman::groth16::PreparedVerifyingKey;
 use crate::groth16::VerifyingKey;
 use crate::types::LispCircuit;
 use crate::MalVal::Zk;
@@ -300,7 +301,7 @@ fn eval(mut ast: MalVal, mut env: Env) -> MalRet {
                     }
                     Sym(ref a0sym) if a0sym == "setup" => {
                         let a1 = l[1].clone();
-                        setup(a1.clone(), env.clone())?;
+                        let pvk = setup(a1.clone(), env.clone())?;
                         eval(a1.clone(), env.clone())
                     }
                     Sym(ref a0sym) if a0sym == "prove" => {
@@ -312,20 +313,17 @@ fn eval(mut ast: MalVal, mut env: Env) -> MalRet {
                     Sym(ref a0sym) if a0sym == "alloc" => {
                         let a1 = l[1].clone();
                         let a2 = l[2].clone();
-                        let value = eval_ast(&a2, &env)?;
+                        let value = eval(a2, env.clone())?;
                         println!("a1 {:?} \n value {:?}", a1, value);
-                        Ok(value)
+                        env_set(&env, MalVal::Sym(a1.pr_str(false)), value)
                     }
                     //Sym(ref a0sym) if a0sym == "verify" => {
                     Sym(ref a0sym) if a0sym == "enforce" => {
                         let (a1, a2) = (l[0].clone(), l[1].clone());
-                        let value = eval_ast(&a2, &env)?;
-                        match value {
-                            List(ref el, _) => {
-                                println!("{:?}", el.to_vec());
-                            }
-                            _ => println!("invalid format"),
-                        }
+                        let left = l[1].clone();
+                        let right = l[2].clone();
+                        let out = l[3].clone();
+                        println!("left {:?} \n  right {:?} \n out {:?}", left, right, out);
                         Ok(Nil)
                     }
                     _ => match eval_ast(&ast, &env)? {
@@ -388,9 +386,7 @@ pub fn env_circuit(mut env: Env) -> MalVal {
     }
 }
 
-pub fn setup(ast: MalVal, mut env: Env) -> MalRet {
-    println!("{:?}", ast);
-    // TODO get params from ast
+pub fn setup(ast: MalVal, mut env: Env) -> Result<PreparedVerifyingKey<Bls12>, MalErr> {
     let start = Instant::now();
     // Create parameters for our circuit. In a production deployment these would
     // be generated securely using a multiparty computation.
@@ -407,7 +403,7 @@ pub fn setup(ast: MalVal, mut env: Env) -> MalRet {
     let pvk = groth16::prepare_verifying_key(&random_parameters.vk);
     println!("Setup: [{:?}]", start.elapsed());
 
-    Ok(MalVal::Nil)
+    Ok(pvk)
 }
 
 pub fn prove(mut ast: MalVal, mut env: Env) -> MalRet {

+ 3 - 2
lisp/new-cs.lisp

@@ -6,7 +6,8 @@
       x3 (alloc "x3" (* aux (* aux aux)))
       input (alloc-input "input variable" aux)]
   ;; (enforce left right output)
-  (enforce 
+  (
+  (enforce  
     (scalar::one x)
     (scalar::one x)
     (scalar::one x2)
@@ -29,7 +30,7 @@
   ;;   ((scalar::one left_i) (mimc_constant cs::one)) 
   ;;   ((scalar::one left_i_1) ((neg scalar::one) right))
   ;;  )
-
+  )
 ))
 (prove))
 ;; (println 'verify  (MyCircuit (scalar 27)))

+ 3 - 2
lisp/types.rs

@@ -1,3 +1,5 @@
+use bellman::groth16::PreparedVerifyingKey;
+use bls12_381::Bls12;
 use bellman::Circuit;
 use bellman::ConstraintSystem;
 use bellman::SynthesisError;
@@ -68,8 +70,7 @@ pub enum MalVal {
     Atom(Rc<RefCell<MalVal>>),
     Zk(LispCircuit),
     Enforce(Rc<Vec<MalVal>>),
-    // TODO maybe change to bls scalar
-    ZKScalar(bls12_381::Scalar),
+    ZKScalar(bls12_381::Scalar)
 }
 
 #[derive(Debug)]