Skip to content

Commit

Permalink
Use UpdateTranscripts as input to update BlindedKeyShares
Browse files Browse the repository at this point in the history
  • Loading branch information
cygnusv committed May 17, 2024
1 parent f422903 commit d20ae20
Showing 1 changed file with 46 additions and 70 deletions.
116 changes: 46 additions & 70 deletions ferveo/src/refresh.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,48 +46,33 @@ impl<E: Pairing> UpdatableBlindedKeyShare<E> {
/// From PSS paper, section 4.2.3, (https://link.springer.com/content/pdf/10.1007/3-540-44750-4_27.pdf)
pub fn apply_share_updates(
&self,
share_updates: &[ShareUpdate<E>],
update_transcripts: &HashMap<u32, UpdateTranscript<E>>,
index: u32,
) -> UpdatableBlindedKeyShare<E> {
// TODO: Validate commitments from share update // FIXME: Don't forget!!!!!
// Current participant receives update transcripts from other participants
let share_updates: Vec<_> = update_transcripts
.values()
.map(|update_transcript_from_producer| {
let update_for_participant = update_transcript_from_producer
.updates
.get(&index)
.cloned()
.unwrap();
update_for_participant
})
.collect();

// TODO: Validate commitments from share update
// FIXME: Don't forget!!!!!
let updated_key_share = share_updates
.iter()
.fold(self.0.blinded_key_share, |acc, delta| (acc + delta.update).into());
UpdatableBlindedKeyShare(BlindedKeyShare{
.fold(self.0.blinded_key_share, |acc, delta| {
(acc + delta.update).into()
});
UpdatableBlindedKeyShare(BlindedKeyShare {
validator_public_key: self.0.validator_public_key,
blinded_key_share: updated_key_share
blinded_key_share: updated_key_share,
})

// let updates_for_participant: Vec<_> =
// update_transcripts_by_producer
// .values()
// .map(|update_transcript_from_producer| {
// // First, verify that the update transcript is valid
// // TODO: Find a better way to ensure they're always validated
// update_transcript_from_producer
// .verify_refresh(validator_keys_map, &fft_domain)
// .unwrap();

// let update_for_participant =
// update_transcript_from_producer
// .updates
// .get(&(p.index as u32))
// .cloned()
// .unwrap();
// update_for_participant
// })
// .collect();

// // And creates a new, refreshed share

// // TODO: Encapsulate this somewhere, originally from PrivateKeyShare.create_updated_key_share
// let updated_blinded_key_share: BlindedKeyShare<E> =
// BlindedKeyShare {
// validator_public_key: participant_public_key,
// blinded_key_share: updates_for_participant.iter().fold(
// blinded_key_share.blinded_key_share,
// |acc, delta| (acc + delta.update).into(),
// ),
// };
}

pub fn unblind_private_key_share(
Expand Down Expand Up @@ -712,44 +697,38 @@ mod tests_refresh {
})
.collect::<HashMap<u32, UpdateTranscript<E>>>();

// Participants validate first all the update transcripts.
// TODO: Find a better way to ensure they're always validated
for update_transcript in update_transcripts_by_producer.values() {
update_transcript
.verify_refresh(validator_keys_map, &fft_domain)
.unwrap();
}

// Participants refresh their shares with the updates from each other:
let refreshed_shares = contexts
.iter()
.map(|p| {
let participant_index = p.index as u32;
let blinded_key_share =
p.public_decryption_contexts[p.index].blinded_key_share;

// Current participant receives update transcripts from other participants
let updates_for_participant: Vec<_> =
update_transcripts_by_producer
.values()
.map(|update_transcript_from_producer| {
// First, verify that the update transcript is valid
// TODO: Find a better way to ensure they're always validated
update_transcript_from_producer
.verify_refresh(validator_keys_map, &fft_domain)
.unwrap();

let update_for_participant =
update_transcript_from_producer
.updates
.get(&(p.index as u32))
.cloned()
.unwrap();
update_for_participant
})
.collect();

// And creates a new, refreshed share
let updated_blinded_key_share = UpdatableBlindedKeyShare(blinded_key_share)
.apply_share_updates(&updates_for_participant);

let validator_keypair = ferveo_common::Keypair{
decryption_key: p.setup_params.b
let updated_blinded_key_share =
UpdatableBlindedKeyShare(blinded_key_share)
.apply_share_updates(
&update_transcripts_by_producer,
participant_index,
);

let validator_keypair = ferveo_common::Keypair {
decryption_key: p.setup_params.b,
};
let updated_private_share = updated_blinded_key_share.unblind_private_key_share(&validator_keypair).unwrap();
let updated_private_share = updated_blinded_key_share
.unblind_private_key_share(&validator_keypair)
.unwrap();

(p.index as u32, updated_private_share)
(participant_index, updated_private_share)
})
// We only need `threshold` refreshed shares to recover the original share
.take(security_threshold)
Expand All @@ -763,11 +742,8 @@ mod tests_refresh {
.collect::<HashMap<u32, DomainPoint<E>>>();

let x_r = ScalarField::zero();
let new_shared_private_key = combine_private_shares_at(
&x_r,
&domain_points,
&refreshed_shares
);
let new_shared_private_key =
combine_private_shares_at(&x_r, &domain_points, &refreshed_shares);
assert_eq!(shared_private_key, new_shared_private_key);
}
}

0 comments on commit d20ae20

Please sign in to comment.