Skip to content

Commit e4ace3c

Browse files
authored
Merge pull request #70 from sigma-rs/victor/a-check-and-a-question
Skip addition of trivial constraints to canonical representation of the linear relation
2 parents 2a29ac1 + 04ae71b commit e4ace3c

File tree

2 files changed

+22
-5
lines changed

2 files changed

+22
-5
lines changed

src/linear_relation/canonical.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,16 @@ impl<G: PrimeGroup> CanonicalLinearRelation<G> {
162162
}
163163
}
164164

165-
// Only include constraints that are non-trivial (not zero constraints)
165+
// Only include constraints that are non-trivial (not zero constraints).
166+
if rhs_terms.is_empty() {
167+
if canonical_image.is_identity().into() {
168+
return Ok(());
169+
}
170+
return Err(InvalidInstance::new(
171+
"trivially false constraint: constraint has empty right-hand side and non-identity left-hand side",
172+
));
173+
}
174+
166175
self.image.push(canonical_image);
167176
self.linear_combinations.push(rhs_terms);
168177

src/tests/test_validation_criteria.rs

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -133,21 +133,29 @@ mod instance_validation {
133133

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

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

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

0 commit comments

Comments
 (0)