Bläddra i källkod

added constants on the lisp circuit

ada 5 år sedan
förälder
incheckning
1857ed1f5f
3 ändrade filer med 23 tillägg och 4 borttagningar
  1. 1 1
      lisp/jubjub-add.lisp
  2. 21 2
      lisp/lisp.rs
  3. 1 1
      lisp/types.rs

+ 1 - 1
lisp/jubjub-add.lisp

@@ -2,7 +2,7 @@
 ;; Compute U = (u1 + v1) * (v2 - EDWARDS_A*u2)
 ;;           = (u1 + v1) * (u2 + v2)
 ( (let* [
-      EDWARDS_D (scalar "2a9318e74bfa2b48f5fd9207e6bd7fd4292d7f6d37579d2601065fd6d6343eb1")
+      EDWARDS_D (alloc-const "EDWARDS_D" (scalar "2a9318e74bfa2b48f5fd9207e6bd7fd4292d7f6d37579d2601065fd6d6343eb1"))
       u1 (alloc "u1" (scalar "15a36d1f0f390d8852a35a8c1908dd87a361ee3fd48fdf77b9819dc82d90607e"))
       v1 (alloc "v1" (scalar "015d8c7f5b43fe33f7891142c001d9251f3abeeb98fad3e87b0dc53c4ebf1891"))
       u2 (alloc "u2" (scalar "15a36d1f0f390d8852a35a8c1908dd87a361ee3fd48fdf77b9819dc82d90607e"))

+ 21 - 2
lisp/lisp.rs

@@ -302,6 +302,23 @@ fn eval(mut ast: MalVal, mut env: Env) -> MalRet {
                         ast = eval(a1.clone(), env.clone())?;
                         prove(a1.clone(), env.clone())
                     }
+                    Sym(ref a0sym) if a0sym == "alloc-const" => {
+                        let a1 = l[1].clone();
+                        let value = eval(l[2].clone(), env.clone())?;
+                        let result = eval(value.clone(), env.clone())?;
+                        let allocs = get_allocations(&env, "AllocationsConst");
+                        let mut new_hm: FnvHashMap<String, MalVal> = FnvHashMap::default();
+                        for (k, v) in allocs.iter() {
+                            new_hm.insert(k.to_string(), eval(v.clone(), env.clone())?);
+                        }
+                        new_hm.insert(a1.pr_str(false), result.clone());
+                        env_set(
+                            &env,
+                            Sym("AllocationsConst".to_string()),
+                            Hash(Rc::new(new_hm), Rc::new(Nil)),
+                        )?;
+                        Ok(result.clone())
+                    }
                     Sym(ref a0sym) if a0sym == "alloc-input" => {
                         let a1 = l[1].clone();
                         let value = eval(l[2].clone(), env.clone())?;
@@ -503,10 +520,11 @@ pub fn setup(_ast: MalVal, env: Env) -> Result<PreparedVerifyingKey<Bls12>, MalE
     // be generated securely using a multiparty computation.
     let allocs_input = get_allocations(&env, "AllocationsInput");
     let allocs = get_allocations(&env, "Allocations");
+    let allocs_const = get_allocations(&env, "AllocationsConst");
     let enforce_allocs = get_enforce_allocs(&env);
 
     let c = LispCircuit {
-        params: vec![],
+        params: allocs_const.as_ref().clone(),
         allocs: allocs.as_ref().clone(),
         alloc_inputs: allocs_input.as_ref().clone(),
         constraints: enforce_allocs,
@@ -528,9 +546,10 @@ pub fn prove(_ast: MalVal, env: Env) -> MalRet {
     let allocs_input = get_allocations(&env, "AllocationsInput");
     let allocs = get_allocations(&env, "Allocations");
     let enforce_allocs = get_enforce_allocs(&env);
+    let allocs_const = get_allocations(&env, "AllocationsConst");
 
     let circuit = LispCircuit {
-        params: vec![],
+        params:  allocs.as_ref().clone(),
         allocs: allocs.as_ref().clone(),
         alloc_inputs: allocs_input.as_ref().clone(),
         constraints: enforce_allocs,

+ 1 - 1
lisp/types.rs

@@ -32,7 +32,7 @@ pub struct EnforceAllocation {
 
 #[derive(Debug, Clone)]
 pub struct LispCircuit {
-    pub params: Vec<Option<Scalar>>,
+    pub params: FnvHashMap<String, MalVal>,
     pub allocs: FnvHashMap<String, MalVal>,
     pub alloc_inputs: FnvHashMap<String, MalVal>,
     pub constraints: Vec<EnforceAllocation>,