diff --git a/plonky2/src/plonk/circuit_builder.rs b/plonky2/src/plonk/circuit_builder.rs index 67db68649a..0da3ed60d6 100644 --- a/plonky2/src/plonk/circuit_builder.rs +++ b/plonky2/src/plonk/circuit_builder.rs @@ -8,7 +8,7 @@ use std::time::Instant; use hashbrown::{HashMap, HashSet}; use itertools::Itertools; -use log::{debug, info, Level}; +use log::{debug, info, warn, Level}; use plonky2_util::ceil_div_usize; use crate::field::cosets::get_unique_coset_shifts; @@ -917,9 +917,20 @@ impl, const D: usize> CircuitBuilder { /// Builds a "full circuit", with both prover and verifier data. pub fn build_with_options>( - mut self, + self, commit_to_sigma: bool, ) -> CircuitData { + let (circuit_data, success) = self.try_build_with_options(commit_to_sigma); + if !success { + panic!("Failed to build circuit"); + } + circuit_data + } + + pub fn try_build_with_options>( + mut self, + commit_to_sigma: bool, + ) -> (CircuitData, bool) { let mut timing = TimingTree::new("preprocess", Level::Trace); #[cfg(feature = "std")] @@ -1125,8 +1136,14 @@ impl, const D: usize> CircuitBuilder { num_lookup_selectors, luts: self.luts, }; + + let mut success = true; + if let Some(goal_data) = self.goal_common_data { - assert_eq!(goal_data, common, "The expected circuit data passed to cyclic recursion method did not match the actual circuit"); + if goal_data != common { + warn!("The expected circuit data passed to cyclic recursion method did not match the actual circuit"); + success = false; + } } let prover_only = ProverOnlyCircuitData:: { @@ -1151,11 +1168,14 @@ impl, const D: usize> CircuitBuilder { timing.print(); #[cfg(feature = "std")] debug!("Building circuit took {}s", start.elapsed().as_secs_f32()); - CircuitData { - prover_only, - verifier_only, - common, - } + ( + CircuitData { + prover_only, + verifier_only, + common, + }, + success, + ) } pub fn build>(self) -> CircuitData { diff --git a/plonky2/src/plonk/circuit_data.rs b/plonky2/src/plonk/circuit_data.rs index c93de8cb98..e850cb4269 100644 --- a/plonky2/src/plonk/circuit_data.rs +++ b/plonky2/src/plonk/circuit_data.rs @@ -265,7 +265,7 @@ impl, C: GenericConfig, const D: usize> } /// Circuit data required by the prover. -#[derive(Debug)] +#[derive(Debug, Clone, PartialEq, Eq)] pub struct VerifierCircuitData< F: RichField + Extendable, C: GenericConfig,