@@ -6,7 +6,11 @@ use catalyst_voting::{
66 proof:: { generate_tally_proof, verify_tally_proof} ,
77 tally, DecryptionTallySetup ,
88 } ,
9- voter:: { encrypt_vote, Vote } ,
9+ voter:: {
10+ encrypt_vote,
11+ proof:: { generate_voter_proof, verify_voter_proof, VoterProofCommitment } ,
12+ Vote ,
13+ } ,
1014 SecretKey ,
1115} ;
1216use proptest:: prelude:: ProptestConfig ;
@@ -28,17 +32,51 @@ fn voting_test(voters: [Voter; 100]) {
2832
2933 let election_secret_key = SecretKey :: random ( & mut rng) ;
3034 let election_public_key = election_secret_key. public_key ( ) ;
35+ let voter_proof_commitment = VoterProofCommitment :: random ( & mut rng) ;
3136
3237 let votes: Vec < _ > = voters
3338 . iter ( )
3439 . map ( |voter| Vote :: new ( voter. choice , VOTING_OPTIONS ) . unwrap ( ) )
3540 . collect ( ) ;
3641
37- let ( encrypted_votes, _randomness ) : ( Vec < _ > , Vec < _ > ) = votes
42+ let ( encrypted_votes, randomness ) : ( Vec < _ > , Vec < _ > ) = votes
3843 . iter ( )
3944 . map ( |vote| encrypt_vote ( vote, & election_public_key, & mut rng) )
4045 . unzip ( ) ;
4146
47+ // Verify encrypted votes
48+ {
49+ let voter_proofs: Vec < _ > = votes
50+ . iter ( )
51+ . zip ( encrypted_votes. iter ( ) )
52+ . zip ( randomness. iter ( ) )
53+ . map ( |( ( v, enc_v) , r) | {
54+ generate_voter_proof (
55+ v,
56+ enc_v. clone ( ) ,
57+ r. clone ( ) ,
58+ & election_public_key,
59+ & voter_proof_commitment,
60+ & mut rng,
61+ )
62+ . unwrap ( )
63+ } )
64+ . collect ( ) ;
65+
66+ let is_ok = voter_proofs
67+ . iter ( )
68+ . zip ( encrypted_votes. iter ( ) )
69+ . all ( |( p, enc_v) | {
70+ verify_voter_proof (
71+ enc_v. clone ( ) ,
72+ & election_public_key,
73+ & voter_proof_commitment,
74+ p,
75+ )
76+ } ) ;
77+ assert ! ( is_ok) ;
78+ }
79+
4280 let voting_powers: Vec < _ > = voters
4381 . iter ( )
4482 . map ( |voter| u64:: from ( voter. voting_power ) )
@@ -51,22 +89,25 @@ fn voting_test(voters: [Voter; 100]) {
5189 let total_voting_power = voting_powers. iter ( ) . sum ( ) ;
5290 let decryption_tally_setup = DecryptionTallySetup :: new ( total_voting_power) . unwrap ( ) ;
5391
54- let tally_proofs: Vec < _ > = encrypted_tallies
55- . iter ( )
56- . map ( |t| generate_tally_proof ( t, & election_secret_key, & mut rng) )
57- . collect ( ) ;
58-
5992 let decrypted_tallies: Vec < _ > = encrypted_tallies
6093 . iter ( )
6194 . map ( |t| decrypt_tally ( t, & election_secret_key, & decryption_tally_setup) . unwrap ( ) )
6295 . collect ( ) ;
6396
64- let is_ok = tally_proofs
65- . iter ( )
66- . zip ( encrypted_tallies. iter ( ) )
67- . zip ( decrypted_tallies. iter ( ) )
68- . all ( |( ( p, enc_t) , t) | verify_tally_proof ( enc_t, * t, & election_public_key, p) ) ;
69- assert ! ( is_ok) ;
97+ // Verify tallies
98+ {
99+ let tally_proofs: Vec < _ > = encrypted_tallies
100+ . iter ( )
101+ . map ( |t| generate_tally_proof ( t, & election_secret_key, & mut rng) )
102+ . collect ( ) ;
103+
104+ let is_ok = tally_proofs
105+ . iter ( )
106+ . zip ( encrypted_tallies. iter ( ) )
107+ . zip ( decrypted_tallies. iter ( ) )
108+ . all ( |( ( p, enc_t) , t) | verify_tally_proof ( enc_t, * t, & election_public_key, p) ) ;
109+ assert ! ( is_ok) ;
110+ }
70111
71112 let expected_tallies: Vec < _ > = ( 0 ..VOTING_OPTIONS )
72113 . map ( |i| {
0 commit comments