mirror of
https://github.com/darkrenaissance/darkfi.git
synced 2026-01-10 23:27:56 -05:00
evaluate multiple enforce left right and output
This commit is contained in:
25
lisp/core.rs
25
lisp/core.rs
@@ -314,10 +314,13 @@ fn scalar_zero(a: MalArgs) -> MalRet {
|
||||
}
|
||||
|
||||
fn scalar_one(a: MalArgs) -> MalRet {
|
||||
Ok(vector![vec![
|
||||
ZKScalar(bls12_381::Scalar::one()),
|
||||
a[0].clone()
|
||||
]])
|
||||
match a.len() {
|
||||
0 => Ok(vector![vec![ZKScalar(bls12_381::Scalar::one())]]),
|
||||
_ => Ok(vector![vec![
|
||||
ZKScalar(bls12_381::Scalar::one()),
|
||||
a[0].clone()
|
||||
]]),
|
||||
}
|
||||
}
|
||||
|
||||
fn cs_one(a: MalArgs) -> MalRet {
|
||||
@@ -325,12 +328,20 @@ fn cs_one(a: MalArgs) -> MalRet {
|
||||
}
|
||||
|
||||
fn negate_from(a: MalArgs) -> MalRet {
|
||||
match a[0].apply(vec![])? {
|
||||
match a[0].clone() {
|
||||
ZKScalar(a0) => Ok(ZKScalar(a0.neg())),
|
||||
Nil => error("nil not supported"),
|
||||
_ => error("negate error, expected (zkscalar)"),
|
||||
_ => match a[0].apply(vec![])? {
|
||||
List(v, _) | Vector(v, _) => {
|
||||
match v[0] {
|
||||
ZKScalar(val) => Ok(vector![vec![ZKScalar(val.neg())]]),
|
||||
_ => error("not scalar"),
|
||||
}
|
||||
}
|
||||
_ => return error("non zkscalar passed to negate"),
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
fn scalar_from(a: MalArgs) -> MalRet {
|
||||
match a[0].clone() {
|
||||
Str(a0) => {
|
||||
|
||||
17
lisp/lisp.rs
17
lisp/lisp.rs
@@ -318,7 +318,8 @@ fn eval(mut ast: MalVal, mut env: Env) -> MalRet {
|
||||
let a1 = l[1].clone();
|
||||
let value = eval(l[2].clone(), env.clone())?;
|
||||
let result = eval(value.clone(), env.clone())?;
|
||||
let symbol = MalVal::Sym(a1.pr_str(false));
|
||||
// let symbol = MalVal::Sym(a1.pr_str(false));
|
||||
env_set(&env, a1.clone(), result.clone());
|
||||
if let Hash(allocs, _) = get_allocations(&env, "AllocationsInput")? {
|
||||
let mut new_hm: FnvHashMap<String, MalVal> = FnvHashMap::default();
|
||||
for (k, v) in allocs.iter() {
|
||||
@@ -337,7 +338,8 @@ fn eval(mut ast: MalVal, mut env: Env) -> MalRet {
|
||||
let a1 = l[1].clone();
|
||||
let value = eval(l[2].clone(), env.clone())?;
|
||||
let result = eval(value.clone(), env.clone())?;
|
||||
let symbol = MalVal::Sym(a1.pr_str(false));
|
||||
// let symbol = MalVal::Sym(a1.pr_str(false));
|
||||
env_set(&env, a1.clone(), result.clone());
|
||||
if let Hash(allocs, _) = get_allocations(&env, "Allocations")? {
|
||||
let mut new_hm: FnvHashMap<String, MalVal> = FnvHashMap::default();
|
||||
for (k, v) in allocs.iter() {
|
||||
@@ -363,10 +365,14 @@ fn eval(mut ast: MalVal, mut env: Env) -> MalRet {
|
||||
let out_eval = eval(out.clone(), env.clone())?;
|
||||
println!(
|
||||
"enforce \n {:?} \n {:?} \n {:?}",
|
||||
left, right, out
|
||||
);
|
||||
println!(
|
||||
"\n {:?} \n {:?} \n {:?} \n",
|
||||
left_eval, right_eval, out_eval
|
||||
);
|
||||
println!("allocations {:?}", get_allocations(&env, "Allocations"));
|
||||
println!("allocations input {:?}", get_allocations(&env, "AllocationsInput"));
|
||||
// println!("allocations {:?}", get_allocations(&env, "Allocations"));
|
||||
// println!("allocations input {:?}", get_allocations(&env, "AllocationsInput"));
|
||||
Ok(vector![vec![left_eval, right_eval, out_eval]])
|
||||
}
|
||||
_ => match eval_ast(&ast, &env)? {
|
||||
@@ -388,7 +394,8 @@ fn eval(mut ast: MalVal, mut env: Env) -> MalRet {
|
||||
continue 'tco;
|
||||
}
|
||||
_ => {
|
||||
Ok(Nil)
|
||||
Ok(vector![el.to_vec()])
|
||||
|
||||
//error("call non-function")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,16 +1,17 @@
|
||||
(println "new-cs.lisp")
|
||||
|
||||
( (let* [aux (scalar 3)
|
||||
x (alloc "x" aux)
|
||||
x2 (alloc "x2" (* aux aux))
|
||||
x3 (alloc "x3" (* aux (* aux aux)))
|
||||
input (alloc-input "input" aux)]
|
||||
|
||||
input (alloc-input "input" aux)
|
||||
]
|
||||
(setup
|
||||
;; (enforce left right output)
|
||||
(
|
||||
(enforce
|
||||
(scalar::one x)
|
||||
(scalar::one x)
|
||||
((neg scalar::one) x)
|
||||
((scalar::one x) (scalar::one x))
|
||||
(scalar::one x2)
|
||||
)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user