Просмотр исходного кода

create allocations malval type to store allocs to the circuit

ada 5 лет назад
Родитель
Сommit
d88ffd49db
2 измененных файлов с 13 добавлено и 28 удалено
  1. 11 27
      lisp/lisp.rs
  2. 2 1
      lisp/types.rs

+ 11 - 27
lisp/lisp.rs

@@ -34,7 +34,7 @@ extern crate regex;
 #[macro_use]
 #[macro_use]
 mod types;
 mod types;
 use crate::types::MalErr::{ErrMalVal, ErrString};
 use crate::types::MalErr::{ErrMalVal, ErrString};
-use crate::types::MalVal::{Bool, Func, Hash, List, MalFunc, Nil, Str, Sym, Vector};
+use crate::types::MalVal::{Bool, Func, Hash, List, MalFunc, Nil, Str, Sym, Vector, Allocations};
 use crate::types::{error, format_error, MalArgs, MalErr, MalRet, MalVal};
 use crate::types::{error, format_error, MalArgs, MalErr, MalRet, MalVal};
 mod env;
 mod env;
 mod printer;
 mod printer;
@@ -315,9 +315,13 @@ fn eval(mut ast: MalVal, mut env: Env) -> MalRet {
                         let value = eval(l[2].clone(), env.clone())?;
                         let value = eval(l[2].clone(), env.clone())?;
                         let result = eval(value.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));
-                        let mut circuit = env_circuit(env.clone());
-                        circuit.allocs.push(Some(Allocation{symbol: symbol, value: value }));
-
+                        let alloc_symbol = &Sym("Allocations".to_string());
+                        let allocations = match env_get(&env.clone(), alloc_symbol) {
+                            Ok(Allocations(v)) => { v },
+                            _ => Rc::new(vec![])
+                        };
+                        
+                        // vec![Allocation { symbol : symbol, value: value }]
                         env_set(&env, symbol,  result)
                         env_set(&env, symbol,  result)
                     }
                     }
                     //Sym(ref a0sym) if a0sym == "verify" => {
                     //Sym(ref a0sym) if a0sym == "verify" => {
@@ -369,33 +373,13 @@ fn eval(mut ast: MalVal, mut env: Env) -> MalRet {
     ret
     ret
 }
 }
 
 
-pub fn env_circuit(mut env: Env) -> MalVal {
-    let s = ZK_CIRCUIT_ENV_KEY;
-    match env_find(&env, s) {
-        Some(e) => match env_get(&e, &Str(s.to_string())) {
-            Ok(v) => v,
-            _ => MalVal::Zk(LispCircuit {
-                params: vec![],
-                allocs: vec![],
-                alloc_inputs: vec![],
-                constraints: vec![],
-                env: env.clone(),
-            }),
-        },
-        _ => MalVal::Zk(LispCircuit {
-            params: vec![],
-            allocs: vec![],
-            alloc_inputs: vec![],
-            constraints: vec![],
-            env: env.clone(),
-        }),
-    }
-}
-
 pub fn setup(ast: MalVal, mut env: Env) -> Result<PreparedVerifyingKey<Bls12>, MalErr> {
 pub fn setup(ast: MalVal, mut env: Env) -> Result<PreparedVerifyingKey<Bls12>, MalErr> {
     let start = Instant::now();
     let start = Instant::now();
     // Create parameters for our circuit. In a production deployment these would
     // Create parameters for our circuit. In a production deployment these would
     // be generated securely using a multiparty computation.
     // be generated securely using a multiparty computation.
+
+    // get all allocs from env 
+
     let mut c = LispCircuit {
     let mut c = LispCircuit {
         params: vec![],
         params: vec![],
         allocs: vec![],
         allocs: vec![],

+ 2 - 1
lisp/types.rs

@@ -68,7 +68,8 @@ pub enum MalVal {
         meta: Rc<MalVal>,
         meta: Rc<MalVal>,
     },
     },
     Atom(Rc<RefCell<MalVal>>),
     Atom(Rc<RefCell<MalVal>>),
-    Zk(LispCircuit),
+    Zk(Rc<LispCircuit>), // TODO remote it
+    Allocations(Rc<Vec<Allocation>>),
     Enforce(Rc<Vec<MalVal>>),
     Enforce(Rc<Vec<MalVal>>),
     ZKScalar(bls12_381::Scalar)
     ZKScalar(bls12_381::Scalar)
 }
 }