Skip to content

Commit

Permalink
Fix: false alarm in phase check of mock prover (#61)
Browse files Browse the repository at this point in the history
* fix false alarm in phase check of mock prover

* fix clippy

* clippy
  • Loading branch information
kunxian-xia authored Aug 17, 2023
1 parent 01f0b52 commit b612b1e
Showing 1 changed file with 26 additions and 4 deletions.
30 changes: 26 additions & 4 deletions halo2_proofs/src/dev.rs
Original file line number Diff line number Diff line change
Expand Up @@ -540,7 +540,7 @@ impl<'a, F: Field + Group> Assignment<F> for MockProver<'a, F> {

fn assign_advice<V, VR, A, AR>(
&mut self,
_: A,
anno: A,
column: Column<Advice>,
row: usize,
to: V,
Expand All @@ -551,6 +551,7 @@ impl<'a, F: Field + Group> Assignment<F> for MockProver<'a, F> {
A: FnOnce() -> AR,
AR: Into<String>,
{
// column of 2nd phase does not need to be assigned when synthesis at 1st phase
if self.current_phase.0 < column.column_type().phase.0 {
return Ok(());
}
Expand Down Expand Up @@ -578,7 +579,18 @@ impl<'a, F: Field + Group> Assignment<F> for MockProver<'a, F> {
.or_default();
}

let assigned = CellValue::Assigned(to().into_field().evaluate().assign()?);
let advice_anno = anno().into();
let val_res = to().into_field().evaluate().assign();
if val_res.is_err() {
log::debug!(
"[{}] assign to advice {:?} at row {} failed at phase {:?}",
advice_anno,
column,
row,
self.current_phase
);
}
let assigned = CellValue::Assigned(val_res?);
*self
.advice
.get_mut(column.index())
Expand Down Expand Up @@ -830,12 +842,16 @@ impl<'a, F: FieldExt> MockProver<'a, F> {
for current_phase in prover.cs.phases() {
prover.current_phase = current_phase;
prover.advice_prev = last_advice;
ConcreteCircuit::FloorPlanner::synthesize(
let syn_res = ConcreteCircuit::FloorPlanner::synthesize(
&mut prover,
circuit,
config.clone(),
constants.clone(),
)?;
);
if syn_res.is_err() {
log::error!("mock prover syn failed at phase {:?}", current_phase);
}
syn_res?;

for (index, phase) in prover.cs.challenge_phase.iter().enumerate() {
if current_phase == *phase {
Expand All @@ -861,6 +877,11 @@ impl<'a, F: FieldExt> MockProver<'a, F> {
panic!("wrong phase assignment");
}
}
if current_phase.0 < prover.cs.max_phase() {
// only keep the regions that we got during last phase's synthesis
// as we do not need to verify these regions.
prover.regions.clear();
}
last_advice = prover.advice_vec.as_ref().clone();
}
}
Expand Down Expand Up @@ -1309,6 +1330,7 @@ impl<'a, F: FieldExt> MockProver<'a, F> {

// Check that within each region, all cells used in instantiated gates have been
// assigned to.
log::debug!("regions.len() = {}", self.regions.len());
let selector_errors = self.regions.iter().enumerate().flat_map(|(r_i, r)| {
r.enabled_selectors.iter().flat_map(move |(selector, at)| {
// Find the gates enabled by this selector
Expand Down

0 comments on commit b612b1e

Please sign in to comment.