|
| 1 | +//! Voter proof generation and verification procedures. |
| 2 | +//! It allows to transparently verify the correctness voter generation and encryption. |
| 3 | +
|
| 4 | +use rand_core::CryptoRngCore; |
| 5 | + |
| 6 | +use super::{EncryptedVote, EncryptionRandomness, Vote}; |
| 7 | +use crate::{ |
| 8 | + crypto::zk_unit_vector::{ |
| 9 | + generate_unit_vector_proof, verify_unit_vector_proof, UnitVectorProof, |
| 10 | + }, |
| 11 | + PublicKey, |
| 12 | +}; |
| 13 | + |
| 14 | +/// Tally proof struct. |
| 15 | +#[allow(clippy::module_name_repetitions)] |
| 16 | +pub struct VoterProof(UnitVectorProof); |
| 17 | + |
| 18 | +/// Generates a voter proof. |
| 19 | +/// More detailed described [here](https://input-output-hk.github.io/catalyst-voices/architecture/08_concepts/voting_transaction/crypto/#voters-proof) |
| 20 | +#[allow(clippy::module_name_repetitions)] |
| 21 | +pub fn generate_voter_proof<R: CryptoRngCore>( |
| 22 | + vote: &Vote, encrypted_vote: EncryptedVote, randomness: EncryptionRandomness, |
| 23 | + public_key: &PublicKey, commitment_key: &PublicKey, rng: &mut R, |
| 24 | +) -> VoterProof { |
| 25 | + let proof = generate_unit_vector_proof( |
| 26 | + &vote.to_unit_vector(), |
| 27 | + encrypted_vote.0, |
| 28 | + randomness.0, |
| 29 | + public_key, |
| 30 | + commitment_key, |
| 31 | + rng, |
| 32 | + ); |
| 33 | + VoterProof(proof) |
| 34 | +} |
| 35 | + |
| 36 | +/// Verifies a voter proof. |
| 37 | +/// More detailed described [here](https://input-output-hk.github.io/catalyst-voices/architecture/08_concepts/voting_transaction/crypto/#voters-proof) |
| 38 | +#[must_use] |
| 39 | +#[allow(clippy::module_name_repetitions)] |
| 40 | +pub fn verify_voter_proof( |
| 41 | + encrypted_vote: EncryptedVote, public_key: &PublicKey, commitment_key: &PublicKey, |
| 42 | + proof: &VoterProof, |
| 43 | +) -> bool { |
| 44 | + verify_unit_vector_proof(&proof.0, encrypted_vote.0, public_key, commitment_key) |
| 45 | +} |
0 commit comments