瀏覽代碼

begin interacting with zkvm add lc0

ada 5 年之前
父節點
當前提交
153798b649
共有 5 個文件被更改,包括 43 次插入19 次删除
  1. 3 3
      lisp/core.rs
  2. 8 2
      lisp/lisp.rs
  3. 22 13
      lisp/new.lisp
  4. 4 1
      lisp/printer.rs
  5. 6 0
      lisp/types.rs

+ 3 - 3
lisp/core.rs

@@ -174,8 +174,8 @@ fn nth(a: MalArgs) -> MalRet {
 
 fn unpack_bits(a: MalArgs) -> MalRet {
     let mut result = vec![];
-    match (a[0].clone(), a[1].clone()) {
-        (Str(ref s), Int(size)) => {
+    match (a[0].clone()) {
+        (Str(ref s)) => {
             let value = Scalar::from_string(s);
                     for (_, bit) in value.to_le_bits().into_iter().cloned().enumerate() {
                         match bit {
@@ -253,7 +253,6 @@ fn conj(a: MalArgs) -> MalRet {
 }
 
 fn add(a: MalArgs) -> MalRet {
-    println!("{:?}", a);
     Ok(Nil)
 }
 
@@ -358,5 +357,6 @@ pub fn ns() -> Vec<(&'static str, MalVal)> {
         ("swap!", func(|a| a[0].swap_bang(&a[1..].to_vec()))),
         ("unpack-bits", func(unpack_bits)),
         ("add", func(add)),
+        ("lc0", func(|a| Ok(MalVal::Lc0))),
     ]
 }

+ 8 - 2
lisp/lisp.rs

@@ -266,9 +266,14 @@ fn eval(mut ast: MalVal, mut env: Env) -> MalRet {
                         }
                     }
                     Sym(ref a0sym) if a0sym == "zkcons!" => {
-                        println!("{:?}", l);
                         let (a1, a2) = (l[1].clone(), l[2].clone());
-                        Ok(Nil)
+                        // a1 circuit name, get it from env
+                        // a2 evaluate expression
+                        let cond = eval(a2.clone(), env.clone());
+                        println!("{:?}", cond);
+                        match cond {
+                            _ => Ok(Nil)
+                        }
                     }
                     Sym(ref a0sym) if a0sym == "defzk!" => {
                         let (a1, a2) = (l[1].clone(), l[2].clone());
@@ -319,6 +324,7 @@ fn eval(mut ast: MalVal, mut env: Env) -> MalRet {
                                 }
                                 _ => { 
                                     Ok(Nil)
+                                    //error("call non-function")
                                 },
                             }
                         }

+ 22 - 13
lisp/new.lisp

@@ -1,17 +1,26 @@
 (def! x "73eda753299d7d483339d80809a1d80553bda402fffe5bfeffffffff00000000")
+(def! one "0000000000000000000000000000000000000000000000000000000000000001")
 (defzk! circuit ())
-(def! bits (unpack-bits x 256))
+(def! bits (unpack-bits x))
 ;;zkcons add a constraints instruction to the circuit
-    (map (fn* [b] (zkcons! circuit 
+    (zkcons! circuit (
                     (add lc0 one) 
-                    (sub lc0 b)
-                    (add lc1 x)
-                    enforce)
-              ) bits)
-   (map (fn* [b] (quote '(add lc0 b) 
-                          'double-coeff-lc)
-             ) bits)
-   (println 'reset-coeff-lc
-   '(sub lc0 x)
-   '(add lc1 one)
-   'enforce)
+                    )
+              )
+;;    (map (fn* [b] (zkcons! circuit (
+;;                    (add lc0 one) 
+;;                    '(sub lc0 b)
+;;                    '(add lc1 x)
+;;                    'enforce)
+;;              )) bits)
+;;   (map (fn* [b] (zkcons! circuit (
+;;                    '(add lc0 b) 
+;;                    'double-coeff-lc)
+;;             )) bits)
+;;   (zkcons! circuit (
+;;                    'reset-coeff-lc
+;;                    '(sub lc0 x)
+;;                    '(add lc1 one)
+;;                    'enforce)
+;;            )
+(println circuit)

+ 4 - 1
lisp/printer.rs

@@ -45,7 +45,10 @@ impl MalVal {
                 ast: a, params: p, ..
             } => format!("(fn* {} {})", p.pr_str(true), a.pr_str(true)),
             Atom(a) => format!("(atom {})", a.borrow().pr_str(true)),
-            Zk(a) => format!("ZKCircuit")
+            Zk(a) => format!("ZKCircuit"),
+            Add => format!("add"),
+            Lc0 => format!("Lc0"),
+            i_ => format!(""),
         }
     }
 }

+ 6 - 0
lisp/types.rs

@@ -41,6 +41,12 @@ pub enum MalVal {
     },
     Atom(Rc<RefCell<MalVal>>),
     Zk(ZKCircuit),
+    Lc0,
+    Lc1,
+    Lc2,
+    Enforce(bool),
+    Add(Rc<MalVal>, Rc<MalVal>),
+    Sub(Rc<MalVal>, Rc<MalVal>),
 }
 
 #[derive(Debug, Clone)]