ada 5 лет назад
Родитель
Сommit
fb843272c5
4 измененных файлов с 39 добавлено и 2 удалено
  1. 3 2
      lisp/Cargo.toml
  2. 9 0
      lisp/bits.lisp
  3. 15 0
      lisp/core.rs
  4. 12 0
      lisp/lib.rs

+ 3 - 2
lisp/Cargo.toml

@@ -1,14 +1,15 @@
 [package]
 [package]
-name = "mal"
+name = "zklisp"
 version = "0.1.0"
 version = "0.1.0"
 authors = ["mileschet"]
 authors = ["mileschet"]
 
 
 [dependencies]
 [dependencies]
 lazy_static = "1.4.0"
 lazy_static = "1.4.0"
-
 regex = "1.3.1"
 regex = "1.3.1"
 itertools = "0.8.0"
 itertools = "0.8.0"
 fnv = "1.0.6"
 fnv = "1.0.6"
+bellman = { version = "0.8", default-features = false, features = ["groth16"] }
+sapvi = { path = "../" } 
 
 
 [[bin]]
 [[bin]]
 name = "lisp"
 name = "lisp"

+ 9 - 0
lisp/bits.lisp

@@ -0,0 +1,9 @@
+(def! bit-dec (fn* [x] (
+                        (def! bits (unpack-bits x 256))                        
+                        (def! enforce-step-1 (fn* [b] (enforce (add-one-lc0 (sub-lc0 b) (add-lc1 b))))
+                        (map enforce-step-1 bits)
+                        ;; this can be improved like declaring the function before using like the example above
+                        (map (fn* [b] ((add-lc0 x) double-coeff-lc) bits)                       
+                        (enforce reset-coeff-lc sub-lc0 add-one-lc1)
+                        )))))
+                            

+ 15 - 0
lisp/core.rs

@@ -153,6 +153,20 @@ fn nth(a: MalArgs) -> MalRet {
     }
     }
 }
 }
 
 
+// (unpack-bits x 256 it produces a Vec
+fn unpack_bits(a: MalArgs) -> MalRet {
+    // Scalar::from_string(
+    match (a[0].clone(), a[1].clone()) {
+        (List(seq, _), Int(idx)) | (Vector(seq, _), Int(idx)) => {
+            if seq.len() <= idx as usize {
+                return error("nth: index out of range");
+            }
+            Ok(seq[idx as usize].clone())
+        }
+        _ => error("invalid args to nth"),
+    }
+}
+
 fn first(a: MalArgs) -> MalRet {
 fn first(a: MalArgs) -> MalRet {
     match a[0].clone() {
     match a[0].clone() {
         List(ref seq, _) | Vector(ref seq, _) if seq.len() == 0 => Ok(Nil),
         List(ref seq, _) | Vector(ref seq, _) if seq.len() == 0 => Ok(Nil),
@@ -315,5 +329,6 @@ pub fn ns() -> Vec<(&'static str, MalVal)> {
         ("deref", func(|a| a[0].deref())),
         ("deref", func(|a| a[0].deref())),
         ("reset!", func(|a| a[0].reset_bang(&a[1]))),
         ("reset!", func(|a| a[0].reset_bang(&a[1]))),
         ("swap!", func(|a| a[0].swap_bang(&a[1..].to_vec()))),
         ("swap!", func(|a| a[0].swap_bang(&a[1..].to_vec()))),
+        ("unpack_bits", func(unpack_bits)),
     ]
     ]
 }
 }

+ 12 - 0
lisp/lib.rs

@@ -0,0 +1,12 @@
+use bellman::groth16;
+use bls12_381::{Bls12, Scalar};
+use std::collections::{HashMap, HashSet};
+
+pub use crate::bls_extensions::BlsStringConversion;
+pub use crate::error::{Error, Result};
+pub use crate::serial::{Decodable, Encodable};
+pub use crate::vm::{
+    AllocType, ConstraintInstruction, CryptoOperation, VariableIndex, VariableRef, ZKVMCircuit,
+    ZKVirtualMachine,
+};
+