Skip to content

Commit

Permalink
Fix test_dkg_simple_tdec_share_recovery
Browse files Browse the repository at this point in the history
Updaters for shares were not applied correctly (see diff in  L417-422).
  • Loading branch information
cygnusv committed Sep 11, 2023
1 parent ce675a6 commit 8a42529
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 15 deletions.
2 changes: 1 addition & 1 deletion ferveo/src/dkg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -355,7 +355,7 @@ pub(crate) mod test_common {
my_index: usize,
) -> TestSetup {
let keypairs = gen_keypairs(shares_num);
let mut validators = gen_validators(&keypairs);
let mut validators = gen_validators(&keypairs.as_slice());
validators.sort();
let me = validators[my_index].clone();
let dkg = PubliclyVerifiableDkg::new(
Expand Down
33 changes: 19 additions & 14 deletions ferveo/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ mod test_dkg_full {
&dkg,
aad,
&ciphertext.header().unwrap(),
&validator_keypairs,
validator_keypairs.as_slice(),
);

let plaintext = tpke::decrypt_with_shared_secret(
Expand Down Expand Up @@ -310,7 +310,7 @@ mod test_dkg_full {
&dkg,
aad,
&ciphertext.header().unwrap(),
&validator_keypairs,
validator_keypairs.as_slice(),
);

izip!(
Expand Down Expand Up @@ -373,11 +373,9 @@ mod test_dkg_full {
&dkg,
aad,
&ciphertext.header().unwrap(),
&validator_keypairs,
validator_keypairs.as_slice(),
);

// Now, we're going to recover a new share at a random point and check that the shared secret is still the same

// Remove one participant from the contexts and all nested structure
let removed_validator_addr =
dkg.validators.keys().last().unwrap().clone();
Expand All @@ -389,9 +387,11 @@ mod test_dkg_full {
let mut domain_points = dkg.domain.elements().collect::<Vec<_>>();
domain_points.pop().unwrap();

// Our random point
// Now, we're going to recover a new share at a random point,
// and check that the shared secret is still the same.

// Our random point:
let x_r = Fr::rand(rng);
// domain_points.push(x_r);

// Each participant prepares an update for each other participant
let share_updates = remaining_validators
Expand All @@ -409,16 +409,17 @@ mod test_dkg_full {
.collect::<HashMap<_, _>>();

// Participants share updates and update their shares
// TODO: Consider moving into the loop
let pvss_aggregated = aggregate(&dkg.vss);

// Now, every participant separately:
// TODO: Move this logic outside tests
let updated_shares: Vec<_> = remaining_validators
.iter()
.map(|(validator_address, validator)| {
// Receives updates from other participants
let updates_for_participant =
share_updates.get(validator_address).unwrap();
.map(|(_validator_address, validator)| {
// Current participant receives updates from other participants
let updates_for_participant: Vec<_> = share_updates
.values()
.map(|updates| *updates.get(validator.share_index).unwrap())
.collect();

// Each validator uses their decryption key to update their share
let decryption_key = validator_keypairs
Expand All @@ -427,10 +428,12 @@ mod test_dkg_full {
.decryption_key;

// Creates updated private key shares
// TODO: Why not using dkg.aggregate()?
let pvss_aggregated = aggregate(&dkg.vss);
pvss_aggregated.update_private_key_share_for_recovery(
&decryption_key,
validator.share_index,
updates_for_participant,
updates_for_participant.as_slice(),
)
})
.collect();
Expand All @@ -454,6 +457,8 @@ mod test_dkg_full {
.iter()
.enumerate()
.map(|(share_index, validator_keypair)| {
// TODO: Why not using dkg.aggregate()?
let pvss_aggregated = aggregate(&dkg.vss);
pvss_aggregated
.make_decryption_share_simple(
&ciphertext.header().unwrap(),
Expand Down

0 comments on commit 8a42529

Please sign in to comment.