diff --git a/src/circuit_builder.rs b/src/circuit_builder.rs index a2c6d935..3b7db285 100644 --- a/src/circuit_builder.rs +++ b/src/circuit_builder.rs @@ -1,6 +1,5 @@ use std::collections::{HashMap, HashSet}; use std::convert::TryInto; -use std::sync::Arc; use std::time::Instant; use log::info; @@ -49,7 +48,7 @@ pub struct CircuitBuilder, const D: usize> { context: String, - pub marked_targets: Vec, + pub marked_targets: Vec>, /// Generators used to generate the witness. pub generators: Vec>>, @@ -308,7 +307,7 @@ impl, const D: usize> CircuitBuilder { self.context = new_context.to_string(); } - pub fn add_marked(&mut self, targets: Arc, name: &str) { + pub fn add_marked(&mut self, targets: Markable, name: &str) { self.marked_targets.push(MarkedTargets { targets, name: name.to_string(), diff --git a/src/circuit_data.rs b/src/circuit_data.rs index e2df2755..56b23e3c 100644 --- a/src/circuit_data.rs +++ b/src/circuit_data.rs @@ -131,7 +131,7 @@ pub(crate) struct ProverOnlyCircuitData, const D: usize> { pub copy_constraints: Vec, /// The concrete placement of each gate in the circuit. pub gate_instances: Vec>, - pub marked_targets: Vec, + pub marked_targets: Vec>, } /// Circuit data required by the verifier, but not the prover. diff --git a/src/fri/recursive_verifier.rs b/src/fri/recursive_verifier.rs index acc4268e..3faa9f08 100644 --- a/src/fri/recursive_verifier.rs +++ b/src/fri/recursive_verifier.rs @@ -1,5 +1,3 @@ -use std::sync::Arc; - use env_logger::builder; use itertools::izip; diff --git a/src/hash.rs b/src/hash.rs index eb8e146b..fd551a6c 100644 --- a/src/hash.rs +++ b/src/hash.rs @@ -1,7 +1,5 @@ //! Concrete instantiation of a hash function. -use std::sync::Arc; - use crate::circuit_builder::CircuitBuilder; use crate::field::extension_field::Extendable; use crate::field::field::Field; diff --git a/src/merkle_proofs.rs b/src/merkle_proofs.rs index 9e355a0d..a4652ca1 100644 --- a/src/merkle_proofs.rs +++ b/src/merkle_proofs.rs @@ -1,5 +1,3 @@ -use std::sync::Arc; - use anyhow::{ensure, Result}; use crate::circuit_builder::CircuitBuilder; @@ -10,7 +8,6 @@ use crate::hash::GMIMC_ROUNDS; use crate::hash::{compress, hash_or_noop}; use crate::proof::{Hash, HashTarget}; use crate::target::Target; -use crate::util::marking::MarkedTargets; use crate::wire::Wire; #[derive(Clone, Debug)] @@ -161,7 +158,6 @@ mod tests { use crate::field::extension_field::quartic::QuarticCrandallField; use crate::merkle_proofs::verify_merkle_proof; use crate::merkle_tree::MerkleTree; - use crate::util::marking::MarkedTargets; use crate::verifier::verify; use crate::witness::PartialWitness; @@ -208,64 +204,4 @@ mod tests { verify(proof, &data.verifier_only, &data.common) } - - #[test] - fn test_recursive_merkle_proof_yo() -> Result<()> { - type F = CrandallField; - type FF = QuarticCrandallField; - let config = CircuitConfig::large_config(); - let mut builder = CircuitBuilder::::new(config); - let mut pw = PartialWitness::new(); - - let eval = vec![ - 8165005271518921330, - 6083226207459673392, - 9958534500108693972, - 3430614617054831715, - 14276647488823198467, - 11751680815846448477, - 2771303161388554632, - 2371046485289351947, - 16743918419162514074, - 9932615810638040318, - 16314448410395528119, - 1511019414432045441, - 5645123553081661379, - 9778873694114674382, - 10629301051878288289, - 16655634835422730769, - 7474748727207643713, - 8501202586470516512, - 5612524789765317534, - 3026252715636633329, - 15131263578183166645, - 1869341605741303173, - 14645831398335944979, - 8356334351657818532, - 4888183615701827634, - 5994174007215505657, - 11524125964783895772, - 2202081323880269694, - 9827048951184368953, - 12675978139336549297, - 5868550852792001156, - ]; - let eval = eval - .into_iter() - .map(F::from_canonical_usize) - .collect::>(); - let data = builder.add_virtual_targets(eval.len()); - for j in 0..data.len() { - pw.set_target(data[j], eval[j]); - } - - dbg!(hash_or_noop(eval.clone())); - let hash = builder.hash_or_noop(data.clone()); - builder.add_marked(Arc::new(hash), "hash test"); - - let data = builder.build(); - let proof = data.prove(pw); - - verify(proof, &data.verifier_only, &data.common) - } } diff --git a/src/recursive_verifier.rs b/src/recursive_verifier.rs index 2f7a6d1e..940c0142 100644 --- a/src/recursive_verifier.rs +++ b/src/recursive_verifier.rs @@ -1,7 +1,3 @@ -use std::sync::Arc; - -use env_logger::builder; - use crate::circuit_builder::CircuitBuilder; use crate::circuit_data::{CircuitConfig, CommonCircuitData, VerifierCircuitTarget}; use crate::field::extension_field::Extendable; @@ -9,7 +5,6 @@ use crate::field::field::Field; use crate::gates::gate::{GateRef, PrefixedGate}; use crate::plonk_challenger::RecursiveChallenger; use crate::proof::{HashTarget, ProofTarget}; -use crate::util::marking::MarkedTargets; use crate::util::scaling::ReducingFactorTarget; use crate::vanishing_poly::eval_vanishing_poly_recursively; use crate::vars::EvaluationTargets; @@ -25,7 +20,6 @@ impl, const D: usize> CircuitBuilder { inner_config: &CircuitConfig, inner_verifier_data: &VerifierCircuitTarget, inner_common_data: &CommonCircuitData, - marked: &mut Vec, ) { assert!(self.config.num_wires >= MIN_WIRES); assert!(self.config.num_wires >= MIN_ROUTED_WIRES); @@ -76,14 +70,8 @@ impl, const D: usize> CircuitBuilder { &betas, &gammas, &alphas, - marked, ); - marked.push(MarkedTargets { - name: "vanishing polys".into(), - targets: Arc::new(vanishing_polys_zeta[0].clone()), - }); - self.set_context("Check vanishing and quotient polynomials."); let quotient_polys_zeta = &proof.openings.quotient_polys; let zeta_pow_deg = self.exp_u64_extension(zeta, 1 << inner_common_data.degree_bits as u64); @@ -364,7 +352,6 @@ mod tests { let mut builder = CircuitBuilder::::new(config.clone()); let mut pw = PartialWitness::new(); - let mut marked = Vec::new(); let pt = proof_to_proof_target(&proof, &mut builder); set_proof_target(&proof, &pt, &mut pw); @@ -373,7 +360,7 @@ mod tests { }; pw.set_hash_target(inner_data.constants_sigmas_root, vd.constants_sigmas_root); - builder.add_recursive_verifier(pt, &config, &inner_data, &cd, &mut marked); + builder.add_recursive_verifier(pt, &config, &inner_data, &cd); let data = builder.build(); let recursive_proof = data.prove(pw); diff --git a/src/util/marking.rs b/src/util/marking.rs index fd0a9e37..fc689137 100644 --- a/src/util/marking.rs +++ b/src/util/marking.rs @@ -1,53 +1,62 @@ use std::convert::TryInto; -use std::sync::Arc; use crate::field::extension_field::target::ExtensionTarget; +use crate::field::extension_field::Extendable; use crate::field::field::Field; use crate::proof::HashTarget; use crate::target::Target; use crate::witness::{PartialWitness, Witness}; -pub trait Markable: 'static + Send + Sync { - fn targets(&self) -> Vec; +#[derive(Clone)] +pub enum Markable { + Target(Target), + ExtensionTarget(ExtensionTarget), + HashTarget(HashTarget), + Vec(Vec>), } -impl Markable for Target { - fn targets(&self) -> Vec { - vec![*self] +impl From for Markable { + fn from(t: Target) -> Self { + Self::Target(t) + } +} +impl From> for Markable { + fn from(et: ExtensionTarget) -> Self { + Self::ExtensionTarget(et) + } +} +impl From for Markable { + fn from(ht: HashTarget) -> Self { + Self::HashTarget(ht) + } +} +impl>, const D: usize> From> for Markable { + fn from(v: Vec) -> Self { + Self::Vec(v.into_iter().map(|m| m.into()).collect()) } } -impl Markable for ExtensionTarget { - fn targets(&self) -> Vec { - self.0.try_into().unwrap() - } -} - -impl Markable for HashTarget { - fn targets(&self) -> Vec { - self.elements.try_into().unwrap() - } -} - -impl Markable for Vec { - fn targets(&self) -> Vec { - self.iter().flat_map(|m| m.targets()).collect() +impl Markable { + fn print_markable>(&self, pw: &PartialWitness) { + match self { + Markable::Target(t) => println!("{}", pw.get_target(*t)), + Markable::ExtensionTarget(et) => println!("{}", pw.get_extension_target(*et)), + Markable::HashTarget(ht) => println!("{:?}", pw.get_hash_target(*ht)), + Markable::Vec(v) => v.iter().for_each(|m| m.print_markable(pw)), + } } } #[derive(Clone)] -pub struct MarkedTargets { - pub targets: Arc, +pub struct MarkedTargets { + pub targets: Markable, pub name: String, } -impl MarkedTargets { - pub fn display(&self, pw: &PartialWitness) { - let targets = self.targets.targets(); +impl MarkedTargets { + pub fn display>(&self, pw: &PartialWitness) { println!("Values for {}:", self.name); - for &t in &targets { - println!("{}", pw.get_target(t)); - } + self.targets.print_markable(pw); println!("End of values for {}", self.name); } } diff --git a/src/vanishing_poly.rs b/src/vanishing_poly.rs index 6c336593..70d19230 100644 --- a/src/vanishing_poly.rs +++ b/src/vanishing_poly.rs @@ -335,7 +335,6 @@ pub fn evaluate_gate_constraints_recursively, const D: usize>( gates: &[PrefixedGate], num_gate_constraints: usize, vars: EvaluationTargets, - marked: &mut Vec, ) -> Vec> { let mut constraints = vec![builder.zero_extension(); num_gate_constraints]; for gate in gates { @@ -343,10 +342,6 @@ pub fn evaluate_gate_constraints_recursively, const D: usize>( .gate .0 .eval_filtered_recursively(builder, vars, &gate.prefix); - // marked.push(MarkedTargets { - // name: gate.gate.0.id(), - // targets: Box::new(gate_constraints.clone()), - // }); for (i, c) in gate_constraints.into_iter().enumerate() { constraints[i] = builder.add_extension(constraints[i], c); } @@ -370,7 +365,6 @@ pub(crate) fn eval_vanishing_poly_recursively, const D: usize>( betas: &[Target], gammas: &[Target], alphas: &[Target], - marked: &mut Vec, ) -> Vec> { let max_degree = common_data.quotient_degree_factor; let (num_prods, final_num_prod) = common_data.num_partial_products; @@ -380,7 +374,6 @@ pub(crate) fn eval_vanishing_poly_recursively, const D: usize>( &common_data.gates, common_data.num_gate_constraints, vars, - marked, ); // The L_1(x) (Z(x) - 1) vanishing terms. diff --git a/src/witness.rs b/src/witness.rs index 8b46d43f..1190fc8f 100644 --- a/src/witness.rs +++ b/src/witness.rs @@ -78,6 +78,12 @@ impl PartialWitness { ) } + pub fn get_hash_target(&self, ht: HashTarget) -> Hash { + Hash { + elements: self.get_targets(&ht.elements).try_into().unwrap(), + } + } + pub fn try_get_target(&self, target: Target) -> Option { self.target_values.get(&target).cloned() }