فهرست منبع

ordered enforce

ada 5 سال پیش
والد
کامیت
181ef6cf10
3فایلهای تغییر یافته به همراه10 افزوده شده و 5 حذف شده
  1. 3 1
      lisp/lisp.rs
  2. 2 2
      lisp/run.sh
  3. 5 2
      lisp/types.rs

+ 3 - 1
lisp/lisp.rs

@@ -419,13 +419,15 @@ fn eval(mut ast: MalVal, mut env: Env) -> MalRet {
                             }
                             _ => {}
                         };
+                        let enforce_vec = get_enforce_allocs(&env);
                         let enforce = EnforceAllocation {
+                            idx: enforce_vec.len() + 1,
                             left: left_vec,
                             right: right_vec,
                             output: out_vec,
                         };
                         let mut new_vec: Vec<EnforceAllocation> = vec![enforce];
-                        for value in get_enforce_allocs(&env).iter() {
+                        for value in enforce_vec.iter() { 
                             new_vec.push(value.clone());
                         }
                         env_set(

+ 2 - 2
lisp/run.sh

@@ -1,3 +1,3 @@
 export RUST_BACKTRACE=full
-#cargo run --bin lisp load jubjub-add.lisp
-cargo run --bin lisp load inverse.lisp
+cargo run --bin lisp load jubjub-add.lisp
+#cargo run --bin lisp load new-cs.lisp

+ 5 - 2
lisp/types.rs

@@ -22,6 +22,7 @@ pub struct Allocation {
 
 #[derive(Debug, Clone)]
 pub struct EnforceAllocation {
+    pub idx: usize,
     pub left: Vec<(String, String)>,
     pub right: Vec<(String, String)>,
     pub output: Vec<(String, String)>,
@@ -113,8 +114,10 @@ impl Circuit<bls12_381::Scalar> for LispCircuit {
         }
 
         println!("Enforce Allocations\n");
-        // we need to keep order
-        for alloc_value in self.constraints.iter() {
+        let mut enforce_sorted = self.constraints.clone();
+        enforce_sorted.sort_by(|a, b| a.idx.cmp(&b.idx)); 
+        for alloc_value in enforce_sorted.iter() {
+            println!("Enforce -> {:?}", alloc_value);
             let coeff = bls12_381::Scalar::one();
             let mut left = bellman::LinearCombination::<Scalar>::zero();
             let mut right = bellman::LinearCombination::<Scalar>::zero();