Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(rust/catalyst-voting): Vote proof #54

Merged
merged 89 commits into from
Oct 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
89 commits
Select commit Hold shift + click to select a range
05af510
initialize a new crate
Mr-Leshiy Sep 24, 2024
6935a1b
add intentionally failed test
Mr-Leshiy Sep 24, 2024
78f601f
fix CI
Mr-Leshiy Sep 24, 2024
9423567
fix
Mr-Leshiy Sep 24, 2024
5d6b95b
fix
Mr-Leshiy Sep 24, 2024
b8d7ece
update vscode setting.recommended.json
Mr-Leshiy Sep 24, 2024
d644602
Merge branch 'main' into feat/voting-crate-setup
Mr-Leshiy Sep 24, 2024
e70f571
Merge branch 'main' into feat/el-gamal
Mr-Leshiy Sep 25, 2024
0803b50
add a basic interfaces for the vote part
Mr-Leshiy Sep 25, 2024
0ea84b3
add basic elgamal encryption based on the ristretto255 group
Mr-Leshiy Sep 25, 2024
91106ff
add arithmetic tests for ristretto255
Mr-Leshiy Sep 26, 2024
e1b8251
fix tests
Mr-Leshiy Sep 26, 2024
6c2d961
wip
Mr-Leshiy Sep 26, 2024
594d114
add decryption algorithm, add tests
Mr-Leshiy Sep 26, 2024
c1b749d
fix CI
Mr-Leshiy Sep 26, 2024
0a5bb99
remove unused std_ops_gen
Mr-Leshiy Sep 26, 2024
0348b6c
add new voter module
Mr-Leshiy Sep 27, 2024
9d9ddd6
add EncryptionRandomness random generation
Mr-Leshiy Sep 27, 2024
c342a1e
add a tally function
Mr-Leshiy Sep 27, 2024
bc658d6
Merge branch 'main' into feat/tally
Mr-Leshiy Sep 27, 2024
7eacd5b
fix
Mr-Leshiy Sep 27, 2024
15d97c6
wip
Mr-Leshiy Sep 27, 2024
dd1b1a3
add a babystep implementation
Mr-Leshiy Sep 28, 2024
a3c4d61
wip
Mr-Leshiy Sep 28, 2024
dcd1484
refactor, add decrypt_tally_result
Mr-Leshiy Sep 28, 2024
4936687
wip
Mr-Leshiy Sep 28, 2024
f572ad3
wip
Mr-Leshiy Sep 28, 2024
81a6323
add voting test
Mr-Leshiy Sep 28, 2024
f988417
remove rayon dependency for now
Mr-Leshiy Sep 29, 2024
37cf886
fix spelling, remove rayon
Mr-Leshiy Sep 30, 2024
24da2bc
fix
Mr-Leshiy Sep 30, 2024
804c723
remove unused anyhow dep
Mr-Leshiy Sep 30, 2024
921ad46
intentionally break the test
Mr-Leshiy Sep 30, 2024
fa63fe1
try
Mr-Leshiy Sep 30, 2024
c54f806
wip
Mr-Leshiy Sep 30, 2024
c444a02
update DecryptionTallySetup interface
Mr-Leshiy Sep 30, 2024
a63d11a
add doctest example
Mr-Leshiy Sep 30, 2024
688f5b7
refactor, make voting_test as integration test
Mr-Leshiy Sep 30, 2024
8466187
fix baby_step_giant_step_test
Mr-Leshiy Oct 1, 2024
eafd538
move tally module into the seprate dir
Mr-Leshiy Oct 1, 2024
ed25f6c
add new proof.rs
Mr-Leshiy Oct 1, 2024
5918f0d
refactor
Mr-Leshiy Oct 1, 2024
87af867
add to_bytes, from_bytes functions for Scalar and GroupElement
Mr-Leshiy Oct 1, 2024
5c399b9
add zk_dl_equality.rs
Mr-Leshiy Oct 1, 2024
dde81b8
add hash module
Mr-Leshiy Oct 2, 2024
e7d5079
update hash implementation
Mr-Leshiy Oct 2, 2024
c275f5a
add dleq verify function, add tests
Mr-Leshiy Oct 2, 2024
ae6c00c
implement tally proof generation and tally proof verification
Mr-Leshiy Oct 2, 2024
0a9ac9b
update voting_test with the tally proofs, fix verify_tally_proof
Mr-Leshiy Oct 2, 2024
ee09463
remove uneeded comment
Mr-Leshiy Oct 2, 2024
c75c0b0
Merge branch 'main' into feat/tally-proof
Mr-Leshiy Oct 2, 2024
1ca194c
fix
Mr-Leshiy Oct 2, 2024
5533456
fix
Mr-Leshiy Oct 2, 2024
359cf53
fix spelling
Mr-Leshiy Oct 2, 2024
a0e25ea
fix comment
Mr-Leshiy Oct 2, 2024
23b0bdc
update rust docs
Mr-Leshiy Oct 2, 2024
9fd9e0c
fix rustdoc tests
Mr-Leshiy Oct 2, 2024
d18a883
refactor
Mr-Leshiy Oct 3, 2024
9625d03
Merge branch 'main' into feat/vote-proof
Mr-Leshiy Oct 4, 2024
78dc7ef
refactor
Mr-Leshiy Oct 4, 2024
fbe4f01
add zk_unit_vector_proof module
Mr-Leshiy Oct 4, 2024
f9191ea
refactor
Mr-Leshiy Oct 4, 2024
dfd13d5
add polynomial generation
Mr-Leshiy Oct 4, 2024
258fa58
fix
Mr-Leshiy Oct 4, 2024
cbbebab
wip
Mr-Leshiy Oct 4, 2024
100bb06
wip
Mr-Leshiy Oct 4, 2024
ab47a68
finish proof generation
Mr-Leshiy Oct 4, 2024
0ac95b4
refactor
Mr-Leshiy Oct 4, 2024
8961881
add new get_bit function
Mr-Leshiy Oct 5, 2024
b7f291f
refactor bit calculation
Mr-Leshiy Oct 5, 2024
5d8f264
wip
Mr-Leshiy Oct 5, 2024
03fec93
fix calculation
Mr-Leshiy Oct 6, 2024
67c1b53
refactor imports
Mr-Leshiy Oct 6, 2024
c188438
refactor
Mr-Leshiy Oct 6, 2024
6d39086
refactor
Mr-Leshiy Oct 6, 2024
47ef261
update tests
Mr-Leshiy Oct 6, 2024
63cd467
update comment
Mr-Leshiy Oct 6, 2024
36141d1
update test
Mr-Leshiy Oct 7, 2024
8e2263a
refactor
Mr-Leshiy Oct 7, 2024
47695e1
fix doc tests
Mr-Leshiy Oct 7, 2024
a84edb4
remove redundant polynomial test
Mr-Leshiy Oct 7, 2024
7317fef
refactor imports, add voter proof module
Mr-Leshiy Oct 7, 2024
fa03427
fix doc test
Mr-Leshiy Oct 7, 2024
cb86a5e
update
Mr-Leshiy Oct 7, 2024
76c78c1
add error handling for `generate_voter_proof`
Mr-Leshiy Oct 7, 2024
5c16fae
update voting_test
Mr-Leshiy Oct 7, 2024
2a52a0c
update test
Mr-Leshiy Oct 7, 2024
5357c58
Merge branch 'main' into feat/vote-proof
Mr-Leshiy Oct 7, 2024
b096f2e
fix spelling
Mr-Leshiy Oct 8, 2024
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/catalyst-voting/src/crypto/babystep_giantstep.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

use std::collections::HashMap;

use super::group::{GroupElement, Scalar};
use crate::crypto::group::{GroupElement, Scalar};

/// Default balance value.
/// Make steps asymmetric, in order to better use caching of baby steps.
Expand Down
6 changes: 3 additions & 3 deletions rust/catalyst-voting/src/crypto/elgamal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@ use std::ops::{Add, Deref, Mul};

use rand_core::CryptoRngCore;

use super::group::{GroupElement, Scalar};
use crate::crypto::group::{GroupElement, Scalar};

/// ``ElGamal`` secret key.
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct SecretKey(Scalar);

/// ``ElGamal`` public key.
#[derive(Debug, Clone, Eq, PartialEq)]
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct PublicKey(GroupElement);

/// ``ElGamal`` ciphertext, encrypted message with the public key.
Expand All @@ -37,7 +37,7 @@ impl Deref for PublicKey {

impl SecretKey {
/// Generate a random `SecretKey` value from the random number generator.
pub fn generate<R: CryptoRngCore>(rng: &mut R) -> Self {
pub fn random<R: CryptoRngCore>(rng: &mut R) -> Self {
Self(Scalar::random(rng))
}

Expand Down
15 changes: 13 additions & 2 deletions rust/catalyst-voting/src/crypto/group/ristretto255.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,12 @@ impl Scalar {
}

/// additive identity
pub fn zero() -> Self {
pub const fn zero() -> Self {
Scalar(IScalar::ZERO)
}

/// multiplicative identity
pub fn one() -> Self {
pub const fn one() -> Self {
Scalar(IScalar::ONE)
}

Expand Down Expand Up @@ -190,6 +190,17 @@ mod tests {
}
}

impl Arbitrary for GroupElement {
type Parameters = ();
type Strategy = BoxedStrategy<Self>;

fn arbitrary_with((): Self::Parameters) -> Self::Strategy {
any::<Scalar>()
.prop_map(|s| GroupElement::GENERATOR.mul(&s))
.boxed()
}
}

#[proptest]
fn scalar_to_bytes_from_bytes_test(e1: Scalar) {
let bytes = e1.to_bytes();
Expand Down
1 change: 1 addition & 0 deletions rust/catalyst-voting/src/crypto/hash.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use curve25519_dalek::digest::{
};

/// Blake2b-512 hasher instance.
#[derive(Clone, Debug)]
pub struct Blake2b512Hasher(blake2b_simd::State);

impl Blake2b512Hasher {
Expand Down
1 change: 1 addition & 0 deletions rust/catalyst-voting/src/crypto/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ pub(crate) mod elgamal;
pub(crate) mod group;
pub(crate) mod hash;
pub(crate) mod zk_dl_equality;
pub(crate) mod zk_unit_vector;
16 changes: 8 additions & 8 deletions rust/catalyst-voting/src/crypto/zk_dl_equality.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@

// cspell: words NIZK dlog

use curve25519_dalek::digest::Update;
use curve25519_dalek::digest::Digest;

use super::{
use crate::crypto::{
group::{GroupElement, Scalar},
hash::Blake2b512Hasher,
};
Expand Down Expand Up @@ -55,12 +55,12 @@ fn calculate_challenge(
a_1: &GroupElement, a_2: &GroupElement,
) -> Scalar {
let blake2b_hasher = Blake2b512Hasher::new()
.chain(base_1.to_bytes())
.chain(base_2.to_bytes())
.chain(point_1.to_bytes())
.chain(point_2.to_bytes())
.chain(a_1.to_bytes())
.chain(a_2.to_bytes());
.chain_update(base_1.to_bytes())
.chain_update(base_2.to_bytes())
.chain_update(point_1.to_bytes())
.chain_update(point_2.to_bytes())
.chain_update(a_1.to_bytes())
.chain_update(a_2.to_bytes());

Scalar::from_hash(blake2b_hasher)
}
Expand Down
42 changes: 42 additions & 0 deletions rust/catalyst-voting/src/crypto/zk_unit_vector/challenges.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
//! ZK unit vector challenges calculation functionality

use curve25519_dalek::digest::Digest;

use crate::{
crypto::{
elgamal::Ciphertext, group::GroupElement, hash::Blake2b512Hasher,
zk_unit_vector::randomness_announcements::Announcement,
},
PublicKey,
};

/// Calculates the first challenge hash.
pub(crate) fn calculate_first_challenge_hash(
commitment_key: &GroupElement, public_key: &PublicKey, ciphertexts: &[Ciphertext],
announcements: &[Announcement],
) -> Blake2b512Hasher {
let mut hash = Blake2b512Hasher::new()
.chain_update(commitment_key.to_bytes())
.chain_update(public_key.to_bytes());
for c in ciphertexts {
hash.update(c.first().to_bytes());
hash.update(c.second().to_bytes());
}
for announcement in announcements {
hash.update(announcement.i.to_bytes());
hash.update(announcement.b.to_bytes());
hash.update(announcement.a.to_bytes());
}
hash
}

/// Calculates the second challenge hash.
pub(crate) fn calculate_second_challenge_hash(
mut com_1_hash: Blake2b512Hasher, ciphertexts: &[Ciphertext],
) -> Blake2b512Hasher {
for c in ciphertexts {
com_1_hash.update(c.first().to_bytes());
com_1_hash.update(c.second().to_bytes());
}
com_1_hash
}
Loading