@@ -5,6 +5,7 @@ use group::prime::PrimeGroup;
55use rand:: rngs:: OsRng ;
66use rand:: RngCore ;
77
8+ use crate :: composition:: ComposedRelation ;
89use crate :: fiat_shamir:: Nizk ;
910use crate :: {
1011 codec:: Shake128DuplexSponge , linear_relation:: CanonicalLinearRelation ,
@@ -266,6 +267,28 @@ pub fn weird_linear_combination<G: PrimeGroup, R: RngCore>(
266267 ( instance, witness)
267268}
268269
270+
271+ fn test_relation_with_subtractions < G : PrimeGroup , R : RngCore > (
272+ mut rng : & mut R ,
273+ ) -> ( CanonicalLinearRelation < G > , Vec < G :: Scalar > ) {
274+ use ff:: PrimeField ;
275+
276+ let x = G :: Scalar :: random ( & mut rng) ;
277+ let B = G :: random ( & mut rng) ;
278+ let X = B * ( x - G :: Scalar :: from_u128 ( 1u128 ) ) ;
279+
280+ let mut linear_relation = LinearRelation :: < G > :: new ( ) ;
281+ let x_var = linear_relation. allocate_scalar ( ) ;
282+ let B_var = linear_relation. allocate_element ( ) ;
283+ let X_var = linear_relation
284+ . allocate_eq ( ( x_var + ( -G :: Scalar :: from_u128 ( 1u128 ) ) ) * B_var ) ;
285+ linear_relation. set_element ( B_var , B ) ;
286+ linear_relation. set_element ( X_var , X ) ;
287+
288+ let instance = ( & linear_relation) . try_into ( ) . unwrap ( ) ;
289+ let witness = vec ! [ x] ;
290+ ( instance, witness)
291+ }
269292/// Generic helper function to test both relation correctness and NIZK functionality
270293#[ test]
271294fn test_common_relations ( ) {
@@ -291,6 +314,7 @@ fn test_common_relations() {
291314 "weird_linear_combination" ,
292315 Box :: new ( weird_linear_combination) ,
293316 ) ;
317+ instance_generators. insert ( "test_relation_with_subtractions" , Box :: new ( test_relation_with_subtractions) ) ;
294318
295319 for ( relation_name, relation_sampler) in instance_generators. iter ( ) {
296320 let mut rng = OsRng ;
0 commit comments