diff --git a/src/prover.rs b/src/prover.rs index 7f0e5399..16f63fdb 100644 --- a/src/prover.rs +++ b/src/prover.rs @@ -23,6 +23,11 @@ pub(crate) fn prove, const D: usize>( inputs: PartialWitness, ) -> Proof { let fri_config = &common_data.config.fri_config; + let config = &common_data.config; + let num_wires = config.num_wires; + let num_challenges = config.num_challenges; + let quotient_degree = common_data.quotient_degree(); + let degree = common_data.degree(); let start_proof_gen = Instant::now(); @@ -33,6 +38,11 @@ pub(crate) fn prove, const D: usize>( "to generate witness" ); + let witness = timed!( + partial_witness.full_witness(degree, num_wires), + "to compute full witness" + ); + timed!( witness .check_copy_constraints(&prover_data.copy_constraints, &prover_data.gate_instances) @@ -40,14 +50,6 @@ pub(crate) fn prove, const D: usize>( "to check copy constraints" ); - let config = &common_data.config; - let num_wires = config.num_wires; - let num_challenges = config.num_challenges; - let quotient_degree = common_data.quotient_degree(); - let degree = common_data.degree(); - - let witness = partial_witness.full_witness(degree, num_wires); - let wires_values: Vec> = timed!( witness .wire_values @@ -169,7 +171,7 @@ fn compute_zs, const D: usize>( witness: &Witness, betas: &[F], gammas: &[F], - prover_data: &ProverOnlyCircuitData, + prover_data: &ProverOnlyCircuitData, common_data: &CommonCircuitData, ) -> Vec> { (0..common_data.config.num_challenges) @@ -181,7 +183,7 @@ fn compute_z, const D: usize>( witness: &Witness, beta: F, gamma: F, - prover_data: &ProverOnlyCircuitData, + prover_data: &ProverOnlyCircuitData, common_data: &CommonCircuitData, ) -> PolynomialValues { let subgroup = &prover_data.subgroup; diff --git a/src/witness.rs b/src/witness.rs index a0e29268..7294f6e4 100644 --- a/src/witness.rs +++ b/src/witness.rs @@ -19,6 +19,41 @@ impl Witness { pub fn get_wire(&self, gate: usize, input: usize) -> F { self.wire_values[input][gate] } + + /// Checks that the copy constraints are satisfied in the witness. + pub fn check_copy_constraints( + &self, + copy_constraints: &[(Target, Target)], + gate_instances: &[GateInstance], + ) -> Result<()> + where + F: Extendable, + { + for &(a, b) in copy_constraints { + // TODO: Take care of public inputs once they land. + if let ( + Target::Wire(Wire { + gate: a_gate, + input: a_input, + }), + Target::Wire(Wire { + gate: b_gate, + input: b_input, + }), + ) = (a, b) + { + let va = self.get_wire(a_gate, a_input); + let vb = self.get_wire(b_gate, b_input); + ensure!( + va == vb, + "Copy constraint between wire {} of gate #{} (`{}`) and wire {} of gate #{} (`{}`) is not satisfied. \ + Got values of {} and {} respectively.", + a_input, a_gate, gate_instances[a_gate].gate_type.0.id(), b_input, b_gate, + gate_instances[b_gate].gate_type.0.id(), va, vb); + } + } + Ok(()) + } } #[derive(Clone, Debug)] @@ -145,31 +180,6 @@ impl PartialWitness { }); Witness { wire_values } } - - /// Checks that the copy constraints are satisfied in the witness. - pub fn check_copy_constraints( - &self, - copy_constraints: &[(Target, Target)], - gate_instances: &[GateInstance], - ) -> Result<()> - where - F: Extendable, - { - for &(a, b) in copy_constraints { - // TODO: Take care of public inputs once they land. - if let (Target::Wire(wa), Target::Wire(wb)) = (a, b) { - let va = self.target_values.get(&a).copied().unwrap_or(F::ZERO); - let vb = self.target_values.get(&b).copied().unwrap_or(F::ZERO); - ensure!( - va == vb, - "Copy constraint between wire {} of gate #{} (`{}`) and wire {} of gate #{} (`{}`) is not satisfied. \ - Got values of {} and {} respectively.", - wa.input, wa.gate, gate_instances[wa.gate].gate_type.0.id(), wb.input, wb.gate, - gate_instances[wb.gate].gate_type.0.id(), va, vb); - } - } - Ok(()) - } } impl Default for PartialWitness {