Skip to content

Commit

Permalink
Use UpdateTranscripts instead of ShareUpdate
Browse files Browse the repository at this point in the history
  • Loading branch information
cygnusv committed Mar 20, 2024
1 parent a7bbcaf commit 183e75a
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 39 deletions.
48 changes: 27 additions & 21 deletions ferveo/src/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -401,17 +401,20 @@ impl ShareRecoveryUpdate {
x_r: &DomainPoint,
) -> Result<HashMap<u32, ShareRecoveryUpdate>> {
let rng = &mut thread_rng();
let update_map = crate::refresh::ShareUpdate::create_recovery_updates(
&dkg.0.domain_and_key_map(),
x_r,
dkg.0.dkg_params.security_threshold(),
rng,
)
.into_iter()
.map(|(share_index, share_update)| {
(share_index, ShareRecoveryUpdate(share_update)) // TODO: Do we need to clone?
})
.collect();
let update_transcript =
crate::refresh::UpdateTranscript::create_recovery_updates(
&dkg.0.domain_and_key_map(),
x_r,
dkg.0.dkg_params.security_threshold(),
rng,
);
let update_map = update_transcript
.updates
.into_iter()
.map(|(share_index, share_update)| {
(share_index, ShareRecoveryUpdate(share_update)) // TODO: Do we need to clone?
})
.collect();
Ok(update_map)
}

Expand All @@ -432,16 +435,19 @@ impl ShareRefreshUpdate {
dkg: &Dkg,
) -> Result<HashMap<u32, ShareRefreshUpdate>> {
let rng = &mut thread_rng();
let updates = crate::refresh::ShareUpdate::create_refresh_updates(
&dkg.0.domain_and_key_map(),
dkg.0.dkg_params.security_threshold(),
rng,
)
.into_iter()
.map(|(share_index, share_update)| {
(share_index, ShareRefreshUpdate(share_update)) // TODO: Do we need to clone?
})
.collect::<HashMap<_, _>>();
let update_transcript =
crate::refresh::UpdateTranscript::create_refresh_updates(
&dkg.0.domain_and_key_map(),
dkg.0.dkg_params.security_threshold(),
rng,
);
let updates = update_transcript
.updates
.into_iter()
.map(|(share_index, share_update)| {
(share_index, ShareRefreshUpdate(share_update)) // TODO: Do we need to clone?
})
.collect::<HashMap<_, _>>();
Ok(updates)
}

Expand Down
10 changes: 6 additions & 4 deletions ferveo/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -477,12 +477,13 @@ mod test_dkg_full {
.keys()
.map(|v_addr| {
let deltas_i =
crate::refresh::ShareUpdate::create_recovery_updates(
crate::refresh::UpdateTranscript::create_recovery_updates(
&dkg.domain_and_key_map(),
&x_r,
dkg.dkg_params.security_threshold(),
rng,
);
)
.updates;
(v_addr.clone(), deltas_i)
})
.collect::<HashMap<_, _>>();
Expand Down Expand Up @@ -650,11 +651,12 @@ mod test_dkg_full {
.validators
.keys()
.map(|v_addr| {
let deltas_i = ShareUpdate::create_refresh_updates(
let deltas_i = UpdateTranscript::create_refresh_updates(
&dkg.domain_and_key_map(),
dkg.dkg_params.security_threshold(),
rng,
);
)
.updates;
(v_addr.clone(), deltas_i)
})
.collect::<HashMap<_, _>>();
Expand Down
27 changes: 13 additions & 14 deletions ferveo/src/refresh.rs
Original file line number Diff line number Diff line change
Expand Up @@ -345,8 +345,7 @@ mod tests_refresh {
use test_case::{test_case, test_matrix};

use crate::{
test_common::*, DomainPoint, PrivateKeyShare, ShareUpdate,
UpdatedPrivateKeyShare,
test_common::*, DomainPoint, PrivateKeyShare, UpdateTranscript, UpdatedPrivateKeyShare
};

/// Using tdec test utilities here instead of PVSS to test the internals of the shared key recovery
Expand All @@ -367,13 +366,13 @@ mod tests_refresh {
let share_updates = remaining_participants
.iter()
.map(|p| {
let share_updates = ShareUpdate::create_recovery_updates(
let share_updates = UpdateTranscript::create_recovery_updates(
&domain_points_and_keys,
x_r,
threshold,
rng,
);
(p.index as u32, share_updates)
(p.index as u32, share_updates.updates)
})
.collect::<HashMap<u32, _>>();

Expand Down Expand Up @@ -598,19 +597,19 @@ mod tests_refresh {
})
.collect::<HashMap<u32, _>>();

// Each participant prepares an update for each other participant:
let share_updates_by_producer = contexts
// Each participant prepares an update transcript for each other participant:
let update_transcripts_by_producer = contexts
.iter()
.map(|p| {
let a_share_updates_map: HashMap<u32, ShareUpdate<E>> =
ShareUpdate::<E>::create_refresh_updates(
let updates_transcript =
UpdateTranscript::<E>::create_refresh_updates(
domain_points_and_keys,
security_threshold as u32,
rng,
);
(p.index as u32, a_share_updates_map)
(p.index as u32, updates_transcript)
})
.collect::<HashMap<u32, _>>();
.collect::<HashMap<u32, UpdateTranscript<E>>>();

// Participants refresh their shares with the updates from each other:
let refreshed_shares = contexts
Expand All @@ -622,11 +621,11 @@ mod tests_refresh {
let participant_public_key =
blinded_key_share.validator_public_key;

// Current participant receives updates from other participants
let updates_for_participant: Vec<_> = share_updates_by_producer
// Current participant receives update transcripts from other participants
let updates_for_participant: Vec<_> = update_transcripts_by_producer
.values()
.map(|updates_from_producer| {
let update_for_participant = updates_from_producer
.map(|update_transcript_from_producer| {
let update_for_participant = update_transcript_from_producer.updates
.get(&(p.index as u32))
.cloned()
.unwrap();
Expand Down

0 comments on commit 183e75a

Please sign in to comment.