Skip to content

Commit cb86a5e

Browse files
committed
update
1 parent fa03427 commit cb86a5e

File tree

4 files changed

+34
-12
lines changed

4 files changed

+34
-12
lines changed

rust/catalyst-voting/src/crypto/group/ristretto255.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,17 @@ mod tests {
190190
}
191191
}
192192

193+
impl Arbitrary for GroupElement {
194+
type Parameters = ();
195+
type Strategy = BoxedStrategy<Self>;
196+
197+
fn arbitrary_with((): Self::Parameters) -> Self::Strategy {
198+
any::<Scalar>()
199+
.prop_map(|s| GroupElement::GENERATOR.mul(&s))
200+
.boxed()
201+
}
202+
}
203+
193204
#[proptest]
194205
fn scalar_to_bytes_from_bytes_test(e1: Scalar) {
195206
let bytes = e1.to_bytes();

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

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ fn generate_response(
155155
/// Verify a unit vector proof.
156156
pub fn verify_unit_vector_proof(
157157
proof: &UnitVectorProof, mut ciphertexts: Vec<Ciphertext>, public_key: &PublicKey,
158-
commitment_key: &PublicKey,
158+
commitment_key: &GroupElement,
159159
) -> bool {
160160
let m = ciphertexts.len();
161161
let n = m.next_power_of_two();
@@ -176,7 +176,7 @@ pub fn verify_unit_vector_proof(
176176
}
177177

178178
/// Check the first part of the proof
179-
fn check_1(proof: &UnitVectorProof, ch_2: &Scalar, commitment_key: &PublicKey) -> bool {
179+
fn check_1(proof: &UnitVectorProof, ch_2: &Scalar, commitment_key: &GroupElement) -> bool {
180180
proof.0.iter().zip(proof.2.iter()).all(|(an, rand)| {
181181
let right = &an.i.mul(ch_2) + &an.b;
182182
let left = &GroupElement::GENERATOR.mul(&rand.z) + &commitment_key.mul(&rand.w);
@@ -244,14 +244,13 @@ mod tests {
244244

245245
#[proptest]
246246
fn zk_unit_vector_test(
247-
secret_key: SecretKey, secret_commitment_key: SecretKey,
247+
secret_key: SecretKey, commitment_key: GroupElement,
248248
#[strategy(1..10_usize)] unit_vector_size: usize,
249249
#[strategy(0..#unit_vector_size)] unit_vector_index: usize,
250250
) {
251251
let mut rng = OsRng;
252252

253253
let public_key = secret_key.public_key();
254-
let commitment_key = secret_commitment_key.public_key();
255254

256255
let unit_vector: Vec<_> = (0..unit_vector_size)
257256
.map(|i| {
@@ -295,7 +294,7 @@ mod tests {
295294

296295
#[proptest]
297296
fn not_a_unit_vector_test(
298-
secret_key: SecretKey, secret_commitment_key: SecretKey,
297+
secret_key: SecretKey, commitment_key: GroupElement,
299298
#[any(size_range(1..10_usize).lift())] random_vector: Vec<Scalar>,
300299
) {
301300
let mut rng = OsRng;
@@ -307,7 +306,6 @@ mod tests {
307306
}
308307

309308
let public_key = secret_key.public_key();
310-
let commitment_key = secret_commitment_key.public_key();
311309

312310
let encryption_randomness: Vec<_> = random_vector
313311
.iter()

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ pub struct EncryptionRandomness(Vec<Scalar>);
2828

2929
impl EncryptionRandomness {
3030
/// Randomly generate the `EncryptionRandomness`.
31-
fn generate<R: CryptoRngCore>(rng: &mut R, voting_options: usize) -> Self {
31+
fn random<R: CryptoRngCore>(rng: &mut R, voting_options: usize) -> Self {
3232
Self((0..voting_options).map(|_| Scalar::random(rng)).collect())
3333
}
3434
}
@@ -89,7 +89,7 @@ impl Vote {
8989
pub fn encrypt_vote<R: CryptoRngCore>(
9090
vote: &Vote, public_key: &PublicKey, rng: &mut R,
9191
) -> (EncryptedVote, EncryptionRandomness) {
92-
let randomness = EncryptionRandomness::generate(rng, vote.voting_options);
92+
let randomness = EncryptionRandomness::random(rng, vote.voting_options);
9393

9494
let unit_vector = vote.to_unit_vector();
9595
let ciphers = unit_vector

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

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
11
//! Voter proof generation and verification procedures.
22
//! It allows to transparently verify the correctness voter generation and encryption.
33
4+
use std::ops::Mul;
5+
46
use rand_core::CryptoRngCore;
57

68
use super::{EncryptedVote, EncryptionRandomness, Vote};
79
use crate::{
8-
crypto::zk_unit_vector::{
9-
generate_unit_vector_proof, verify_unit_vector_proof, UnitVectorProof,
10+
crypto::{
11+
group::{GroupElement, Scalar},
12+
zk_unit_vector::{generate_unit_vector_proof, verify_unit_vector_proof, UnitVectorProof},
1013
},
1114
PublicKey,
1215
};
@@ -15,19 +18,29 @@ use crate::{
1518
#[allow(clippy::module_name_repetitions)]
1619
pub struct VoterProof(UnitVectorProof);
1720

21+
/// Voter proof commitment struct.
22+
pub struct VoterProofCommitment(GroupElement);
23+
24+
impl VoterProofCommitment {
25+
/// Randomly generate the `VoterProofCommitment`.
26+
pub fn random<R: CryptoRngCore>(rng: &mut R) -> Self {
27+
Self(GroupElement::GENERATOR.mul(&Scalar::random(rng)))
28+
}
29+
}
30+
1831
/// Generates a voter proof.
1932
/// More detailed described [here](https://input-output-hk.github.io/catalyst-voices/architecture/08_concepts/voting_transaction/crypto/#voters-proof)
2033
#[allow(clippy::module_name_repetitions)]
2134
pub fn generate_voter_proof<R: CryptoRngCore>(
2235
vote: &Vote, encrypted_vote: EncryptedVote, randomness: EncryptionRandomness,
23-
public_key: &PublicKey, commitment_key: &PublicKey, rng: &mut R,
36+
public_key: &PublicKey, commitment: &VoterProofCommitment, rng: &mut R,
2437
) -> VoterProof {
2538
let proof = generate_unit_vector_proof(
2639
&vote.to_unit_vector(),
2740
encrypted_vote.0,
2841
randomness.0,
2942
public_key,
30-
commitment_key,
43+
&commitment.0,
3144
rng,
3245
);
3346
VoterProof(proof)

0 commit comments

Comments
 (0)