Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
11 changes: 10 additions & 1 deletion src/linear_relation/canonical.rs
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,16 @@ impl<G: PrimeGroup> CanonicalLinearRelation<G> {
}
}

// Only include constraints that are non-trivial (not zero constraints)
// Only include constraints that are non-trivial (not zero constraints).
if rhs_terms.is_empty() {
if canonical_image.is_identity().into() {
return Ok(());
}
return Err(InvalidInstance::new(
"trivially false constraint: constraint has empty right-hand side and non-identity left-hand side",
));
}

self.image.push(canonical_image);
self.linear_combinations.push(rhs_terms);

Expand Down
16 changes: 12 additions & 4 deletions src/tests/test_validation_criteria.rs
Original file line number Diff line number Diff line change
Expand Up @@ -133,21 +133,29 @@ mod instance_validation {

// The following relation is trivially invalid.
// That is, we know that no witness will ever satisfy it.
// In this case, we're letting the prover fail and build the relation anyways.
let mut linear_relation = LinearRelation::<G>::new();
let B_var = linear_relation.allocate_element();
let C_var = linear_relation.allocate_eq(B_var);
linear_relation.set_elements([(B_var, B), (C_var, C)]);
assert!(linear_relation.canonical().is_ok());
assert!(linear_relation
.canonical()
.err()
.unwrap()
.message
.contains("trivially false constraint"));

// Also in this case, we know that no witness will ever satisfy the relation.
// Also here, the relation is built even though the prover will never be able to give a valid proof for it.
// X != B * pub_scalar + A * 3
let mut linear_relation = LinearRelation::<G>::new();
let [B_var, A_var] = linear_relation.allocate_elements();
let X_var = linear_relation.allocate_eq(B_var * pub_scalar + A_var * Scalar::from(3));
linear_relation.set_elements([(B_var, B), (A_var, A), (X_var, X)]);
assert!(linear_relation.canonical().is_ok());
assert!(linear_relation
.canonical()
.err()
.unwrap()
.message
.contains("trivially false constraint"));

// The following relation is valid and should pass.
let mut linear_relation = LinearRelation::<G>::new();
Expand Down
Loading