diff --git a/phase2/src/circom_circuit.rs b/phase2/src/circom_circuit.rs index 5c21001..b760dfd 100644 --- a/phase2/src/circom_circuit.rs +++ b/phase2/src/circom_circuit.rs @@ -7,6 +7,7 @@ use std::fs::{OpenOptions, File}; use std::io::{Read, Write}; use std::collections::BTreeMap; use std::iter::repeat; +use std::sync::Arc; use itertools::Itertools; use rand::{Rng, OsRng}; use parameters::MPCParameters; @@ -27,6 +28,7 @@ use bellman_ce::{ }, pairing::{ Engine, + CurveAffine, ff::{ PrimeField, }, @@ -180,7 +182,9 @@ impl<'a, E: Engine> Circuit for CircomCircuit { } pub fn prove(circuit: CircomCircuit, params: &Parameters, mut rng: R) -> Result, SynthesisError> { - return create_random_proof(circuit, params, &mut rng); + let mut params2 = params.clone(); + filter_params(&mut params2); + return create_random_proof(circuit, ¶ms2, &mut rng); } pub fn verify(circuit: &CircomCircuit, params: &Parameters, proof: &Proof) -> Result { @@ -260,11 +264,18 @@ pub fn load_params_file(filename: &str) -> Parameters { pub fn load_params(reader: R) -> Parameters { let should_filter_points_at_infinity = false; - let mut params = MPCParameters::read(reader, should_filter_points_at_infinity, true).expect("unable to read params"); - params.filter_params(); + let params = MPCParameters::read(reader, should_filter_points_at_infinity, true).expect("unable to read params"); return params.get_params().clone(); } +pub fn filter_params(params: &mut Parameters) { + params.vk.ic = params.vk.ic.clone().into_iter().filter(|x| !x.is_zero()).collect::>(); + params.h = Arc::new((*params.h).clone().into_iter().filter(|x| !x.is_zero()).collect::>()); + params.a = Arc::new((*params.a).clone().into_iter().filter(|x| !x.is_zero()).collect::>()); + params.b_g1 = Arc::new((*params.b_g1).clone().into_iter().filter(|x| !x.is_zero()).collect::>()); + params.b_g2 = Arc::new((*params.b_g2).clone().into_iter().filter(|x| !x.is_zero()).collect::>()); +} + pub fn proving_key_json(params: &Parameters) -> Result { let proving_key = ProvingKeyJson { a: params.a.iter().map(|e| p1_to_vec(e)).collect_vec(), diff --git a/phase2/src/parameters.rs b/phase2/src/parameters.rs index 1c6dd32..db380ef 100644 --- a/phase2/src/parameters.rs +++ b/phase2/src/parameters.rs @@ -401,14 +401,6 @@ impl MPCParameters { &self.params } - pub fn filter_params(&mut self) { - self.params.vk.ic = self.params.vk.ic.clone().into_iter().filter(|x| !x.is_zero()).collect::>(); - self.params.h = Arc::new((*self.params.h).clone().into_iter().filter(|x| !x.is_zero()).collect::>()); - self.params.a = Arc::new((*self.params.a).clone().into_iter().filter(|x| !x.is_zero()).collect::>()); - self.params.b_g1 = Arc::new((*self.params.b_g1).clone().into_iter().filter(|x| !x.is_zero()).collect::>()); - self.params.b_g2 = Arc::new((*self.params.b_g2).clone().into_iter().filter(|x| !x.is_zero()).collect::>()); - } - /// Contributes some randomness to the parameters. Only one /// contributor needs to be honest for the parameters to be /// secure.