From 078492f1bb8c2959e99ef6a0f0b1ebf15a4e367e Mon Sep 17 00:00:00 2001 From: ada Date: Mon, 15 Feb 2021 19:58:31 +0100 Subject: [PATCH 1/4] debuging jubjub mul --- lisp/core.rs | 5 ++++- lisp/jubjub-mul.lisp | 15 +-------------- lisp/lisp.rs | 3 +-- lisp/types.rs | 6 +++--- 4 files changed, 9 insertions(+), 20 deletions(-) diff --git a/lisp/core.rs b/lisp/core.rs index 20b015f72..3dc3fa6ad 100644 --- a/lisp/core.rs +++ b/lisp/core.rs @@ -383,6 +383,9 @@ fn negate_from(a: MalArgs) -> MalRet { fn scalar_from(a: MalArgs) -> MalRet { match a[0].clone() { + ZKScalar(s0) => { + Ok(ZKScalar(s0)) + } Str(a0) => { let s0 = bls12_381::Scalar::from_string(&a0.to_string()); Ok(ZKScalar(s0)) @@ -391,7 +394,7 @@ fn scalar_from(a: MalArgs) -> MalRet { let s0 = bls12_381::Scalar::from(a0 as u64); Ok(ZKScalar(s0)) } - _ => error("expected (string or int)"), + _ => error("scalar from expected (string or int)"), } } diff --git a/lisp/jubjub-mul.lisp b/lisp/jubjub-mul.lisp index 795aecf66..472bc9be5 100644 --- a/lisp/jubjub-mul.lisp +++ b/lisp/jubjub-mul.lisp @@ -6,20 +6,7 @@ (setup (prove -( - (zk* [ - u11 (alloc "u11" (scalar 2)) - v11 (alloc "v11" (scalar 2)) - U1 (alloc-input "U1" (* u11 v11)) - ] - ( - (enforce - (scalar::one u11) - (scalar::one v11) - (scalar::one U1) - ) - ) - ) + ( (zk* [ u1 (alloc "u1" param1) v1 (alloc "v1" param2) diff --git a/lisp/lisp.rs b/lisp/lisp.rs index 2a6da2cd0..40720ffb7 100644 --- a/lisp/lisp.rs +++ b/lisp/lisp.rs @@ -593,7 +593,6 @@ pub fn prove(_ast: MalVal, env: Env) -> MalRet { let proof = groth16::create_random_proof(circuit, params.as_ref().unwrap(), &mut OsRng)?; let mut vec_input = vec![]; for (k, val) in allocs_input.iter() { - println!("{:?}", val); match val { MalVal::Str(v) => { vec_input.push(bls12_381::Scalar::from_string(&v.to_string())); @@ -605,8 +604,8 @@ pub fn prove(_ast: MalVal, env: Env) -> MalRet { }; } let result = groth16::verify_proof(verifying_key.as_ref().unwrap(), &proof, &vec_input); - println!("{:?}", result); println!("vec public {:?}", vec_input); + println!("result {:?}", result); Ok(MalVal::Nil) } diff --git a/lisp/types.rs b/lisp/types.rs index ea886a8c8..47a66abe4 100644 --- a/lisp/types.rs +++ b/lisp/types.rs @@ -142,7 +142,7 @@ impl Circuit for LispCircuit { } } } - println!("left: a {:?} b {:?} val_b: {:?}", a, b, val_b); +// println!("left: a {:?} b {:?} val_b: {:?}", a, b, val_b); } for values in alloc_value.right.iter() { @@ -156,7 +156,7 @@ impl Circuit for LispCircuit { } else if a == "scalar::one::neg" { right = right + (coeff.neg(), val_b); } - println!("right: a {:?} b {:?} val_b: {:?}", a, b, val_b); + //println!("right: a {:?} b {:?} val_b: {:?}", a, b, val_b); } for values in alloc_value.output.iter() { @@ -170,7 +170,7 @@ impl Circuit for LispCircuit { } else if a == "scalar::one::neg" { output = output + (coeff.neg(), val_b); } - println!("output: a {:?} b {:?} val_b: {:?}", a, b, val_b); + //println!("output: a {:?} b {:?} val_b: {:?}", a, b, val_b); } println!("Enforcing ..."); From 7be811d99aec0c794acbab4522baa12edaa934af Mon Sep 17 00:00:00 2001 From: ada Date: Mon, 15 Feb 2021 21:11:51 +0100 Subject: [PATCH 2/4] context and def! alloc --- lisp/jubjub-mul.lisp | 15 ++++++++++++++- lisp/lisp.rs | 4 +++- lisp/run.sh | 2 +- 3 files changed, 18 insertions(+), 3 deletions(-) diff --git a/lisp/jubjub-mul.lisp b/lisp/jubjub-mul.lisp index 472bc9be5..42254d43d 100644 --- a/lisp/jubjub-mul.lisp +++ b/lisp/jubjub-mul.lisp @@ -1,9 +1,21 @@ -(println "jubjub-mul.lisp") + (println "jubjub-mul.lisp") (def! param4 (scalar "015d8c7f5b43fe33f7891142c001d9251f3abeeb98fad3e87b0dc53c4ebf1891")) (def! param3 (scalar "15a36d1f0f390d8852a35a8c1908dd87a361ee3fd48fdf77b9819dc82d90607e")) (def! param2 (scalar "015d8c7f5b43fe33f7891142c001d9251f3abeeb98fad3e87b0dc53c4ebf1891")) (def! param1 (scalar "15a36d1f0f390d8852a35a8c1908dd87a361ee3fd48fdf77b9819dc82d90607e")) + (def! double (fn* [val1 val2] ( + (def! u11 (alloc "u11" (scalar val1))) + (def! v11 (alloc "v11" (scalar val2))) + (def! U1 (alloc-input "U1" (* u11 v11))) + (enforce + (scalar::one u11) + (scalar::one v11) + (scalar::one U1) + ) + ) + )) + (setup (prove ( @@ -19,6 +31,7 @@ C (alloc "C" (* EDWARDS_D (* A B))) u3 (alloc-input "u3" (/ (+ A B) (+ scalar::one C))) v3 (alloc-input "v3" (/ (- (- U A) B) (- scalar::one C))) + v4 (double param1 param1) ] ( (enforce diff --git a/lisp/lisp.rs b/lisp/lisp.rs index 40720ffb7..f279dec23 100644 --- a/lisp/lisp.rs +++ b/lisp/lisp.rs @@ -165,9 +165,11 @@ fn eval(mut ast: MalVal, mut env: Env) -> MalRet { let a0 = &l[0]; match a0 { Sym(ref a0sym) if a0sym == "def!" => { + println!("def {:?}", l[1]); env_set(&env, l[1].clone(), eval(l[2].clone(), env.clone())?) } Sym(ref a0sym) if a0sym == "zk*" => { + println!("zk* {:?}", l[1]); let (a1, a2) = (l[1].clone(), l[2].clone()); match a1 { List(ref binds, _) | Vector(ref binds, _) => { @@ -490,8 +492,8 @@ fn eval(mut ast: MalVal, mut env: Env) -> MalRet { continue 'tco; } _ => { + println!("{:?}", args); Ok(vector![el.to_vec()]) - //error("call non-function") } } diff --git a/lisp/run.sh b/lisp/run.sh index 913940183..d3940353e 100755 --- a/lisp/run.sh +++ b/lisp/run.sh @@ -1,3 +1,3 @@ -export RUST_BACKTRACE=full +#export RUST_BACKTRACE=full cargo run --bin lisp load jubjub-mul.lisp #cargo run --bin lisp load new-cs.lisp From e76ed0505b19e53db8a1924855980bc18d0d421e Mon Sep 17 00:00:00 2001 From: plato Date: Tue, 16 Feb 2021 17:01:34 +0100 Subject: [PATCH 3/4] organizing two circuits interacting --- lisp/jubjub-mul.lisp | 36 +++++++++++++++++------------------- lisp/lisp.rs | 1 - 2 files changed, 17 insertions(+), 20 deletions(-) diff --git a/lisp/jubjub-mul.lisp b/lisp/jubjub-mul.lisp index 42254d43d..a12031735 100644 --- a/lisp/jubjub-mul.lisp +++ b/lisp/jubjub-mul.lisp @@ -1,9 +1,12 @@ - (println "jubjub-mul.lisp") +(println "jubjub-mul.lisp") (def! param4 (scalar "015d8c7f5b43fe33f7891142c001d9251f3abeeb98fad3e87b0dc53c4ebf1891")) (def! param3 (scalar "15a36d1f0f390d8852a35a8c1908dd87a361ee3fd48fdf77b9819dc82d90607e")) (def! param2 (scalar "015d8c7f5b43fe33f7891142c001d9251f3abeeb98fad3e87b0dc53c4ebf1891")) (def! param1 (scalar "15a36d1f0f390d8852a35a8c1908dd87a361ee3fd48fdf77b9819dc82d90607e")) +(setup + (prove + ( (def! double (fn* [val1 val2] ( (def! u11 (alloc "u11" (scalar val1))) (def! v11 (alloc "v11" (scalar val2))) @@ -16,23 +19,18 @@ ) )) -(setup - (prove - ( - (zk* [ - u1 (alloc "u1" param1) - v1 (alloc "v1" param2) - u2 (alloc "u2" param3) - v2 (alloc "v2" param4) - EDWARDS_D (alloc-const "EDWARDS_D" (scalar "2a9318e74bfa2b48f5fd9207e6bd7fd4292d7f6d37579d2601065fd6d6343eb1")) - U (alloc "U" (* (+ u1 v1) (+ u2 v2))) - A (alloc "A" (* v2 u1)) - B (alloc "B" (* u2 v1)) - C (alloc "C" (* EDWARDS_D (* A B))) - u3 (alloc-input "u3" (/ (+ A B) (+ scalar::one C))) - v3 (alloc-input "v3" (/ (- (- U A) B) (- scalar::one C))) - v4 (double param1 param1) - ] + (def! u1 (alloc "u1" param1)) + (def! v1 (alloc "v1" param2)) + (def! u2 (alloc "u2" param3)) + (def! v2 (alloc "v2" param4)) + (def! EDWARDS_D (alloc-const "EDWARDS_D" (scalar "2a9318e74bfa2b48f5fd9207e6bd7fd4292d7f6d37579d2601065fd6d6343eb1"))) + (def! U (alloc "U" (* (+ u1 v1) (+ u2 v2)))) + (def! A (alloc "A" (* v2 u1))) + (def! B (alloc "B" (* u2 v1))) + (def! C (alloc "C" (* EDWARDS_D (* A B)))) + (def! u3 (alloc-input "u3" (/ (+ A B) (+ scalar::one C)))) + (def! v3 (alloc-input "v3" (/ (- (- U A) B) (- scalar::one C)))) + (double param1 param1) ( (enforce ((scalar::one u1) (scalar::one v1)) @@ -57,4 +55,4 @@ ) ) ) -)) +) diff --git a/lisp/lisp.rs b/lisp/lisp.rs index f279dec23..5b2335a8e 100644 --- a/lisp/lisp.rs +++ b/lisp/lisp.rs @@ -165,7 +165,6 @@ fn eval(mut ast: MalVal, mut env: Env) -> MalRet { let a0 = &l[0]; match a0 { Sym(ref a0sym) if a0sym == "def!" => { - println!("def {:?}", l[1]); env_set(&env, l[1].clone(), eval(l[2].clone(), env.clone())?) } Sym(ref a0sym) if a0sym == "zk*" => { From 6bbf2603a01797d4f3d19e834e3f96f35f826df6 Mon Sep 17 00:00:00 2001 From: plato Date: Tue, 16 Feb 2021 17:10:00 +0100 Subject: [PATCH 4/4] fixing commits --- lisp/jubjub-mul.lisp | 1 + 1 file changed, 1 insertion(+) diff --git a/lisp/jubjub-mul.lisp b/lisp/jubjub-mul.lisp index a12031735..97b34e608 100644 --- a/lisp/jubjub-mul.lisp +++ b/lisp/jubjub-mul.lisp @@ -1,4 +1,5 @@ (println "jubjub-mul.lisp") + (def! param4 (scalar "015d8c7f5b43fe33f7891142c001d9251f3abeeb98fad3e87b0dc53c4ebf1891")) (def! param3 (scalar "15a36d1f0f390d8852a35a8c1908dd87a361ee3fd48fdf77b9819dc82d90607e")) (def! param2 (scalar "015d8c7f5b43fe33f7891142c001d9251f3abeeb98fad3e87b0dc53c4ebf1891"))