diff --git a/lisp/Cargo.toml b/lisp/Cargo.toml index c4aca5fe1..c7685a7e3 100644 --- a/lisp/Cargo.toml +++ b/lisp/Cargo.toml @@ -1,14 +1,15 @@ [package] -name = "mal" +name = "zklisp" version = "0.1.0" authors = ["mileschet"] [dependencies] lazy_static = "1.4.0" - regex = "1.3.1" itertools = "0.8.0" fnv = "1.0.6" +bellman = { version = "0.8", default-features = false, features = ["groth16"] } +sapvi = { path = "../" } [[bin]] name = "lisp" diff --git a/lisp/bits.lisp b/lisp/bits.lisp new file mode 100644 index 000000000..5738d7013 --- /dev/null +++ b/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) + ))))) + diff --git a/lisp/core.rs b/lisp/core.rs index 547f578d1..f49b93836 100644 --- a/lisp/core.rs +++ b/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 { match a[0].clone() { 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())), ("reset!", func(|a| a[0].reset_bang(&a[1]))), ("swap!", func(|a| a[0].swap_bang(&a[1..].to_vec()))), + ("unpack_bits", func(unpack_bits)), ] } diff --git a/lisp/lib.rs b/lisp/lib.rs new file mode 100644 index 000000000..01a5b6fdb --- /dev/null +++ b/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, +}; +