@@ -7,11 +7,13 @@ use sigma_rs::toolbox::sigma::sage_test::custom_schnorr_proof::SchnorrProofCusto
77use sigma_rs:: toolbox:: sigma:: transcript:: KeccakDuplexSponge ;
88use sigma_rs:: toolbox:: sigma:: {
99 GroupMorphismPreimage ,
10- transcript:: { ShakeTranscript , ByteSchnorrCodec } ,
10+ transcript:: ByteSchnorrCodec ,
1111 NISigmaProtocol ,
1212} ;
1313
1414type Gp = G1Projective ;
15+ type Codec = ByteSchnorrCodec :: < Gp , KeccakDuplexSponge > ;
16+ type SigmaP = SchnorrProofCustom < Gp > ;
1517
1618fn msm_pr < G : Group > ( scalars : & [ G :: Scalar ] , bases : & [ G ] ) -> G {
1719 let mut acc = G :: identity ( ) ;
@@ -46,14 +48,14 @@ fn discrete_logarithm<G: SRandom + Group + GroupEncoding>(
4648
4749
4850#[ allow( non_snake_case) ]
49- fn dleq < G : Group + GroupEncoding > (
51+ fn dleq < G : Group + GroupEncoding + SRandom > (
5052 rng : & mut ( impl Rng + CryptoRng )
5153) -> ( GroupMorphismPreimage < G > , Vec < G :: Scalar > ) {
5254 let mut morphismp: GroupMorphismPreimage < G > = GroupMorphismPreimage :: new ( ) ;
5355
5456 let G = G :: generator ( ) ;
57+ let x = G :: srandom ( & mut * rng) ;
5558 let H = G :: random ( & mut * rng) ;
56- let x = G :: Scalar :: random ( & mut * rng) ;
5759 let X = G * x;
5860 let Y = H * x;
5961
@@ -71,15 +73,15 @@ fn dleq<G: Group + GroupEncoding>(
7173
7274
7375#[ allow( non_snake_case) ]
74- fn pedersen_commitment < G : Group + GroupEncoding > (
76+ fn pedersen_commitment < G : Group + GroupEncoding + SRandom > (
7577 rng : & mut ( impl Rng + CryptoRng )
7678) -> ( GroupMorphismPreimage < G > , Vec < G :: Scalar > ) {
7779 let mut morphismp: GroupMorphismPreimage < G > = GroupMorphismPreimage :: new ( ) ;
7880
7981 let G = G :: generator ( ) ;
8082 let H = G :: random ( & mut * rng) ;
81- let x = G :: Scalar :: random ( & mut * rng) ;
82- let r = G :: Scalar :: random ( & mut * rng) ;
83+ let x = G :: srandom ( & mut * rng) ;
84+ let r = G :: srandom ( & mut * rng) ;
8385 let witness = vec ! [ x, r] ;
8486
8587 let C = G * x + H * r;
@@ -97,7 +99,7 @@ fn pedersen_commitment<G: Group + GroupEncoding>(
9799
98100
99101#[ allow( non_snake_case) ]
100- fn pedersen_commitment_dleq < G : Group + GroupEncoding > (
102+ fn pedersen_commitment_dleq < G : Group + GroupEncoding + SRandom > (
101103 rng : & mut ( impl Rng + CryptoRng )
102104) -> ( GroupMorphismPreimage < G > , Vec < G :: Scalar > ) {
103105 let mut morphismp: GroupMorphismPreimage < G > = GroupMorphismPreimage :: new ( ) ;
@@ -109,8 +111,8 @@ fn pedersen_commitment_dleq<G: Group + GroupEncoding>(
109111 generators. push ( G :: random ( & mut * rng) ) ;
110112
111113 let mut witness = Vec :: < G :: Scalar > :: new ( ) ;
112- witness. push ( G :: Scalar :: random ( & mut * rng) ) ;
113- witness. push ( G :: Scalar :: random ( & mut * rng) ) ;
114+ witness. push ( G :: srandom ( & mut * rng) ) ;
115+ witness. push ( G :: srandom ( & mut * rng) ) ;
114116
115117 let X = msm_pr :: < G > ( & witness, & [ generators[ 0 ] , generators[ 1 ] ] ) ;
116118 let Y = msm_pr :: < G > ( & witness, & [ generators[ 2 ] , generators[ 3 ] ] ) ;
@@ -134,7 +136,7 @@ fn pedersen_commitment_dleq<G: Group + GroupEncoding>(
134136
135137
136138#[ allow( non_snake_case) ]
137- fn bbs_blind_commitment_computation < G : Group + GroupEncoding > (
139+ fn bbs_blind_commitment_computation < G : Group + GroupEncoding + SRandom > (
138140 rng : & mut ( impl Rng + CryptoRng )
139141) -> ( GroupMorphismPreimage < G > , Vec < G :: Scalar > ) {
140142 let mut morphismp: GroupMorphismPreimage < G > = GroupMorphismPreimage :: new ( ) ;
@@ -144,10 +146,10 @@ fn bbs_blind_commitment_computation<G: Group + GroupEncoding>(
144146 // BBS.create_generators(M + 1, "BLIND_" || api_id)
145147 let ( Q_2 , J_1 , J_2 , J_3 ) = ( G :: random ( & mut * rng) , G :: random ( & mut * rng) , G :: random ( & mut * rng) , G :: random ( & mut * rng) ) ;
146148 // BBS.messages_to_scalars(committed_messages, api_id)
147- let ( msg_1, msg_2, msg_3) = ( G :: Scalar :: random ( & mut * rng) , G :: Scalar :: random ( & mut * rng) , G :: Scalar :: random ( & mut * rng) ) ;
149+ let ( msg_1, msg_2, msg_3) = ( G :: srandom ( & mut * rng) , G :: srandom ( & mut * rng) , G :: srandom ( & mut * rng) ) ;
148150
149151 // these are computed before the proof in the specification
150- let secret_prover_blind = G :: Scalar :: random ( & mut * rng) ;
152+ let secret_prover_blind = G :: srandom ( & mut * rng) ;
151153 let C = Q_2 * secret_prover_blind + J_1 * msg_1 + J_2 * msg_2 + J_3 * msg_3;
152154
153155 // This is the part that needs to be changed in the specification of blind bbs.
@@ -181,7 +183,7 @@ fn NI_discrete_logarithm() {
181183
182184 let protocol = SchnorrProofCustom { morphismp } ;
183185 let domain_sep: Vec < u8 > = b"yellow submarineyellow submarine" . to_vec ( ) ;
184- let mut nizk = NISigmaProtocol :: < SchnorrProofCustom < Gp > , ByteSchnorrCodec :: < Gp , KeccakDuplexSponge > , Gp > :: new ( & domain_sep, protocol) ;
186+ let mut nizk = NISigmaProtocol :: < SigmaP , Codec , Gp > :: new ( & domain_sep, protocol) ;
185187
186188 let proof_bytes = nizk. prove ( & witness, & mut rng) ;
187189 let verified = nizk. verify ( & proof_bytes) . is_ok ( ) ;
@@ -192,14 +194,14 @@ fn NI_discrete_logarithm() {
192194#[ allow( non_snake_case) ]
193195#[ test]
194196fn NI_dleq ( ) {
195- let mut rng = TestDRNG :: new ( b"79656c6c6f77207375626d6172696e6579656c6c6f77207375626d6172696e65 " ) ;
197+ let mut rng = TestDRNG :: new ( b"hello world " ) ;
196198 let ( morphismp, witness) = dleq :: < Gp > ( & mut rng) ;
197199
198200 println ! ( "witness: {:?}" , witness) ;
199201
200202 let protocol = SchnorrProofCustom { morphismp } ;
201203 let domain_sep: Vec < u8 > = b"yellow submarineyellow submarine" . to_vec ( ) ;
202- let mut nizk = NISigmaProtocol :: < SchnorrProofCustom < Gp > , ShakeTranscript < Gp > , Gp > :: new ( & domain_sep, protocol) ;
204+ let mut nizk = NISigmaProtocol :: < SigmaP , Codec , Gp > :: new ( & domain_sep, protocol) ;
203205
204206 let proof_bytes = nizk. prove ( & witness, & mut rng) ;
205207 let verified = nizk. verify ( & proof_bytes) . is_ok ( ) ;
@@ -210,14 +212,14 @@ fn NI_dleq() {
210212#[ allow( non_snake_case) ]
211213#[ test]
212214fn NI_pedersen_commitment ( ) {
213- let mut rng = TestDRNG :: new ( b"79656c6c6f77207375626d6172696e6579656c6c6f77207375626d6172696e65 " ) ;
215+ let mut rng = TestDRNG :: new ( b"hello world " ) ;
214216 let ( morphismp, witness) = pedersen_commitment :: < Gp > ( & mut rng) ;
215217
216218 println ! ( "witness: {:?}" , witness) ;
217219
218220 let protocol = SchnorrProofCustom { morphismp } ;
219221 let domain_sep: Vec < u8 > = b"yellow submarineyellow submarine" . to_vec ( ) ;
220- let mut nizk = NISigmaProtocol :: < SchnorrProofCustom < Gp > , ShakeTranscript < Gp > , Gp > :: new ( & domain_sep, protocol) ;
222+ let mut nizk = NISigmaProtocol :: < SigmaP , Codec , Gp > :: new ( & domain_sep, protocol) ;
221223
222224 let proof_bytes = nizk. prove ( & witness, & mut rng) ;
223225 let verified = nizk. verify ( & proof_bytes) . is_ok ( ) ;
@@ -228,14 +230,14 @@ fn NI_pedersen_commitment() {
228230#[ allow( non_snake_case) ]
229231#[ test]
230232fn NI_pedersen_commitment_dleq ( ) {
231- let mut rng = TestDRNG :: new ( b"79656c6c6f77207375626d6172696e6579656c6c6f77207375626d6172696e65 " ) ;
233+ let mut rng = TestDRNG :: new ( b"hello world " ) ;
232234 let ( morphismp, witness) = pedersen_commitment_dleq :: < Gp > ( & mut rng) ;
233235
234236 println ! ( "witness: {:?}" , witness) ;
235237
236238 let protocol = SchnorrProofCustom { morphismp } ;
237239 let domain_sep: Vec < u8 > = b"yellow submarineyellow submarine" . to_vec ( ) ;
238- let mut nizk = NISigmaProtocol :: < SchnorrProofCustom < Gp > , ShakeTranscript < Gp > , Gp > :: new ( & domain_sep, protocol) ;
240+ let mut nizk = NISigmaProtocol :: < SigmaP , Codec , Gp > :: new ( & domain_sep, protocol) ;
239241
240242 let proof_bytes = nizk. prove ( & witness, & mut rng) ;
241243 let verified = nizk. verify ( & proof_bytes) . is_ok ( ) ;
@@ -246,14 +248,14 @@ fn NI_pedersen_commitment_dleq() {
246248#[ allow( non_snake_case) ]
247249#[ test]
248250fn NI_bbs_blind_commitment_computation ( ) {
249- let mut rng = TestDRNG :: new ( b"79656c6c6f77207375626d6172696e6579656c6c6f77207375626d6172696e65 " ) ;
251+ let mut rng = TestDRNG :: new ( b"hello world " ) ;
250252 let ( morphismp, witness) = bbs_blind_commitment_computation :: < Gp > ( & mut rng) ;
251253
252254 println ! ( "witness: {:?}" , witness) ;
253255
254256 let protocol = SchnorrProofCustom { morphismp } ;
255257 let domain_sep: Vec < u8 > = b"yellow submarineyellow submarine" . to_vec ( ) ;
256- let mut nizk = NISigmaProtocol :: < SchnorrProofCustom < Gp > , ShakeTranscript < Gp > , Gp > :: new ( & domain_sep, protocol) ;
258+ let mut nizk = NISigmaProtocol :: < SigmaP , Codec , Gp > :: new ( & domain_sep, protocol) ;
257259
258260 let proof_bytes = nizk. prove ( & witness, & mut rng) ;
259261 let verified = nizk. verify ( & proof_bytes) . is_ok ( ) ;
0 commit comments