@@ -5,7 +5,7 @@ use group::prime::PrimeGroup;
55use rand:: rngs:: OsRng ;
66use rand:: RngCore ;
77
8- use crate :: composition :: ComposedRelation ;
8+ use ff :: PrimeField ;
99use crate :: fiat_shamir:: Nizk ;
1010use crate :: {
1111 codec:: Shake128DuplexSponge , linear_relation:: CanonicalLinearRelation ,
@@ -268,11 +268,9 @@ pub fn weird_linear_combination<G: PrimeGroup, R: RngCore>(
268268}
269269
270270
271- fn test_relation_with_subtractions < G : PrimeGroup , R : RngCore > (
271+ fn simple_subtractions < G : PrimeGroup , R : RngCore > (
272272 mut rng : & mut R ,
273273) -> ( CanonicalLinearRelation < G > , Vec < G :: Scalar > ) {
274- use ff:: PrimeField ;
275-
276274 let x = G :: Scalar :: random ( & mut rng) ;
277275 let B = G :: random ( & mut rng) ;
278276 let X = B * ( x - G :: Scalar :: from_u128 ( 1u128 ) ) ;
@@ -289,6 +287,28 @@ fn test_relation_with_subtractions<G: PrimeGroup, R: RngCore>(
289287 let witness = vec ! [ x] ;
290288 ( instance, witness)
291289}
290+
291+ fn subtractions_with_shift < G : PrimeGroup , R : RngCore > (
292+ mut rng : & mut R ,
293+ ) -> ( CanonicalLinearRelation < G > , Vec < G :: Scalar > ) {
294+
295+ let B = G :: generator ( ) ;
296+ let x = G :: Scalar :: random ( & mut rng) ;
297+ let X = B * ( x - G :: Scalar :: from ( 2 ) ) ;
298+
299+ let mut linear_relation = LinearRelation :: < G > :: new ( ) ;
300+ let x_var = linear_relation. allocate_scalar ( ) ;
301+ let B_var = linear_relation. allocate_element ( ) ;
302+ let X_var = linear_relation
303+ . allocate_eq ( ( x_var + ( -G :: Scalar :: from_u128 ( 1u128 ) ) ) * B_var + ( -B_var ) ) ;
304+
305+ linear_relation. set_element ( B_var , B ) ;
306+ linear_relation. set_element ( X_var , X ) ;
307+ let instance = ( & linear_relation) . try_into ( ) . unwrap ( ) ;
308+ let witness = vec ! [ x] ;
309+ ( instance, witness)
310+ }
311+
292312/// Generic helper function to test both relation correctness and NIZK functionality
293313#[ test]
294314fn test_common_relations ( ) {
@@ -314,7 +334,8 @@ fn test_common_relations() {
314334 "weird_linear_combination" ,
315335 Box :: new ( weird_linear_combination) ,
316336 ) ;
317- instance_generators. insert ( "test_relation_with_subtractions" , Box :: new ( test_relation_with_subtractions) ) ;
337+ instance_generators. insert ( "simple_subtractions" , Box :: new ( simple_subtractions) ) ;
338+ instance_generators. insert ( "subtractions_with_shift" , Box :: new ( subtractions_with_shift) ) ;
318339
319340 for ( relation_name, relation_sampler) in instance_generators. iter ( ) {
320341 let mut rng = OsRng ;
0 commit comments