Skip to content

Commit

Permalink
improve debugging: add sanity check to opcode prover (#279)
Browse files Browse the repository at this point in the history
  • Loading branch information
hero78119 authored Sep 25, 2024
1 parent 0e472dc commit ccc8c91
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 3 deletions.
1 change: 1 addition & 0 deletions ceno_zkvm/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ pub enum ZKVMError {
CircuitError,
UtilError(UtilError),
WitnessNotFound(String),
InvalidWitness(String),
VKNotFound(String),
FixedTraceNotFound(String),
VerifyError(String),
Expand Down
21 changes: 20 additions & 1 deletion ceno_zkvm/src/scheme/prover.rs
Original file line number Diff line number Diff line change
Expand Up @@ -473,11 +473,30 @@ impl<E: ExtensionField, PCS: PolynomialCommitmentScheme<E>> ZKVMProver<E, PCS> {
assert!(sel_non_lc_zero_sumcheck.is_some());

// \sum_t (sel(rt, t) * (\sum_j alpha_{j} * all_monomial_terms(t) ))
for (expr, alpha) in cs
for ((expr, name), alpha) in cs
.assert_zero_sumcheck_expressions
.iter()
.zip_eq(cs.assert_zero_sumcheck_expressions_namespace_map.iter())
.zip_eq(alpha_pow_iter)
{
// sanity check in debug build and output != instance index for zero check sumcheck poly
if cfg!(debug_assertions) {
let expected_zero_poly = wit_infer_by_expr(&[], &witnesses, challenges, expr);
let top_100_errors = expected_zero_poly
.get_ext_field_vec()
.iter()
.enumerate()
.filter(|(_, v)| **v != E::ZERO)
.take(100)
.collect_vec();
if !top_100_errors.is_empty() {
return Err(ZKVMError::InvalidWitness(format!(
"degree > 1 zero check virtual poly: expr {name} != 0 on instance indexes: {}...",
top_100_errors.into_iter().map(|(i, _)| i).join(",")
)));
}
}

distrinct_zerocheck_terms_set.extend(virtual_polys.add_mle_list_by_expr(
sel_non_lc_zero_sumcheck.as_ref(),
witnesses.iter().collect_vec(),
Expand Down
5 changes: 3 additions & 2 deletions ceno_zkvm/src/uint/arithmetic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -326,9 +326,10 @@ impl<const M: usize, E: ExtensionField> UIntLimbs<M, 8, E> {
si.iter()
.zip(self.limbs.iter())
.zip(rhs.limbs.iter())
.try_for_each(|((flag, a), b)| {
.enumerate()
.try_for_each(|(i, ((flag, a), b))| {
circuit_builder.require_zero(
|| "byte diff zero check",
|| format!("byte diff {i} zero check"),
a.expr() - b.expr() - flag.expr() * a.expr() + flag.expr() * b.expr(),
)
})?;
Expand Down

0 comments on commit ccc8c91

Please sign in to comment.