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

Document domain points determinism in DKG instances #182

Merged
merged 2 commits into from
Mar 19, 2024
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
1 change: 1 addition & 0 deletions ferveo/src/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -640,6 +640,7 @@ impl PrivateKeyShare {
mod test_ferveo_api {
use std::collections::HashMap;

use ark_std::iterable::Iterable;
use ferveo_tdec::SecretBox;
use itertools::{izip, Itertools};
use rand::{
Expand Down
69 changes: 69 additions & 0 deletions ferveo/src/dkg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -752,6 +752,75 @@ mod test_aggregation {
let sender = dkg.me.clone();
assert!(dkg.verify_message(&sender, &aggregate).is_err());
}

/// Size of the domain should be equal a power of 2
#[test]
fn test_domain_points_size_is_power_of_2() {
// Using a validators number which is not a power of 2
let validators_num = 6;
let (dkg, _) = setup_dealt_dkg_with_n_validators(
validators_num,
validators_num,
validators_num,
);
// This should cause the domain to be of size that is a power of 2
assert_eq!(dkg.domain.elements().count(), 8);
}

/// For the same number of validators, we should get the same domain points
/// in two different DKG instances
#[test]
fn test_domain_point_determinism_for_share_number() {
let validators_num = 6;
let (dkg1, _) = setup_dealt_dkg_with_n_validators(
validators_num,
validators_num,
validators_num,
);
let (dkg2, _) = setup_dealt_dkg_with_n_validators(
validators_num,
validators_num,
validators_num,
);
assert_eq!(dkg1.domain_points(), dkg2.domain_points());
}

/// For a different number of validators, two DKG instances should have different domain points
/// This is because the number of share determines the generator of the domain
#[test]
fn test_domain_points_different_for_different_domain_size() {
// In the first case, both DKG should have the same domain points despite different
// number of validators. This is because the domain size is the nearest power of 2
// and both 6 and 7 are rounded to 8
let validators_num = 6;
let (dkg1, _) = setup_dealt_dkg_with_n_validators(
validators_num,
validators_num,
validators_num,
);
let (dkg2, _) = setup_dealt_dkg_with_n_validators(
validators_num + 1,
validators_num + 1,
validators_num + 1,
);
assert_eq!(dkg1.domain.elements().count(), 8);
assert_eq!(dkg2.domain.elements().count(), 8);
assert_eq!(
dkg1.domain_points()[..validators_num as usize],
dkg2.domain_points()[..validators_num as usize]
);

// In the second case, the domain size is different and so the domain points
// should be different
let validators_num_different = 15;
let (dkg3, _) = setup_dealt_dkg_with_n_validators(
validators_num_different,
validators_num_different,
validators_num_different,
);
assert_eq!(dkg3.domain.elements().count(), 16);
assert_ne!(dkg1.domain_points(), dkg3.domain_points());
}
}

/// Test DKG parameters
Expand Down
Loading