|
@@ -1,8 +1,9 @@
|
|
|
#![allow(non_snake_case)]
|
|
#![allow(non_snake_case)]
|
|
|
|
|
|
|
|
|
|
+use crate::MalVal::Zk;
|
|
|
use crate::groth16::VerifyingKey;
|
|
use crate::groth16::VerifyingKey;
|
|
|
use crate::types::LispCircuit;
|
|
use crate::types::LispCircuit;
|
|
|
-use sapvi::ZKVMCircuit;
|
|
|
|
|
|
|
+use sapvi::{ZKVMCircuit, ZKVirtualMachine};
|
|
|
use sapvi::bls_extensions::BlsStringConversion;
|
|
use sapvi::bls_extensions::BlsStringConversion;
|
|
|
|
|
|
|
|
use simplelog::*;
|
|
use simplelog::*;
|
|
@@ -49,6 +50,8 @@ use crate::env::{env_bind, env_find, env_get, env_new, env_set, env_sets, Env};
|
|
|
#[macro_use]
|
|
#[macro_use]
|
|
|
mod core;
|
|
mod core;
|
|
|
|
|
|
|
|
|
|
+pub const ZK_CIRCUIT_ENV_KEY : &str = "ZKC";
|
|
|
|
|
+
|
|
|
// read
|
|
// read
|
|
|
fn read(str: &str) -> MalRet {
|
|
fn read(str: &str) -> MalRet {
|
|
|
reader::read_str(str.to_string())
|
|
reader::read_str(str.to_string())
|
|
@@ -286,24 +289,27 @@ fn eval(mut ast: MalVal, mut env: Env) -> MalRet {
|
|
|
}
|
|
}
|
|
|
Sym(ref a0sym) if a0sym == "setup" => {
|
|
Sym(ref a0sym) if a0sym == "setup" => {
|
|
|
let a1 = l[1].clone();
|
|
let a1 = l[1].clone();
|
|
|
|
|
+ let circuit = setup(&ast)?;
|
|
|
|
|
+ println!("{:?}", a1);
|
|
|
|
|
+ env_sets(&env, ZK_CIRCUIT_ENV_KEY, circuit);
|
|
|
eval(a1.clone(), env.clone())
|
|
eval(a1.clone(), env.clone())
|
|
|
}
|
|
}
|
|
|
- //Sym(ref a0sym) if a0sym == "prove" => {
|
|
|
|
|
|
|
+ Sym(ref a0sym) if a0sym == "prove" => {
|
|
|
|
|
+ let a1 = l[1].clone();
|
|
|
|
|
+ println!("{:?}", a1);
|
|
|
|
|
+ prove(a1.clone(), env.clone())
|
|
|
|
|
+ }
|
|
|
//Sym(ref a0sym) if a0sym == "verify" => {
|
|
//Sym(ref a0sym) if a0sym == "verify" => {
|
|
|
Sym(ref a0sym) if a0sym == "enforce" => {
|
|
Sym(ref a0sym) if a0sym == "enforce" => {
|
|
|
- let (a1, a2) = (l[1].clone(), l[2].clone());
|
|
|
|
|
|
|
+ let (a1, a2) = (l[0].clone(), l[1].clone());
|
|
|
let value = eval_ast(&a2, &env)?;
|
|
let value = eval_ast(&a2, &env)?;
|
|
|
match value {
|
|
match value {
|
|
|
List(ref el, _) => {
|
|
List(ref el, _) => {
|
|
|
- //let val = zkcons_eval(el.to_vec(), &a1, &env)?;
|
|
|
|
|
- //val.clone();
|
|
|
|
|
println!("{:?}", el.to_vec());
|
|
println!("{:?}", el.to_vec());
|
|
|
}
|
|
}
|
|
|
_ => println!("invalid format"),
|
|
_ => println!("invalid format"),
|
|
|
}
|
|
}
|
|
|
- // println!("3 {:?}", eval(a1.clone(), env.clone()));
|
|
|
|
|
- env_set(&env, a1.clone(), eval(a1.clone(), env.clone())?);
|
|
|
|
|
- eval(a1.clone(), env.clone())
|
|
|
|
|
|
|
+ Ok(Nil)
|
|
|
}
|
|
}
|
|
|
Sym(ref a0sym) if a0sym == "fn*" => {
|
|
Sym(ref a0sym) if a0sym == "fn*" => {
|
|
|
let (a1, a2) = (l[1].clone(), l[2].clone());
|
|
let (a1, a2) = (l[1].clone(), l[2].clone());
|
|
@@ -374,10 +380,22 @@ pub fn setup(ast: &MalVal) -> MalRet {
|
|
|
Ok(MalVal::Zk(Rc::new(c)))
|
|
Ok(MalVal::Zk(Rc::new(c)))
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-pub fn prove(ast: &MalVal) -> MalRet {
|
|
|
|
|
|
|
+pub fn prove(mut ast: MalVal, mut env: Env) -> MalRet {
|
|
|
|
|
+ let c = match env_find(&env, ZK_CIRCUIT_ENV_KEY) {
|
|
|
|
|
+ Some(e) => match env_get(&e, &Sym(ZK_CIRCUIT_ENV_KEY.to_string()))? {
|
|
|
|
|
+ Zk(c) => {
|
|
|
|
|
+ MalVal::Zk(c)
|
|
|
|
|
+ }
|
|
|
|
|
+ _ => { MalVal::Nil }
|
|
|
|
|
+ }
|
|
|
|
|
+ None => { println!("circuit not found."); MalVal::Nil }
|
|
|
|
|
+ };
|
|
|
|
|
+
|
|
|
|
|
+ println!("{:?}", c);
|
|
|
|
|
+
|
|
|
// Pick a preimage and compute its hash.
|
|
// Pick a preimage and compute its hash.
|
|
|
let quantity = bls12_381::Scalar::from(3);
|
|
let quantity = bls12_381::Scalar::from(3);
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
// Create an instance of our circuit (with the preimage as a witness).
|
|
// Create an instance of our circuit (with the preimage as a witness).
|
|
|
let c = LispCircuit {
|
|
let c = LispCircuit {
|
|
|
params: Rc::new(vector![vec![
|
|
params: Rc::new(vector![vec![
|