Skip to content

Commit 11162ca

Browse files
committed
fix(linear_relation): remove redundant (and wrong) checks.
1 parent 46b9cdf commit 11162ca

File tree

2 files changed

+42
-14
lines changed

2 files changed

+42
-14
lines changed

src/linear_relation/canonical.rs

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -370,14 +370,8 @@ impl<G: PrimeGroup> TryFrom<&LinearRelation<G>> for CanonicalLinearRelation<G> {
370370
for (lhs, rhs) in
371371
iter::zip(&relation.image, &relation.linear_map.linear_combinations)
372372
{
373-
374-
// If the linear combination is empty, skip it
375-
if rhs.0.is_empty() {
376-
continue;
377-
}
378-
379373
// If the linear combination is trivial, check it directly and skip processing.
380-
if !rhs.0.is_empty() && rhs.0.iter().all(|weighted| matches!(weighted.term.scalar, ScalarTerm::Unit)) {
374+
if rhs.0.iter().all(|weighted| matches!(weighted.term.scalar, ScalarTerm::Unit)) {
381375
let lhs_value = relation
382376
.linear_map
383377
.group_elements

src/tests/test_validation_criteria.rs

Lines changed: 41 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
66
#[cfg(test)]
77
mod instance_validation {
8-
use crate::linear_relation::{CanonicalLinearRelation, LinearRelation};
8+
use crate::linear_relation::{CanonicalLinearRelation, LinearRelation, Sum, Term, Weighted};
99
use bls12_381::{G1Projective as G, Scalar};
1010

1111
#[test]
@@ -113,14 +113,34 @@ mod instance_validation {
113113
}
114114

115115
#[test]
116-
fn without_witness() {
117-
let B = G::generator();
118-
let A = G::generator() * Scalar::from(42);
119-
let X = G::generator() * Scalar::from(4);
116+
fn test_statement_without_witness() {
120117
let pub_scalar = Scalar::from(42);
118+
let A = G::generator();
119+
let B = G::generator() * Scalar::from(42);
120+
let C = B * pub_scalar + A * Scalar::from(3);
121+
122+
let X = G::generator() * Scalar::from(4);
123+
124+
// The following relation is invalid and should trigger a fail.
125+
let mut linear_relation = LinearRelation::<G>::new();
126+
let B_var = linear_relation.allocate_element();
127+
let C_var = linear_relation.allocate_eq(B_var);
128+
linear_relation.set_element(B_var, B);
129+
linear_relation.set_element(C_var, C);
130+
let result = CanonicalLinearRelation::try_from(&linear_relation);
131+
assert!(result.is_err());
121132

122-
// The following relation does not have a witness and should trigger a fail.
123-
// X = B * pub_scalar + A * 3
133+
// The following relation is valid and should pass.
134+
let mut linear_relation = LinearRelation::<G>::new();
135+
let B_var = linear_relation.allocate_element();
136+
let C_var = linear_relation.allocate_eq(B_var);
137+
linear_relation.set_element(B_var, B);
138+
linear_relation.set_element(C_var, B);
139+
let result = CanonicalLinearRelation::try_from(&linear_relation);
140+
assert!(result.is_ok());
141+
142+
// The following relation is invalid and should trigger a fail.
143+
// X != B * pub_scalar + A * 3
124144
let mut linear_relation = LinearRelation::<G>::new();
125145
let B_var = linear_relation.allocate_element();
126146
let A_var = linear_relation.allocate_element();
@@ -133,6 +153,20 @@ mod instance_validation {
133153
let result = CanonicalLinearRelation::try_from(&linear_relation);
134154
assert!(result.is_err());
135155

156+
// The following relation is valid and should pass.
157+
// C = B * pub_scalar + A * 3
158+
let mut linear_relation = LinearRelation::<G>::new();
159+
let B_var = linear_relation.allocate_element();
160+
let A_var = linear_relation.allocate_element();
161+
let C_var = linear_relation.allocate_eq(B_var * pub_scalar + A_var * Scalar::from(3));
162+
163+
linear_relation.set_element(B_var, B);
164+
linear_relation.set_element(A_var, A);
165+
linear_relation.set_element(C_var, C);
166+
167+
let result = CanonicalLinearRelation::try_from(&linear_relation);
168+
assert!(result.is_ok());
169+
136170
// The following relation is for
137171
// X = B * x + B * pub_scalar + A * 3
138172
// and should be considered a valid instance.

0 commit comments

Comments
 (0)