@@ -28,13 +28,32 @@ impl VoterProofCommitment {
2828 }
2929}
3030
31+ /// Generate voter proof error
32+ #[ derive( thiserror:: Error , Debug ) ]
33+ pub enum GenerateVoterProofError {
34+ /// Arguments mismatch
35+ #[ error( "Provided arguments mismatch. Size of the provided `vote`: {0}, `encrypted_vote: {1}` and `randomness`: {2} must be equal with each other." ) ]
36+ ArgumentsMismatch ( usize , usize , usize ) ,
37+ }
38+
3139/// Generates a voter proof.
3240/// More detailed described [here](https://input-output-hk.github.io/catalyst-voices/architecture/08_concepts/voting_transaction/crypto/#voters-proof)
41+ ///
42+ /// # Errors
43+ /// - `GenerateVoterProofError`
3344#[ allow( clippy:: module_name_repetitions) ]
3445pub fn generate_voter_proof < R : CryptoRngCore > (
3546 vote : & Vote , encrypted_vote : EncryptedVote , randomness : EncryptionRandomness ,
3647 public_key : & PublicKey , commitment : & VoterProofCommitment , rng : & mut R ,
37- ) -> VoterProof {
48+ ) -> Result < VoterProof , GenerateVoterProofError > {
49+ if vote. voting_options != encrypted_vote. 0 . len ( ) || vote. voting_options != randomness. 0 . len ( ) {
50+ return Err ( GenerateVoterProofError :: ArgumentsMismatch (
51+ vote. voting_options ,
52+ encrypted_vote. 0 . len ( ) ,
53+ randomness. 0 . len ( ) ,
54+ ) ) ;
55+ }
56+
3857 let proof = generate_unit_vector_proof (
3958 & vote. to_unit_vector ( ) ,
4059 encrypted_vote. 0 ,
@@ -43,7 +62,7 @@ pub fn generate_voter_proof<R: CryptoRngCore>(
4362 & commitment. 0 ,
4463 rng,
4564 ) ;
46- VoterProof ( proof)
65+ Ok ( VoterProof ( proof) )
4766}
4867
4968/// Verifies a voter proof.
0 commit comments