Skip to content

Commit 02fed63

Browse files
authored
Fix constraint satisfaction check (#409)
* Fix constraint satisfaction check * Address comments
1 parent 4c740f7 commit 02fed63

File tree

2 files changed

+11
-4
lines changed

2 files changed

+11
-4
lines changed

relations/src/gr1cs/predicate/mod.rs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -183,12 +183,20 @@ impl<F: Field> PredicateConstraintSystem<F> {
183183
/// Check if the constraints enforced by this predicate are satisfied
184184
/// i.e. `L(x_1, x_2, ..., x_n) == 0`.
185185
pub fn which_constraint_is_unsatisfied(&self, cs: &ConstraintSystem<F>) -> Option<usize> {
186+
let panic_msg = |v| panic!("Variable {v:?} is not assigned; did you run `cs.finalize()`?");
186187
for (i, constraint) in self.iter_constraints().enumerate() {
187188
let variables: Vec<F> = constraint
188189
.into_iter()
189-
.map(|variable| cs.assigned_value(variable).unwrap())
190+
.map(|v| {
191+
cs.assigned_value(v).unwrap_or_else(|| {
192+
cs.get_lc(v)
193+
.iter()
194+
.map(|&(c, v)| c * cs.assigned_value(v).unwrap_or_else(|| panic_msg(v)))
195+
.sum()
196+
})
197+
})
190198
.collect();
191-
if self.predicate.is_satisfied(&variables) {
199+
if !self.predicate.is_satisfied(&variables) {
192200
return Some(i);
193201
}
194202
}

relations/src/gr1cs/predicate/polynomial_constraint.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,7 @@ impl<F: Field> PolynomialPredicate<F> {
4444
impl<F: Field> PolynomialPredicate<F> {
4545
/// Check if the predicate is satisfied by the given variables.
4646
pub fn is_satisfied(&self, variables: &[F]) -> bool {
47-
// TODO: Change the polynomial eval to get a slice as an evaluation point
48-
!self.polynomial.evaluate(&variables.to_vec()).is_zero()
47+
self.polynomial.evaluate(&variables.to_vec()).is_zero()
4948
}
5049

5150
/// Evaluate the predicate on the given variables.

0 commit comments

Comments
 (0)