mirror of
https://github.com/darkrenaissance/darkfi.git
synced 2026-04-28 03:00:18 -04:00
added lib.rs and bits.lisp
This commit is contained in:
@@ -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"
|
||||
|
||||
9
lisp/bits.lisp
Normal file
9
lisp/bits.lisp
Normal file
@@ -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
lisp/core.rs
15
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)),
|
||||
]
|
||||
}
|
||||
|
||||
12
lisp/lib.rs
Normal file
12
lisp/lib.rs
Normal file
@@ -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,
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user