Skip to content

Commit 7317fef

Browse files
committed
refactor imports, add voter proof module
1 parent a84edb4 commit 7317fef

File tree

5 files changed

+60
-14
lines changed

5 files changed

+60
-14
lines changed

rust/catalyst-voting/src/crypto/zk_unit_vector/mod.rs

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@
44
//!
55
//! This implementation follows this [specification](https://input-output-hk.github.io/catalyst-voices/architecture/08_concepts/voting_transaction/crypto/#d-non-interactive-zk-vote-proof)
66
7-
#![allow(dead_code)]
8-
97
mod challenges;
108
mod polynomial;
119
mod randomness_announcements;
@@ -42,8 +40,8 @@ pub struct UnitVectorProof(
4240
/// Pls make sure that you are providing a correct arguments, otherwise
4341
/// the proof will be invalid.
4442
pub fn generate_unit_vector_proof<R: CryptoRngCore>(
45-
unit_vector: &[Scalar], mut encryption_randomness: Vec<Scalar>,
46-
mut ciphertexts: Vec<Ciphertext>, public_key: &PublicKey, commitment_key: &GroupElement,
43+
unit_vector: &[Scalar], mut ciphertexts: Vec<Ciphertext>,
44+
mut encryption_randomness: Vec<Scalar>, public_key: &PublicKey, commitment_key: &GroupElement,
4745
rng: &mut R,
4846
) -> UnitVectorProof {
4947
let i = unit_vector
@@ -238,8 +236,6 @@ mod tests {
238236

239237
use super::{super::elgamal::SecretKey, *};
240238

241-
const VECTOR_SIZE: usize = 3;
242-
243239
fn is_unit_vector(vector: &[Scalar]) -> bool {
244240
let ones = vector.iter().filter(|s| s == &&Scalar::one()).count();
245241
let zeros = vector.iter().filter(|s| s == &&Scalar::zero()).count();
@@ -282,8 +278,8 @@ mod tests {
282278

283279
let proof = generate_unit_vector_proof(
284280
&unit_vector,
285-
encryption_randomness,
286281
ciphertexts.clone(),
282+
encryption_randomness,
287283
&public_key,
288284
&commitment_key,
289285
&mut rng,
@@ -326,8 +322,8 @@ mod tests {
326322

327323
let proof = generate_unit_vector_proof(
328324
&random_vector,
329-
encryption_randomness,
330325
ciphertexts.clone(),
326+
encryption_randomness,
331327
&public_key,
332328
&commitment_key,
333329
&mut rng,

rust/catalyst-voting/src/lib.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -83,9 +83,7 @@
8383
//! ```
8484
8585
mod crypto;
86-
mod tally;
87-
mod voter;
86+
pub mod tally;
87+
pub mod voter;
8888

8989
pub use crypto::elgamal::{PublicKey, SecretKey};
90-
pub use tally::{proof::*, *};
91-
pub use voter::*;

rust/catalyst-voting/src/voter/mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
//! Module containing all primitives related to the voter.
22
3+
pub mod proof;
4+
35
use rand_core::CryptoRngCore;
46

57
use crate::crypto::{
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
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+
}

rust/catalyst-voting/tests/voting_test.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,13 @@
11
//! A general voting integration test, which performs a full voting procedure.
22
33
use catalyst_voting::{
4-
decrypt_tally, encrypt_vote, generate_tally_proof, tally, verify_tally_proof,
5-
DecryptionTallySetup, SecretKey, Vote,
4+
tally::{
5+
decrypt_tally,
6+
proof::{generate_tally_proof, verify_tally_proof},
7+
tally, DecryptionTallySetup,
8+
},
9+
voter::{encrypt_vote, Vote},
10+
SecretKey,
611
};
712
use proptest::prelude::ProptestConfig;
813
use test_strategy::{proptest, Arbitrary};

0 commit comments

Comments
 (0)