11use curve25519_dalek:: ristretto:: RistrettoPoint ;
2+ use group:: Group ;
23use rand:: rngs:: OsRng ;
34use subtle:: CtOption ;
45
56use super :: test_relations:: * ;
6- use crate :: codec:: Shake128DuplexSponge ;
77use crate :: composition:: { ComposedRelation , ComposedWitness } ;
8- use crate :: fiat_shamir:: Nizk ;
98use crate :: schnorr_protocol:: SchnorrProof ;
109
1110type G = RistrettoPoint ;
@@ -24,20 +23,23 @@ fn test_composition_correctness() {
2423
2524 // definitions of the underlying protocols
2625 let mut rng = OsRng ;
27- let ( relation1, witness1) = dleq :: < G , _ > ( & mut rng) ;
28- let ( relation2, witness2) = pedersen_commitment :: < G , _ > ( & mut rng) ;
29- let ( relation3, witness3) = discrete_logarithm :: < G , _ > ( & mut rng) ;
30- let ( relation4, witness4) = pedersen_commitment_dleq :: < G , _ > ( & mut rng) ;
31- let ( relation5, witness5) = bbs_blind_commitment :: < G , _ > ( & mut rng) ;
26+ let ( relation1, witness1) = dleq ( & mut rng) ;
27+ let ( relation2, witness2) = pedersen_commitment ( & mut rng) ;
28+ let ( relation3, witness3) = discrete_logarithm ( & mut rng) ;
29+ let ( relation4, witness4) = pedersen_commitment_dleq ( & mut rng) ;
30+ let ( relation5, witness5) = bbs_blind_commitment ( & mut rng) ;
3231
32+ let wrong_witness2 = ( 0 ..witness2. len ( ) )
33+ . map ( |_| <G as Group >:: Scalar :: random ( & mut rng) )
34+ . collect :: < Vec < _ > > ( ) ;
3335 // second layer protocol definitions
34- let or_protocol1 = ComposedRelation :: Or ( vec ! [
36+ let or_protocol1 = ComposedRelation :: < G > :: Or ( vec ! [
3537 ComposedRelation :: Simple ( SchnorrProof ( relation1) ) ,
3638 ComposedRelation :: Simple ( SchnorrProof ( relation2) ) ,
3739 ] ) ;
3840 let or_witness1 = ComposedWitness :: Or ( vec ! [
3941 CtOption :: new( ComposedWitness :: Simple ( witness1) , 1u8 . into( ) ) ,
40- CtOption :: new( ComposedWitness :: Simple ( witness2 . clone ( ) ) , 0u8 . into( ) ) ,
42+ CtOption :: new( ComposedWitness :: Simple ( wrong_witness2 ) , 0u8 . into( ) ) ,
4143 ] ) ;
4244
4345 let simple_protocol1 = ComposedRelation :: Simple ( SchnorrProof ( relation3) ) ;
@@ -53,12 +55,10 @@ fn test_composition_correctness() {
5355 ] ) ;
5456
5557 // definition of the final protocol
56- let protocol = ComposedRelation :: And ( vec ! [ or_protocol1, simple_protocol1, and_protocol1] ) ;
58+ let instance = ComposedRelation :: And ( vec ! [ or_protocol1, simple_protocol1, and_protocol1] ) ;
5759 let witness = ComposedWitness :: And ( vec ! [ or_witness1, simple_witness1, and_witness1] ) ;
5860
59- let nizk = Nizk :: < ComposedRelation < RistrettoPoint > , Shake128DuplexSponge < G > > :: new (
60- domain_sep, protocol,
61- ) ;
61+ let nizk = instance. into_nizk ( domain_sep) ;
6262
6363 // Batchable and compact proofs
6464 let proof_batchable_bytes = nizk. prove_batchable ( & witness, & mut OsRng ) . unwrap ( ) ;
0 commit comments