narodnik 5 лет назад
Родитель
Сommit
47131b3a53
4 измененных файлов с 42 добавлено и 4 удалено
  1. 5 0
      proofs/simple.pism
  2. 1 1
      proofs/working.pism
  3. 12 0
      scripts/codegen.py
  4. 24 3
      scripts/pism.py

+ 5 - 0
proofs/simple.pism

@@ -14,5 +14,10 @@ start
 
 
     ec_add public public ak
     ec_add public public ak
     emit_ec public
     emit_ec public
+
+    alloc_binary preimage
+    ec_repr repr_ak ak
+    binary_clone repr_ak2 repr_ak
+    binary_extend preimage repr_ak
 end
 end
 
 

+ 1 - 1
proofs/working.pism

@@ -55,7 +55,7 @@ start
     # let mut nf_preimage: BinaryNumber = []
     # let mut nf_preimage: BinaryNumber = []
     alloc_binary nf_preimage
     alloc_binary nf_preimage
     ec_repr repr_nk nk
     ec_repr repr_nk nk
-    binary_clone repr_nk repr_nk2
+    binary_clone repr_nk2 repr_nk
     # ivk_preimage.put(nk)
     # ivk_preimage.put(nk)
     binary_extend ivk_preimage repr_nk
     binary_extend ivk_preimage repr_nk
     # nf_preimage.put(nk)
     # nf_preimage.put(nk)

+ 12 - 0
scripts/codegen.py

@@ -26,6 +26,18 @@ r"""let %s = ecc::fixed_base_multiplication(
 def ec_add(line, out, a, b):
 def ec_add(line, out, a, b):
     return 'let %s = %s.add(cs.namespace(|| "%s"), &%s)?;' % (out, a, line, b)
     return 'let %s = %s.add(cs.namespace(|| "%s"), &%s)?;' % (out, a, line, b)
 
 
+def ec_repr(line, out, point):
+    return 'let %s = %s.repr(cs.namespace(|| "%s"))?;' % (out, point, line)
+
 def emit_ec(line, point):
 def emit_ec(line, point):
     return '%s.inputize(cs.namespace(|| "%s"))?;' % (point, line)
     return '%s.inputize(cs.namespace(|| "%s"))?;' % (point, line)
 
 
+def alloc_binary(line, out):
+    return "let mut %s = vec![];" % out
+
+def binary_clone(line, out, binary):
+    return "let %s = %s.iter().cloned()" % (out, binary)
+
+def binary_extend(line, binary, value):
+    return "%s.extend(%s);" % (binary, value)
+

+ 24 - 3
scripts/pism.py

@@ -15,7 +15,11 @@ symbol_table = {
     "fr_as_binary_le": 2,
     "fr_as_binary_le": 2,
     "ec_mul_const": 3,
     "ec_mul_const": 3,
     "ec_add": 3,
     "ec_add": 3,
-    "emit_ec": 1
+    "ec_repr": 2,
+    "emit_ec": 1,
+    "alloc_binary": 1,
+    "binary_clone": 2,
+    "binary_extend": 2,
 }
 }
 
 
 types_map = {
 types_map = {
@@ -48,9 +52,24 @@ command_desc = {
         ("EdwardsPoint",    False),
         ("EdwardsPoint",    False),
         ("EdwardsPoint",    False),
         ("EdwardsPoint",    False),
     ),
     ),
+    "ec_repr": (
+        ("Vec<Boolean>",    True),
+        ("EdwardsPoint",    False),
+    ),
     "emit_ec": (
     "emit_ec": (
         ("EdwardsPoint",    False),
         ("EdwardsPoint",    False),
-    )
+    ),
+    "alloc_binary": (
+        ("Vec<Boolean>",    True),
+    ),
+    "binary_clone": (
+        ("Vec<Boolean>",    True),
+        ("Vec<Boolean>",    False),
+    ),
+    "binary_extend": (
+        ("Vec<Boolean>",    False),
+        ("Vec<Boolean>",    False),
+    ),
 }
 }
 
 
 def eprint(*args):
 def eprint(*args):
@@ -258,6 +277,8 @@ use zcash_proofs::circuit::ecc;
 
 
             if is_param:
             if is_param:
                 actual_type = self.params[argname]
                 actual_type = self.params[argname]
+            elif argname in self.constants:
+                actual_type = self.constants[argname]
             else:
             else:
                 # Check the stack here
                 # Check the stack here
                 if argname not in self.stack:
                 if argname not in self.stack:
@@ -268,7 +289,7 @@ use zcash_proofs::circuit::ecc;
 
 
                 actual_type = self.stack[argname]
                 actual_type = self.stack[argname]
 
 
-            return True
+        return True
 
 
     def _check_args(self, command, args, line):
     def _check_args(self, command, args, line):
         assert command in command_desc
         assert command in command_desc