Skip to content

Commit

Permalink
feat: add debugging functions
Browse files Browse the repository at this point in the history
Functions only available for testing:
* `ctx.debug_assert_false` for debug break point to search for other
  constrain failures in mock prover
* `assigned_value.debug_prank(prank_value)` to prank witness values for
  negative tests
  • Loading branch information
jonathanpwang committed Jul 26, 2023
1 parent d1beb92 commit cdac269
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions halo2-base/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,13 @@ impl<F: ScalarField> AssignedValue<F> {
_ => unreachable!(), // if trying to fetch an un-evaluated fraction, you will have to do something manual
}
}

/// Debug helper function for writing negative tests. This will change the **witness** value of the assigned cell
/// to `prank_value`. It does not change any constraints.
#[cfg(test)]
pub fn debug_prank(&mut self, prank_value: F) {
self.value = Assigned::Trivial(prank_value);
}
}

/// Represents a single thread of an execution trace.
Expand Down Expand Up @@ -413,4 +420,14 @@ impl<F: ScalarField> Context<F> {
self.zero_cell = Some(zero_cell);
zero_cell
}

#[cfg(test)]
/// Helper function for debugging using `MockProver`. This adds a constraint that always fails.
/// The `MockProver` will print out the row, column where it fails, so it serves as a debugging "break point"
/// so you can add to your code to search for where the actual constraint failure occurs.
pub fn debug_assert_false(&mut self) {
let one = self.load_constant(F::one());
let zero = self.load_zero();
self.constrain_equal(&one, &zero);
}
}

0 comments on commit cdac269

Please sign in to comment.