Pārlūkot izejas kodu

py: Proof.create() return None when failing rather than use .unwrap()

zero 2 gadi atpakaļ
vecāks
revīzija
74b7d2f7b8
2 mainītis faili ar 14 papildinājumiem un 5 dzēšanām
  1. 3 0
      bin/zkrunner/zkrunner.py
  2. 11 5
      src/sdk/python/src/zkas.rs

+ 3 - 0
bin/zkrunner/zkrunner.py

@@ -133,6 +133,9 @@ def main(witness_file, source_file, mock=False, trace=False):
     if not mock:
         print("Proving knowledge of witnesses...")
         proof = Proof.create(proving_key, [circuit], instances)
+        if proof is None:
+            eprint(f"Proof creation failed")
+            return -3
 
         if trace:
             show_trace(zkbin.opcodes(), circuit.opvalues())

+ 11 - 5
src/sdk/python/src/zkas.rs

@@ -232,7 +232,7 @@ impl Proof {
         pk: &PyCell<ProvingKey>,
         circuits: Vec<&PyCell<ZkCircuit>>,
         instances: Vec<&PyCell<Fp>>,
-    ) -> Self {
+    ) -> Option<Self> {
         let pk = pk.borrow().deref().0.clone();
 
         // Ugh this is so annoying. The halo2 API expects &[] of values.
@@ -268,16 +268,22 @@ impl Proof {
 
         let instances: Vec<pallas::Base> = instances.iter().map(|i| i.borrow().deref().0).collect();
 
-        let proof =
-            zk::proof::Proof::create(&pk, ucircuits.as_slice(), instances.as_slice(), &mut OsRng)
-                .unwrap();
+        let proof = match zk::proof::Proof::create(
+            &pk,
+            ucircuits.as_slice(),
+            instances.as_slice(),
+            &mut OsRng,
+        ) {
+            Ok(proof) => proof,
+            Err(_) => return None,
+        };
 
         // Now replace the "stuff" back again
         for (old_circ, (circ, stuff)) in circuits.iter().zip(ucircuits.into_iter().zip(other_stuff))
         {
             old_circ.replace(ZkCircuit(circ, stuff.0, stuff.1));
         }
-        Self(proof)
+        Some(Self(proof))
     }
 
     fn verify(&self, vk: &PyCell<VerifyingKey>, instances: Vec<&PyCell<Fp>>) -> bool {