Merge pull request #26 from narodnik/feature/lisp

Feature/lisp
This commit is contained in:
ada
2021-02-16 17:12:17 +01:00
committed by GitHub
5 changed files with 38 additions and 36 deletions

View File

@@ -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)"),
}
}

View File

@@ -1,4 +1,5 @@
(println "jubjub-mul.lisp")
(def! param4 (scalar "015d8c7f5b43fe33f7891142c001d9251f3abeeb98fad3e87b0dc53c4ebf1891"))
(def! param3 (scalar "15a36d1f0f390d8852a35a8c1908dd87a361ee3fd48fdf77b9819dc82d90607e"))
(def! param2 (scalar "015d8c7f5b43fe33f7891142c001d9251f3abeeb98fad3e87b0dc53c4ebf1891"))
@@ -6,33 +7,31 @@
(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)
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)))
]
(
(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)
)
)
))
(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 +56,4 @@
)
)
)
))
)

View File

@@ -168,6 +168,7 @@ 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 == "zk*" => {
println!("zk* {:?}", l[1]);
let (a1, a2) = (l[1].clone(), l[2].clone());
match a1 {
List(ref binds, _) | Vector(ref binds, _) => {
@@ -490,8 +491,8 @@ fn eval(mut ast: MalVal, mut env: Env) -> MalRet {
continue 'tco;
}
_ => {
println!("{:?}", args);
Ok(vector![el.to_vec()])
//error("call non-function")
}
}
@@ -593,7 +594,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 +605,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)
}

View File

@@ -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

View File

@@ -142,7 +142,7 @@ impl Circuit<bls12_381::Scalar> 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<bls12_381::Scalar> 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<bls12_381::Scalar> 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 ...");