55
66#[ cfg( test) ]
77mod 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