Skip to content

Commit

Permalink
Merge pull request #1391 from succinctlabs/chris/recursion
Browse files Browse the repository at this point in the history
Add try_build_with_options
  • Loading branch information
puma314 authored Dec 1, 2023
2 parents 32d0096 + b598e6f commit 2d0df39
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 9 deletions.
36 changes: 28 additions & 8 deletions plonky2/src/plonk/circuit_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -917,9 +917,20 @@ impl<F: RichField + Extendable<D>, const D: usize> CircuitBuilder<F, D> {

/// Builds a "full circuit", with both prover and verifier data.
pub fn build_with_options<C: GenericConfig<D, F = F>>(
mut self,
self,
commit_to_sigma: bool,
) -> CircuitData<F, C, D> {
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<C: GenericConfig<D, F = F>>(
mut self,
commit_to_sigma: bool,
) -> (CircuitData<F, C, D>, bool) {
let mut timing = TimingTree::new("preprocess", Level::Trace);

#[cfg(feature = "std")]
Expand Down Expand Up @@ -1125,8 +1136,14 @@ impl<F: RichField + Extendable<D>, const D: usize> CircuitBuilder<F, D> {
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::<F, C, D> {
Expand All @@ -1151,11 +1168,14 @@ impl<F: RichField + Extendable<D>, const D: usize> CircuitBuilder<F, D> {
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<C: GenericConfig<D, F = F>>(self) -> CircuitData<F, C, D> {
Expand Down
2 changes: 1 addition & 1 deletion plonky2/src/plonk/circuit_data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ impl<F: RichField + Extendable<D>, C: GenericConfig<D, F = F>, const D: usize>
}

/// Circuit data required by the prover.
#[derive(Debug)]
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct VerifierCircuitData<
F: RichField + Extendable<D>,
C: GenericConfig<D, F = F>,
Expand Down

0 comments on commit 2d0df39

Please sign in to comment.