Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion rust/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ members = [
"cbork",
"cbork-abnf-parser",
"cbork-cddl-parser",
"catalyst-voting",
"catalyst-voting", "jormungandr-vote-tx",
]

[workspace.package]
Expand Down
4 changes: 2 additions & 2 deletions rust/Earthfile
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ COPY_SRC:
.cargo .config \
c509-certificate \
cardano-chain-follower \
catalyst-voting \
catalyst-voting jormungandr-vote-tx \
cbork cbork-abnf-parser cbork-cddl-parser \
hermes-ipfs \
.
Expand Down Expand Up @@ -53,7 +53,7 @@ build:
--cmd="/scripts/std_build.py" \
--args1="--libs=c509-certificate --libs=cardano-chain-follower --libs=hermes-ipfs" \
--args2="--libs=cbork-cddl-parser --libs=cbork-abnf-parser" \
--args3="--libs=catalyst-voting" \
--args3="--libs=catalyst-voting --libs=jormungandr-vote-tx" \
--args4="--bins=cbork/cbork" \
--args5="--cov_report=$HOME/build/coverage-report.info" \
--output="release/[^\./]+" \
Expand Down
2 changes: 1 addition & 1 deletion rust/catalyst-voting/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@ curve25519-dalek = { version = "4.1.3", features = ["digest", "rand_core"] }
ed25519-dalek = { version = "2.1.1", features = ["rand_core"] }
blake2b_simd = "1.0.2"
rayon = "1.10.0"
proptest = { version = "1.5.0" }

[dev-dependencies]
criterion = "0.5.1"
proptest = { version = "1.5.0" }
# Potentially it could be replaced with using `proptest::property_test` attribute macro,
# after this PR will be merged https://github.com/proptest-rs/proptest/pull/523
test-strategy = "0.4.0"
2 changes: 1 addition & 1 deletion rust/catalyst-voting/benches/vote_protocol.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
)]

use catalyst_voting::{
crypto::default_rng,
crypto::rng::default_rng,
vote_protocol::{
committee::{ElectionPublicKey, ElectionSecretKey},
tally::{
Expand Down
17 changes: 12 additions & 5 deletions rust/catalyst-voting/src/crypto/ed25519/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ mod decoding;
use ed25519_dalek::{
ed25519::signature::Signer, Signature as Ed25519Signature, SigningKey, VerifyingKey,
};
use rand_core::CryptoRngCore;

use crate::crypto::rng::rand_core::CryptoRngCore;

/// `Ed25519` private key struct.
#[must_use]
Expand Down Expand Up @@ -45,12 +46,11 @@ pub fn verify_signature(pk: &PublicKey, msg: &[u8], sig: &Signature) -> bool {
pk.0.verify_strict(msg, &sig.0).is_ok()
}

#[cfg(test)]
mod tests {
#[allow(missing_docs, clippy::missing_docs_in_private_items)]
mod arbitrary_impl {
use proptest::prelude::{any, Arbitrary, BoxedStrategy, Strategy};
use test_strategy::proptest;

use super::*;
use super::{PrivateKey, SigningKey};

impl Arbitrary for PrivateKey {
type Parameters = ();
Expand All @@ -62,6 +62,13 @@ mod tests {
.boxed()
}
}
}

#[cfg(test)]
mod tests {
use test_strategy::proptest;

use super::*;

#[proptest]
fn sign_test(private_key: PrivateKey, msg: Vec<u8>) {
Expand Down
14 changes: 10 additions & 4 deletions rust/catalyst-voting/src/crypto/elgamal/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,15 +66,14 @@ impl Add<&Ciphertext> for &Ciphertext {
}
}

#[cfg(test)]
mod tests {
#[allow(missing_docs, clippy::missing_docs_in_private_items)]
mod arbitrary_impl {
use proptest::{
arbitrary::any,
prelude::{Arbitrary, BoxedStrategy, Strategy},
};
use test_strategy::proptest;

use super::*;
use super::{Ciphertext, GroupElement};

impl Arbitrary for Ciphertext {
type Parameters = ();
Expand All @@ -86,6 +85,13 @@ mod tests {
.boxed()
}
}
}

#[cfg(test)]
mod tests {
use test_strategy::proptest;

use super::*;

#[proptest]
fn ciphertext_add_test(e1: Scalar, e2: Scalar, e3: Scalar, e4: Scalar) {
Expand Down
20 changes: 14 additions & 6 deletions rust/catalyst-voting/src/crypto/group/ristretto255/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,11 @@ use curve25519_dalek::{
traits::Identity,
RistrettoPoint,
};
use rand_core::CryptoRngCore;

use crate::crypto::hash::digest::{consts::U64, Digest};
use crate::crypto::{
hash::digest::{consts::U64, Digest},
rng::rand_core::CryptoRngCore,
};

/// Ristretto group scalar.
#[derive(Debug, Clone, PartialEq, Eq)]
Expand Down Expand Up @@ -157,15 +159,14 @@ impl Sub<&GroupElement> for &GroupElement {
}
}

#[cfg(test)]
mod tests {
#[allow(missing_docs, clippy::missing_docs_in_private_items)]
mod arbitrary_impl {
use proptest::{
arbitrary::any,
prelude::{Arbitrary, BoxedStrategy, Strategy},
};
use test_strategy::proptest;

use super::*;
use super::{GroupElement, Mul, Scalar};

impl Arbitrary for Scalar {
type Parameters = ();
Expand All @@ -186,6 +187,13 @@ mod tests {
.boxed()
}
}
}

#[cfg(test)]
mod tests {
use test_strategy::proptest;

use super::*;

#[proptest]
fn scalar_arithmetic_tests(e1: Scalar, e2: Scalar, e3: Scalar) {
Expand Down
12 changes: 1 addition & 11 deletions rust/catalyst-voting/src/crypto/mod.rs
Original file line number Diff line number Diff line change
@@ -1,20 +1,10 @@
//! Crypto primitives which are used by voting protocol.

// cspell: words Seedable

use rand_chacha::ChaCha8Rng;
use rand_core::{CryptoRngCore, SeedableRng};

pub mod babystep_giantstep;
pub mod ed25519;
pub mod elgamal;
pub mod group;
pub mod hash;
pub mod rng;
pub mod zk_dl_equality;
pub mod zk_unit_vector;

/// Default random number generator `rand_chacha::ChaCha8Rng`.
#[must_use]
pub fn default_rng() -> impl CryptoRngCore {
ChaCha8Rng::from_entropy()
}
14 changes: 14 additions & 0 deletions rust/catalyst-voting/src/crypto/rng.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
//! Random number generator objects.

// cspell: words Seedable

use rand_chacha::ChaCha8Rng;
pub use rand_core;
use rand_core::{CryptoRngCore, SeedableRng};

/// Default random number generator `rand_chacha::ChaCha8Rng`.
#[must_use]
#[allow(clippy::module_name_repetitions)]
pub fn default_rng() -> impl CryptoRngCore {
ChaCha8Rng::from_entropy()
}
19 changes: 13 additions & 6 deletions rust/catalyst-voting/src/crypto/zk_unit_vector/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@ use std::ops::Mul;

use challenges::{calculate_first_challenge_hash, calculate_second_challenge_hash};
use polynomial::{calculate_polynomial_val, generate_polynomial, Polynomial};
use rand_core::CryptoRngCore;
use randomness_announcements::{Announcement, BlindingRandomness, ResponseRandomness};
use rayon::iter::{IndexedParallelIterator, IntoParallelRefIterator, ParallelIterator};
use utils::get_bit;

use crate::crypto::{
elgamal::{encrypt, Ciphertext},
group::{GroupElement, Scalar},
rng::rand_core::CryptoRngCore,
};

/// Unit vector proof struct
Expand Down Expand Up @@ -235,16 +235,14 @@ fn check_2(
&right_1 + &right_2 == left
}

#[cfg(test)]
mod tests {
#[allow(missing_docs, clippy::missing_docs_in_private_items)]
mod arbitrary_impl {
use proptest::{
prelude::{any_with, Arbitrary, BoxedStrategy, Strategy},
sample::size_range,
};
use rand_core::OsRng;
use test_strategy::proptest;

use super::{super::elgamal::generate_public_key, *};
use super::{Announcement, Ciphertext, ResponseRandomness, Scalar, UnitVectorProof};

impl Arbitrary for UnitVectorProof {
type Parameters = usize;
Expand All @@ -263,6 +261,15 @@ mod tests {
.boxed()
}
}
}

#[cfg(test)]
mod tests {
use proptest::sample::size_range;
use rand_core::OsRng;
use test_strategy::proptest;

use super::{super::elgamal::generate_public_key, *};

fn is_unit_vector(vector: &[Scalar]) -> bool {
let ones = vector.iter().filter(|s| s == &&Scalar::one()).count();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@

use std::ops::Mul;

use rand_core::CryptoRngCore;

use crate::crypto::group::{GroupElement, Scalar};
use crate::crypto::{
group::{GroupElement, Scalar},
rng::rand_core::CryptoRngCore,
};

/// Randomness generated in the proof, used for the hiding property.
#[derive(Clone, Debug, Eq, PartialEq)]
Expand Down Expand Up @@ -78,14 +79,14 @@ impl ResponseRandomness {
}
}

#[cfg(test)]
mod tests {
#[allow(missing_docs, clippy::missing_docs_in_private_items)]
mod arbitrary_impl {
use proptest::{
arbitrary::any,
prelude::{Arbitrary, BoxedStrategy, Strategy},
};

use super::*;
use super::{Announcement, BlindingRandomness, GroupElement, ResponseRandomness, Scalar};

impl Arbitrary for BlindingRandomness {
type Parameters = ();
Expand Down
1 change: 0 additions & 1 deletion rust/catalyst-voting/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
//! Voting primitives which are used among Catalyst ecosystem.

pub mod crypto;
pub mod txs;
mod utils;
pub mod vote_protocol;
3 changes: 0 additions & 3 deletions rust/catalyst-voting/src/txs/mod.rs

This file was deleted.

24 changes: 0 additions & 24 deletions rust/catalyst-voting/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,30 +2,6 @@

use std::io::Read;

/// Read a single byte from the reader.
#[inline]
pub(crate) fn read_be_u8<R: Read>(reader: &mut R) -> anyhow::Result<u8> {
let mut buf = [0u8; 1];
reader.read_exact(&mut buf)?;
Ok(u8::from_be_bytes(buf))
}

/// Read a big-endian u32 from the reader.
#[inline]
pub(crate) fn read_be_u32<R: Read>(reader: &mut R) -> anyhow::Result<u32> {
let mut buf = [0u8; 4];
reader.read_exact(&mut buf)?;
Ok(u32::from_be_bytes(buf))
}

/// Read a big-endian u64 from the reader.
#[inline]
pub(crate) fn read_be_u64<R: Read>(reader: &mut R) -> anyhow::Result<u64> {
let mut buf = [0u8; 8];
reader.read_exact(&mut buf)?;
Ok(u64::from_be_bytes(buf))
}

/// Read a N-byte array from the reader.
#[inline]
pub(crate) fn read_array<R: Read, const N: usize>(reader: &mut R) -> anyhow::Result<[u8; N]> {
Expand Down
10 changes: 4 additions & 6 deletions rust/catalyst-voting/src/vote_protocol/committee/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,10 @@

mod decoding;

use rand_core::CryptoRngCore;

use crate::crypto::{
default_rng,
elgamal::generate_public_key,
group::{GroupElement, Scalar},
rng::{default_rng, rand_core::CryptoRngCore},
};

/// Election secret key.
Expand Down Expand Up @@ -38,11 +36,11 @@ impl ElectionSecretKey {
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct ElectionPublicKey(pub(crate) GroupElement);

#[cfg(test)]
mod tests {
#[allow(missing_docs, clippy::missing_docs_in_private_items)]
mod arbitrary_impl {
use proptest::prelude::{any, Arbitrary, BoxedStrategy, Strategy};

use super::*;
use super::{ElectionSecretKey, Scalar};

impl Arbitrary for ElectionSecretKey {
type Parameters = ();
Expand Down
4 changes: 1 addition & 3 deletions rust/catalyst-voting/src/vote_protocol/tally/proof.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,11 @@

use std::ops::Mul;

use rand_core::CryptoRngCore;

use super::EncryptedTally;
use crate::{
crypto::{
default_rng,
group::{GroupElement, Scalar},
rng::{default_rng, rand_core::CryptoRngCore},
zk_dl_equality::{generate_dleq_proof, verify_dleq_proof, DleqProof},
},
vote_protocol::committee::{ElectionPublicKey, ElectionSecretKey},
Expand Down
3 changes: 2 additions & 1 deletion rust/catalyst-voting/src/vote_protocol/voter/decoding.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ use crate::{

impl EncryptedVote {
/// Get an underlying vector length.
pub(crate) fn size(&self) -> usize {
#[must_use]
pub fn size(&self) -> usize {
self.0.len()
}

Expand Down
Loading