Skip to content

Commit 1f8cd01

Browse files
committed
fix(linear_relation): relation can be skipped also if weights are zero
1 parent d3c55de commit 1f8cd01

File tree

2 files changed

+17
-6
lines changed

2 files changed

+17
-6
lines changed

src/linear_relation/canonical.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -381,7 +381,7 @@ impl<G: PrimeGroup> TryFrom<&LinearRelation<G>> for CanonicalLinearRelation<G> {
381381
if rhs
382382
.0
383383
.iter()
384-
.all(|weighted| matches!(weighted.term.scalar, ScalarTerm::Unit))
384+
.all(|weighted| matches!(weighted.term.scalar, ScalarTerm::Unit) || weighted.weight.is_zero_vartime())
385385
{
386386
let rhs_value = rhs.0.iter().fold(G::identity(), |acc, weighted| {
387387
acc + relation

src/tests/test_validation_criteria.rs

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ mod instance_validation {
1515

1616
// Allocate scalars and elements
1717
let [var_x] = relation.allocate_scalars();
18-
let [var_g, var_x_g] = relation.allocate_elements::<2>();
18+
let [var_g, var_x_g] = relation.allocate_elements();
1919

2020
// Set only one element, leaving var_g unassigned
2121
let x_val = G::generator() * Scalar::from(42u64);
@@ -43,14 +43,26 @@ mod instance_validation {
4343
assert!(result.is_err());
4444

4545
// Create a trivially valid linear relation with zero elements in the image
46-
// 0 = 0*B (which is invalid)
46+
// 0 = 0*B
4747
let mut relation = LinearRelation::<G>::new();
4848
let [var_B] = relation.allocate_elements();
4949
let var_X = relation.allocate_eq(var_B * Scalar::from(0));
5050
relation.set_element(var_B, G::generator());
5151
relation.set_element(var_X, G::identity());
5252
let result = CanonicalLinearRelation::try_from(&relation);
5353
assert!(result.is_ok());
54+
55+
// Create a valid linear relation with zero elements in the image
56+
// 0 = 0*x*C
57+
let mut relation = LinearRelation::<G>::new();
58+
let [var_x] = relation.allocate_scalars();
59+
let [var_C] = relation.allocate_elements();
60+
let var_X = relation.allocate_eq(var_C * var_x * Scalar::from(0));
61+
relation.set_element(var_C, G::generator());
62+
relation.set_element(var_X, G::identity());
63+
let result = CanonicalLinearRelation::try_from(&relation);
64+
assert!(result.is_ok());
65+
5466
}
5567

5668
#[test]
@@ -81,7 +93,7 @@ mod instance_validation {
8193
// Create a relation with mismatched equations and image elements
8294
let mut relation = LinearRelation::<G>::new();
8395
let [var_x] = relation.allocate_scalars();
84-
let [var_g, var_h] = relation.allocate_elements::<2>();
96+
let [var_g, var_h] = relation.allocate_elements();
8597
relation.set_elements([
8698
(var_g, G::generator()),
8799
(var_h, G::generator() * Scalar::from(2u64)),
@@ -110,8 +122,7 @@ mod instance_validation {
110122
let mut relation = LinearRelation::<G>::new();
111123
let var_B = relation.allocate_element();
112124
let var_C = relation.allocate_eq(var_B * Scalar::from(1));
113-
relation.set_element(var_B, G::generator());
114-
relation.set_element(var_C, G::generator());
125+
relation.set_elements([(var_B, G::generator()), (var_C, G::generator())]);
115126
assert!(CanonicalLinearRelation::try_from(&relation).is_ok());
116127
}
117128

0 commit comments

Comments
 (0)