11//! Definitions used in tests for this crate.
22
33use ff:: Field ;
4- use group:: { Group , GroupEncoding } ;
4+ use group:: { prime :: PrimeGroup , Group } ;
55
66use crate :: linear_relation:: { msm_pr, LinearRelation } ;
77
88/// LinearMap for knowledge of a discrete logarithm relative to a fixed basepoint.
99#[ allow( non_snake_case) ]
10- pub fn discrete_logarithm < G : Group + GroupEncoding > (
11- x : G :: Scalar ,
12- ) -> ( LinearRelation < G > , Vec < G :: Scalar > ) {
10+ pub fn discrete_logarithm < G : PrimeGroup > ( x : G :: Scalar ) -> ( LinearRelation < G > , Vec < G :: Scalar > ) {
1311 let mut relation: LinearRelation < G > = LinearRelation :: new ( ) ;
1412
1513 let var_x = relation. allocate_scalar ( ) ;
@@ -28,7 +26,7 @@ pub fn discrete_logarithm<G: Group + GroupEncoding>(
2826
2927/// LinearMap for knowledge of a translated discrete logarithm relative to a fixed basepoint.
3028#[ allow( non_snake_case) ]
31- pub fn translated_discrete_logarithm < G : Group + GroupEncoding > (
29+ pub fn translated_discrete_logarithm < G : PrimeGroup > (
3230 x : G :: Scalar ,
3331) -> ( LinearRelation < G > , Vec < G :: Scalar > ) {
3432 let mut relation: LinearRelation < G > = LinearRelation :: new ( ) ;
@@ -49,7 +47,7 @@ pub fn translated_discrete_logarithm<G: Group + GroupEncoding>(
4947
5048/// LinearMap for knowledge of a discrete logarithm equality between two pairs.
5149#[ allow( non_snake_case) ]
52- pub fn dleq < G : Group + GroupEncoding > ( H : G , x : G :: Scalar ) -> ( LinearRelation < G > , Vec < G :: Scalar > ) {
50+ pub fn dleq < G : PrimeGroup > ( H : G , x : G :: Scalar ) -> ( LinearRelation < G > , Vec < G :: Scalar > ) {
5351 let mut relation: LinearRelation < G > = LinearRelation :: new ( ) ;
5452
5553 let var_x = relation. allocate_scalar ( ) ;
@@ -71,10 +69,7 @@ pub fn dleq<G: Group + GroupEncoding>(H: G, x: G::Scalar) -> (LinearRelation<G>,
7169
7270/// LinearMap for knowledge of a translated dleq.
7371#[ allow( non_snake_case) ]
74- pub fn translated_dleq < G : Group + GroupEncoding > (
75- H : G ,
76- x : G :: Scalar ,
77- ) -> ( LinearRelation < G > , Vec < G :: Scalar > ) {
72+ pub fn translated_dleq < G : PrimeGroup > ( H : G , x : G :: Scalar ) -> ( LinearRelation < G > , Vec < G :: Scalar > ) {
7873 let mut relation: LinearRelation < G > = LinearRelation :: new ( ) ;
7974
8075 let var_x = relation. allocate_scalar ( ) ;
@@ -96,7 +91,7 @@ pub fn translated_dleq<G: Group + GroupEncoding>(
9691
9792/// LinearMap for knowledge of an opening to a Pedersen commitment.
9893#[ allow( non_snake_case) ]
99- pub fn pedersen_commitment < G : Group + GroupEncoding > (
94+ pub fn pedersen_commitment < G : PrimeGroup > (
10095 H : G ,
10196 x : G :: Scalar ,
10297 r : G :: Scalar ,
@@ -120,7 +115,7 @@ pub fn pedersen_commitment<G: Group + GroupEncoding>(
120115
121116/// LinearMap for knowledge of equal openings to two distinct Pedersen commitments.
122117#[ allow( non_snake_case) ]
123- pub fn pedersen_commitment_dleq < G : Group + GroupEncoding > (
118+ pub fn pedersen_commitment_dleq < G : PrimeGroup > (
124119 generators : [ G ; 4 ] ,
125120 witness : [ G :: Scalar ; 2 ] ,
126121) -> ( LinearRelation < G > , Vec < G :: Scalar > ) {
@@ -150,7 +145,7 @@ pub fn pedersen_commitment_dleq<G: Group + GroupEncoding>(
150145/// LinearMap for knowledge of an opening for use in a BBS commitment.
151146// BBS message length is 3
152147#[ allow( non_snake_case) ]
153- pub fn bbs_blind_commitment_computation < G : Group + GroupEncoding > (
148+ pub fn bbs_blind_commitment_computation < G : PrimeGroup > (
154149 [ Q_2 , J_1 , J_2 , J_3 ] : [ G ; 4 ] ,
155150 [ msg_1, msg_2, msg_3] : [ G :: Scalar ; 3 ] ,
156151 secret_prover_blind : G :: Scalar ,
@@ -187,7 +182,7 @@ pub fn bbs_blind_commitment_computation<G: Group + GroupEncoding>(
187182
188183/// Test function with the requested LinearRelation code
189184#[ allow( non_snake_case) ]
190- pub fn test_linear_relation_example < G : Group + GroupEncoding > ( ) -> LinearRelation < G > {
185+ pub fn test_linear_relation_example < G : PrimeGroup > ( ) -> LinearRelation < G > {
191186 use ff:: Field ;
192187
193188 let mut sigma__lr = LinearRelation :: < G > :: new ( ) ;
@@ -199,3 +194,30 @@ pub fn test_linear_relation_example<G: Group + GroupEncoding>() -> LinearRelatio
199194 sigma__lr
200195}
201196
197+ /// LinearMap for the user's specific relation: A * 1 + gen__disj1_x_r * B
198+ #[ allow( non_snake_case) ]
199+ pub fn user_specific_linear_combination < G : PrimeGroup > (
200+ B : G ,
201+ gen__disj1_x_r : G :: Scalar ,
202+ ) -> ( LinearRelation < G > , Vec < G :: Scalar > ) {
203+ let mut sigma__lr = LinearRelation :: < G > :: new ( ) ;
204+
205+ let gen__disj1_x_r_var = sigma__lr. allocate_scalar ( ) ;
206+ let A = sigma__lr. allocate_element ( ) ;
207+ let B_var = sigma__lr. allocate_element ( ) ;
208+
209+ let sigma__eq1 =
210+ sigma__lr. allocate_eq ( A * <G :: Scalar as ff:: Field >:: ONE + gen__disj1_x_r_var * B_var ) ;
211+
212+ // Set the group elements
213+ sigma__lr. set_elements ( [ ( A , G :: generator ( ) ) , ( B_var , B ) ] ) ;
214+ sigma__lr. compute_image ( & [ gen__disj1_x_r] ) . unwrap ( ) ;
215+
216+ let result = sigma__lr. linear_map . group_elements . get ( sigma__eq1) . unwrap ( ) ;
217+
218+ // Verify the relation computes correctly
219+ let expected = G :: generator ( ) + B * gen__disj1_x_r;
220+ assert_eq ! ( result, expected) ;
221+
222+ ( sigma__lr, vec ! [ gen__disj1_x_r] )
223+ }
0 commit comments