From 34add7d928ebd326054a0994b1d8b99d32a82d68 Mon Sep 17 00:00:00 2001
From: Piotr Roslaniec
Date: Wed, 14 Feb 2024 13:52:07 +0100
Subject: [PATCH] test: document domain point determinism
---
ferveo/src/dkg.rs | 53 +++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 53 insertions(+)
diff --git a/ferveo/src/dkg.rs b/ferveo/src/dkg.rs
index 1ee6ec6e..8db940af 100644
--- a/ferveo/src/dkg.rs
+++ b/ferveo/src/dkg.rs
@@ -752,6 +752,59 @@ 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 share number which is not a power of 2
+ let shares_num = 6;
+ let (dkg, _) = setup_dealt_dkg_with(SECURITY_THRESHOLD, shares_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 shares, we should get the same domain points
+ /// in two different DKG instances
+ #[test]
+ fn test_domain_point_determinism_for_share_number() {
+ let (dkg1, _) = setup_dealt_dkg_with(SECURITY_THRESHOLD, SHARES_NUM);
+ let (dkg2, _) = setup_dealt_dkg_with(SECURITY_THRESHOLD, SHARES_NUM);
+ assert_eq!(dkg1.domain_points(), dkg2.domain_points());
+
+ // Now, let's create another DKG instance with a different power-of-2 number of shares
+ // let shares_num_other = 15;
+ // let (dkg2, _) = setup_dealt_dkg_with(SECURITY_THRESHOLD, shares_num_other);
+ // assert_eq!(dkg2.domain.elements().count(), 16);
+
+ // The first `shares_num` domain points should be the same
+ // assert_eq!(dkg1.domain_points()[..shares_num as usize], dkg2.domain_points()[..shares_num as usize]);
+ // // Up to `dkg1.domain_points().len()` should be the same
+ // assert_eq!(dkg1.domain_points(), dkg2.domain_points()[..dkg1.domain.elements().count()]);
+ }
+
+ /// For a different number of shares, 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_differet_for_different_domain_size() {
+ // In the first case, both DKG should have the same domain points despite different
+ // number of shares. This is because the domain size is the nearest power of 2
+ // and both 6 and 7 are rounded to 8
+ let shares_num = 6;
+ let (dkg1, _) = setup_dealt_dkg_with(SECURITY_THRESHOLD, shares_num);
+ let (dkg2, _) =
+ setup_dealt_dkg_with(SECURITY_THRESHOLD, shares_num + 1);
+ assert_eq!(
+ dkg1.domain_points()[..shares_num as usize],
+ dkg2.domain_points()[..shares_num as usize]
+ );
+
+ // In the second case, the domain size is different and so the domain points
+ // should be different
+ let shares_num_different = 15;
+ let (dkg3, _) =
+ setup_dealt_dkg_with(SECURITY_THRESHOLD, shares_num_different);
+ assert_ne!(dkg1.domain_points(), dkg3.domain_points());
+ }
}
/// Test DKG parameters