Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix MockProver assert_verify panic errors #118

Merged
merged 6 commits into from
Jan 9, 2023
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 32 additions & 10 deletions halo2_proofs/src/dev.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1315,6 +1315,27 @@ impl<F: FieldExt> MockProver<F> {
panic!("circuit was not satisfied");
}
}

/// Panics if the circuit being checked by this `MockProver` is not satisfied.
///
/// Any verification failures will be pretty-printed to stderr before the function
/// panics.
///
/// Internally, this function uses a parallel aproach in order to verify the `MockProver` contents.
///
/// Apart from the stderr output, this method is equivalent to:
/// ```ignore
/// assert_eq!(prover.verify_par(), Ok(()));
/// ```
pub fn assert_satisfied_par(&self) {
if let Err(errs) = self.verify_par() {
for err in errs {
err.emit(self);
eprintln!();
}
panic!("circuit was not satisfied");
}
}
}

#[cfg(test)]
Expand Down Expand Up @@ -1392,16 +1413,17 @@ mod tests {
}

let prover = MockProver::run(K, &FaultyCircuit {}, vec![]).unwrap();
assert_eq!(
prover.verify(),
Err(vec![VerifyFailure::CellNotAssigned {
gate: (0, "Equality check").into(),
region: (0, "Faulty synthesis".to_owned()).into(),
gate_offset: 1,
column: Column::new(1, Any::advice()),
offset: 1,
}])
);
prover.assert_satisfied();
// assert_eq!(
// prover.verify(),
// Err(vec![VerifyFailure::CellNotAssigned {
// gate: (0, "Equality check").into(),
// region: (0, "Faulty synthesis".to_owned()).into(),
// gate_offset: 1,
// column: Column::new(1, Any::advice()),
// offset: 1,
// }])
// );
CPerezz marked this conversation as resolved.
Show resolved Hide resolved
}

#[test]
Expand Down
18 changes: 9 additions & 9 deletions halo2_proofs/src/dev/failure.rs
Original file line number Diff line number Diff line change
Expand Up @@ -398,18 +398,18 @@ fn render_lookup<F: FieldExt>(

// Recover the fixed columns from the table expressions. We don't allow composite
// expressions for the table side of lookups.
let table_columns = lookup.table_expressions.iter().map(|expr| {
let lookup_columns = lookup.table_expressions.iter().map(|expr| {
expr.evaluate(
&|_| panic!("no constants in table expressions"),
&|_| panic!("no selectors in table expressions"),
&|query| format!("F{}", query.column_index),
&|_| panic!("no advice columns in table expressions"),
&|_| panic!("no instance columns in table expressions"),
&|_| panic!("no challenges in table expressions"),
&|_| panic!("no negations in table expressions"),
&|_, _| panic!("no sums in table expressions"),
&|_, _| panic!("no products in table expressions"),
&|_, _| panic!("no scaling in table expressions"),
&|query| format! {"A{}", query.column_index},
&|query| format! {"I{}", query.column_index},
&|challenge| format! {"C{}", challenge.index()},
&|query| format! {"-{}", query},
&|a, b| format! {"{} + {}", a,b},
&|a, b| format! {"{} * {}", a,b},
&|a, b| format! {"{} * {:?}", a, b},
)
});

Expand Down Expand Up @@ -441,7 +441,7 @@ fn render_lookup<F: FieldExt>(
eprint!("{}L{}", if i == 0 { "" } else { ", " }, i);
}
eprint!(") ∉ (");
for (i, column) in table_columns.enumerate() {
for (i, column) in lookup_columns.enumerate() {
eprint!("{}{}", if i == 0 { "" } else { ", " }, column);
}
eprintln!(")");
Expand Down
19 changes: 11 additions & 8 deletions halo2_proofs/src/dev/failure/emitter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,15 +120,18 @@ pub(super) fn expression_to_string<F: Field>(
&|query| {
layout
.get(&query.rotation.0)
.unwrap()
.get(
&(
Any::Advice(Advice { phase: query.phase }),
query.column_index,
.map(|map| {
map.get(
&(
Any::Advice(Advice { phase: query.phase }),
query.column_index,
)
.into(),
)
.into(),
)
.unwrap()
})
.flatten()
CPerezz marked this conversation as resolved.
Show resolved Hide resolved
.cloned()
.unwrap_or_else(|| String::new())
.clone()
},
&|query| {
Expand Down