mirror of
https://github.com/darkrenaissance/darkfi.git
synced 2026-04-28 03:00:18 -04:00
Merge pull request #23 from mileschet/feature/lisp
jj mul + double same circuit 1
This commit is contained in:
36
lisp/lisp.rs
36
lisp/lisp.rs
@@ -168,7 +168,9 @@ fn eval(mut ast: MalVal, mut env: Env) -> MalRet {
|
||||
env_set(&env, l[1].clone(), eval(l[2].clone(), env.clone())?)
|
||||
}
|
||||
Sym(ref a0sym) if a0sym == "let*" => {
|
||||
env = env_new(Some(env.clone()));
|
||||
// TODO let should be restored to the first purpose
|
||||
// and the new let* without an env creation should be availaable
|
||||
// env = env_new(Some(env.clone()));
|
||||
let (a1, a2) = (l[1].clone(), l[2].clone());
|
||||
match a1 {
|
||||
List(ref binds, _) | Vector(ref binds, _) => {
|
||||
@@ -427,7 +429,7 @@ fn eval(mut ast: MalVal, mut env: Env) -> MalRet {
|
||||
output: out_vec,
|
||||
};
|
||||
let mut new_vec: Vec<EnforceAllocation> = vec![enforce];
|
||||
for value in enforce_vec.iter() {
|
||||
for value in enforce_vec.iter() {
|
||||
new_vec.push(value.clone());
|
||||
}
|
||||
env_set(
|
||||
@@ -547,12 +549,12 @@ pub fn prove(_ast: MalVal, env: Env) -> MalRet {
|
||||
let allocs_const = get_allocations(&env, "AllocationsConst");
|
||||
//setup
|
||||
let params = Some({
|
||||
let circuit = LispCircuit {
|
||||
params: allocs_const.as_ref().clone(),
|
||||
allocs: allocs.as_ref().clone(),
|
||||
alloc_inputs: allocs_input.as_ref().clone(),
|
||||
constraints: enforce_allocs.clone(),
|
||||
};
|
||||
let circuit = LispCircuit {
|
||||
params: allocs_const.as_ref().clone(),
|
||||
allocs: allocs.as_ref().clone(),
|
||||
alloc_inputs: allocs_input.as_ref().clone(),
|
||||
constraints: enforce_allocs.clone(),
|
||||
};
|
||||
groth16::generate_random_parameters::<Bls12, _, _>(circuit, &mut OsRng)?
|
||||
});
|
||||
let verifying_key = Some(groth16::prepare_verifying_key(¶ms.as_ref().unwrap().vk));
|
||||
@@ -568,15 +570,17 @@ pub fn prove(_ast: MalVal, env: Env) -> MalRet {
|
||||
let mut vec_input = vec![];
|
||||
for (k, val) in allocs_input.iter() {
|
||||
println!("{:?}", val);
|
||||
if let MalVal::Str(v) = val {
|
||||
vec_input.push(bls12_381::Scalar::from_string(&v.to_string()));
|
||||
}
|
||||
match val {
|
||||
MalVal::Str(v) => {
|
||||
vec_input.push(bls12_381::Scalar::from_string(&v.to_string()));
|
||||
}
|
||||
MalVal::ZKScalar(v) => {
|
||||
vec_input.push(bls12_381::Scalar::from(*v));
|
||||
}
|
||||
_ => {}
|
||||
};
|
||||
}
|
||||
let result = groth16::verify_proof(
|
||||
verifying_key.as_ref().unwrap(),
|
||||
&proof,
|
||||
&vec_input,
|
||||
);
|
||||
let result = groth16::verify_proof(verifying_key.as_ref().unwrap(), &proof, &vec_input);
|
||||
println!("{:?}", result);
|
||||
println!("vec public {:?}", vec_input);
|
||||
|
||||
|
||||
@@ -1,3 +1,3 @@
|
||||
export RUST_BACKTRACE=full
|
||||
cargo run --bin lisp load jubjub-add.lisp
|
||||
cargo run --bin lisp load jubjub-mul.lisp
|
||||
#cargo run --bin lisp load new-cs.lisp
|
||||
|
||||
@@ -38,7 +38,7 @@ pub struct LispCircuit {
|
||||
pub params: FnvHashMap<String, MalVal>,
|
||||
pub allocs: FnvHashMap<String, MalVal>,
|
||||
pub alloc_inputs: FnvHashMap<String, MalVal>,
|
||||
// todo change this for a ordered data structure so enforce
|
||||
// todo change this for a ordered data structure so enforce
|
||||
pub constraints: Vec<EnforceAllocation>,
|
||||
}
|
||||
|
||||
@@ -118,7 +118,7 @@ impl Circuit<bls12_381::Scalar> for LispCircuit {
|
||||
|
||||
println!("Enforce Allocations\n");
|
||||
let mut enforce_sorted = self.constraints.clone();
|
||||
enforce_sorted.sort_by(|a, b| a.idx.cmp(&b.idx));
|
||||
enforce_sorted.sort_by(|a, b| a.idx.cmp(&b.idx));
|
||||
for alloc_value in enforce_sorted.iter() {
|
||||
println!("Enforce -> {:?}", alloc_value);
|
||||
let coeff = bls12_381::Scalar::one();
|
||||
|
||||
Reference in New Issue
Block a user