Sfoglia il codice sorgente

Merge branch 'master' of github.com:narodnik/sapvi into master

narodnik 5 anni fa
parent
commit
1f040cc862
6 ha cambiato i file con 32 aggiunte e 27 eliminazioni
  1. 7 0
      run_mimc2.sh
  2. 1 1
      src/bin/mimc.rs
  3. 1 1
      src/bin/mint.rs
  4. 5 7
      src/bin/zkvm.rs
  5. 1 2
      src/vm.rs
  6. 17 16
      src/vm_serial.rs

+ 7 - 0
run_mimc2.sh

@@ -0,0 +1,7 @@
+#!/bin/bash -x
+python scripts/preprocess.py proofs/mimc.psm > /tmp/mimc.psm || exit $?
+python scripts/compile.py --supervisor /tmp/mimc.psm --output mimc.zcd || exit $?
+cargo run --release --bin zkvm -- init mimc.zcd mimc.zts
+cargo run --release --bin zkvm -- prove mimc.zcd mimc.zts proofs/mimc.params mimc.prf
+cargo run --release --bin zkvm -- verify mimc.zcd mimc.zts mimc.prf
+cargo run --release --bin zkvm -- show mimc.prf

+ 1 - 1
src/bin/mimc.rs

@@ -77,7 +77,7 @@ fn main() -> Result<()> {
 
     // Do the trusted setup
 
-    contract.setup();
+    contract.setup("mimc.zts");
 
     // Put in our input parameters
 

+ 1 - 1
src/bin/mint.rs

@@ -56,7 +56,7 @@ fn main() -> Result<()> {
         visor.vm.constraints.len()
     );
 
-    visor.setup();
+    visor.setup("mint.zts");
 
     // We use the ExtendedPoint in calculations because it's faster
     let public_point = jubjub::ExtendedPoint::from(jubjub::SubgroupPoint::random(&mut OsRng));

+ 5 - 7
src/bin/zkvm.rs

@@ -52,8 +52,8 @@ fn create_proof(
     let lines: Vec<&str> = param_content.lines().collect();
     for line in lines {
         let name = line.split_whitespace().next().unwrap_or("");
-        let value = line.trim_start_matches(name).trim_left();
-        contract.set_param(name, Scalar::from_string(value));
+        let value = line.trim_start_matches(name).trim_start();
+        contract.set_param(name, Scalar::from_string(value))?;
         println!("Set parameter: {}", name);
         println!("      Value: {}", value);
     }
@@ -65,26 +65,24 @@ fn create_proof(
 
 //verify the proof
 fn verify_proof(contract_data: String, setup_file: String, zk_proof: String) -> Result<()> {
-    let start = Instant::now();
     let contract_file = File::open(contract_data)?;
     let mut contract = ZKContract::decode(contract_file)?;
     contract.load_setup(&setup_file)?;
     let proof_file = File::open(zk_proof)?;
     let proof = ZKProof::decode(proof_file)?;
-    if (contract.verify(&proof)) {
+    if contract.verify(&proof) {
         println!("Zero-knowledge proof verified correctly.")
     } else {
-        println!("Verification failed.")
+        eprintln!("Verification failed.")
     }
     Ok(())
 }
 
 // show public values in proof
 fn show_public(zk_proof: String) -> Result<()> {
-    let start = Instant::now();
     let file = File::open(zk_proof)?;
     let proof = ZKProof::decode(file)?;
-    assert_eq!(proof.public.len(), 2);
+    //assert_eq!(proof.public.len(), 2);
     println!("Public values: {:?}", proof.public);
     Ok(())
 }

+ 1 - 2
src/vm.rs

@@ -1,7 +1,6 @@
 use bellman::{
     gadgets::{
-        boolean::{AllocatedBit, Boolean},
-        multipack, num, Assignment,
+        Assignment,
     },
     groth16, Circuit, ConstraintSystem, SynthesisError,
 };

+ 17 - 16
src/vm_serial.rs

@@ -1,7 +1,8 @@
 use crate::error::{Error, Result};
 use crate::serial::{Decodable, Encodable, ReadExt, VarInt};
 use crate::vm::{
-    AllocType, ConstraintInstruction, CryptoOperation, VariableIndex, VariableRef, ZKVirtualMachine,
+    AllocType, ConstraintInstruction, CryptoOperation, VariableIndex, VariableRef, 
+    ZKVirtualMachine,
 };
 use crate::{impl_vec, ZKContract, ZKProof};
 use bellman::groth16;
@@ -13,9 +14,9 @@ impl_vec!((String, VariableIndex));
 impl_vec!((String, bls::Scalar));
 
 impl Encodable for ZKContract {
-    fn encode<S: io::Write>(&self, mut s: S) -> Result<usize> {
+    fn encode<S: io::Write>(&self, _s: S) -> Result<usize> {
         unimplemented!();
-        Ok(0)
+        //Ok(0)
     }
 }
 
@@ -70,7 +71,7 @@ impl Decodable for ZKProof {
 }
 
 impl Encodable for groth16::Proof<bls::Bls12> {
-    fn encode<S: io::Write>(&self, mut s: S) -> Result<usize> {
+    fn encode<S: io::Write>(&self, s: S) -> Result<usize> {
         self.write(s)?;
         // Depends on groth16 impl
         Ok(48 + 96 + 48)
@@ -78,17 +79,17 @@ impl Encodable for groth16::Proof<bls::Bls12> {
 }
 
 impl Decodable for groth16::Proof<bls::Bls12> {
-    fn decode<D: io::Read>(mut d: D) -> Result<Self> {
+    fn decode<D: io::Read>(d: D) -> Result<Self> {
         Ok(groth16::Proof::read(d)?)
     }
 }
 
 impl Encodable for (AllocType, VariableIndex) {
-    fn encode<S: io::Write>(&self, mut s: S) -> Result<usize> {
+    fn encode<S: io::Write>(&self, _s: S) -> Result<usize> {
         //let len = self.x.encode(&mut s)?;
         //Ok(len + self.y.encode(s)?)
         unimplemented!();
-        Ok(0)
+        //Ok(0)
     }
 }
 
@@ -108,9 +109,9 @@ impl Decodable for (AllocType, VariableIndex) {
 impl_vec!((AllocType, VariableIndex));
 
 impl Encodable for VariableIndex {
-    fn encode<S: io::Write>(&self, mut s: S) -> Result<usize> {
+    fn encode<S: io::Write>(&self, _s: S) -> Result<usize> {
         unimplemented!();
-        Ok(0)
+        //Ok(0)
     }
 }
 
@@ -121,9 +122,9 @@ impl Decodable for VariableIndex {
 }
 
 impl Encodable for VariableRef {
-    fn encode<S: io::Write>(&self, mut s: S) -> Result<usize> {
+    fn encode<S: io::Write>(&self, _s: S) -> Result<usize> {
         unimplemented!();
-        Ok(0)
+        //Ok(0)
     }
 }
 
@@ -139,9 +140,9 @@ impl Decodable for VariableRef {
 }
 
 impl Encodable for CryptoOperation {
-    fn encode<S: io::Write>(&self, mut s: S) -> Result<usize> {
+    fn encode<S: io::Write>(&self, _s: S) -> Result<usize> {
         unimplemented!();
-        Ok(0)
+        //Ok(0)
     }
 }
 
@@ -188,7 +189,7 @@ impl Decodable for CryptoOperation {
             )),
             12 => Ok(Self::DumpAlloc),
             13 => Ok(Self::DumpLocal),
-            i => Err(Error::BadOperationType),
+            _i => Err(Error::BadOperationType),
         }
     }
 }
@@ -196,9 +197,9 @@ impl Decodable for CryptoOperation {
 impl_vec!(CryptoOperation);
 
 impl Encodable for ConstraintInstruction {
-    fn encode<S: io::Write>(&self, mut s: S) -> Result<usize> {
+    fn encode<S: io::Write>(&self, _s: S) -> Result<usize> {
         unimplemented!();
-        Ok(0)
+        //Ok(0)
     }
 }