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

added const for right and output on circuit enforce

plato 5 лет назад
Родитель
Сommit
faaea967a6
4 измененных файлов с 26 добавлено и 7 удалено
  1. 8 5
      lisp/examples/macro-test.lisp
  2. 12 0
      lisp/types.rs
  3. 2 2
      run_mint.sh
  4. 4 0
      scripts/modp.py

+ 8 - 5
lisp/examples/macro-test.lisp

@@ -36,16 +36,19 @@
         (let* [u2 (gensym)
                v2 (gensym)
                u2v2 (gensym)
-               EDWARDS_D (gensym)
-               result (gensym)] (
+               EDWARDS_D (gensym)] (
         `(def! ~EDWARDS_D (alloc-const ~EDWARDS_D (scalar "2a9318e74bfa2b48f5fd9207e6bd7fd4292d7f6d37579d2601065fd6d6343eb1")))
         `(def! ~u2 (alloc ~u2 (get (nth (nth (zk-square ~val1) 0) 3) "v2")))
         `(def! ~v2 (alloc ~v2 (get (nth (nth (zk-square ~val2) 0) 3) "v2")))
-        `(def! result (alloc-input ~u2v2 (get (last (last (zk-mul ~u2 ~v2))) "result")))        
+        ;; `(def! result (alloc-input ~u2v2 (get (last (last (zk-mul ~u2 ~v2))) "result")))        
+        ;; `(def! ~u2 (alloc ~u2 (square ~val1)))
+        ;; `(def! ~v2 (alloc ~v2 (square ~val2)))
+        `(def! result (alloc-input ~u2v2 (* ~u2 ~v2)))        
         `(enforce  
             ((scalar::one::neg ~u2) (scalar::one ~v2))
             (scalar::one cs::one)
             ((scalar::one cs::one) (~EDWARDS_D ~u2v2))
+            ;; (scalar::one cs::one)
          )
         `{ "result" result }
         )
@@ -54,8 +57,8 @@
 
 (def! param1 (scalar 3))
 (def! param2 (scalar 9))
-(def! param-u (scalar "6800f4fa0f001cfc7ff6826ad58004b4d1d8da41af03744e3bce3b7793664337"))
-(def! param-v (scalar "6d81d3a9cb45dedbe6fb2a6e1e22ab50ad46f1b0473b803b3caefab9380b6a8b"))
+(def! param-u (scalar "273f910d9ecc1615d8618ed1d15fef4e9472c89ac043042d36183b2cb4d7ef51"))
+(def! param-v (scalar "466a7e3a82f67ab1d32294fd89774ad6bc3332d0fa1ccd18a77a81f50667c8d7"))
 (prove 
   (
     ;; (println (zk-square param1))

+ 12 - 0
lisp/types.rs

@@ -155,6 +155,12 @@ impl Circuit<bls12_381::Scalar> for LispCircuit {
                     right = right + (coeff, val_b);
                 } else if a == "scalar::one::neg" {
                     right = right + (coeff.neg(), val_b);
+                } else {
+                    if let Some(value) = params_const.get(a) {
+                        if let MalVal::ZKScalar(val) = value {
+                            right = right + (*val, val_b);
+                        }
+                    }
                 }
                 println!("right: a {:?} b {:?} val_b: {:?}", a, b, val_b);
             }
@@ -169,6 +175,12 @@ impl Circuit<bls12_381::Scalar> for LispCircuit {
                     output = output + (coeff, val_b);
                 } else if a == "scalar::one::neg" {
                     output = output + (coeff.neg(), val_b);
+                } else {
+                    if let Some(value) = params_const.get(a) {
+                        if let MalVal::ZKScalar(val) = value {
+                            output = output + (*val, val_b);
+                        }
+                    }
                 }
                 println!("output: a {:?} b {:?} val_b: {:?}", a, b, val_b);
             }

+ 2 - 2
run_mint.sh

@@ -1,5 +1,5 @@
 #!/bin/bash -x
-python scripts/preprocess.py proofs/mint2.psm > /tmp/mint2.psm || exit $?
-python scripts/compile.py --supervisor /tmp/mint2.psm --output mint.zcd || exit $?
+python3 scripts/preprocess.py proofs/mint2.psm > /tmp/mint2.psm || exit $?
+python3 scripts/compile.py --supervisor /tmp/mint2.psm --output mint.zcd || exit $?
 cargo run --release --bin mint
 

+ 4 - 0
scripts/modp.py

@@ -3,9 +3,13 @@ from finite_fields.modp import IntegersModP
 q = 0x73eda753299d7d483339d80809a1d80553bda402fffe5bfeffffffff00000001
 modq = IntegersModP(q)
 
+a = modq(-1) 
+print("0x%x" % a.n)
+print("\n")
 two = modq(2)
 inv2 = modq(2).inverse()
 print("Inverse of 2 = 0x%x" % inv2.n)
+print((two * inv2))
 # This is from bellman
 inv2_bellman = 0x39f6d3a994cebea4199cec0404d0ec02a9ded2017fff2dff7fffffff80000001
 assert inv2.n == inv2_bellman