Skip to content

Commit

Permalink
secret-sharing/src/churp: Separate handoff kinds
Browse files Browse the repository at this point in the history
  • Loading branch information
peternose committed Sep 10, 2024
1 parent 9c911a5 commit 7aeb763
Show file tree
Hide file tree
Showing 3 changed files with 270 additions and 221 deletions.
Empty file added .changelog/5847.trivial.md
Empty file.
40 changes: 31 additions & 9 deletions keymanager/src/churp/handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,10 @@ use oasis_core_runtime::{
};

use secret_sharing::{
churp::{encode_shareholder, Dealer, Handoff, HandoffKind, Shareholder, VerifiableSecretShare},
churp::{
encode_shareholder, CommitteeChanged, CommitteeUnchanged, Dealer, DealingPhase, Handoff,
HandoffKind, Shareholder, VerifiableSecretShare,
},
kdc::KeySharer,
poly::{scalar_from_bytes, scalar_to_bytes},
suites::{p384, Suite},
Expand Down Expand Up @@ -114,7 +117,7 @@ struct HandoffInfo<G: Group + GroupEncoding> {
/// The handoff epoch.
epoch: EpochTime,
/// The handoff associated with this information.
handoff: Arc<Handoff<G>>,
handoff: Arc<Box<dyn Handoff<G> + Send + Sync>>,
}

pub(crate) trait Handler {
Expand Down Expand Up @@ -597,7 +600,7 @@ impl<S: Suite> Instance<S> {
&self,
node_id: PublicKey,
status: &Status,
handoff: &Handoff<S::Group>,
handoff: &Arc<Box<dyn Handoff<S::Group> + Send + Sync>>,
client: &RemoteClient,
) -> Result<bool> {
let x = encode_shareholder::<S>(&node_id.0, &self.shareholder_dst)?;
Expand Down Expand Up @@ -652,7 +655,7 @@ impl<S: Suite> Instance<S> {
&self,
node_id: PublicKey,
status: &Status,
handoff: &Handoff<S::Group>,
handoff: &Arc<Box<dyn Handoff<S::Group> + Send + Sync>>,
client: &RemoteClient,
) -> Result<bool> {
let x = encode_shareholder::<S>(&node_id.0, &self.shareholder_dst)?;
Expand Down Expand Up @@ -686,7 +689,7 @@ impl<S: Suite> Instance<S> {
&self,
node_id: PublicKey,
status: &Status,
handoff: &Handoff<S::Group>,
handoff: &Arc<Box<dyn Handoff<S::Group> + Send + Sync>>,
client: &RemoteClient,
) -> Result<bool> {
let x = encode_shareholder::<S>(&node_id.0, &self.shareholder_dst)?;
Expand Down Expand Up @@ -930,7 +933,10 @@ impl<S: Suite> Instance<S> {
}

/// Returns the handoff for the given epoch.
fn get_handoff(&self, epoch: EpochTime) -> Result<Arc<Handoff<S::Group>>> {
fn get_handoff(
&self,
epoch: EpochTime,
) -> Result<Arc<Box<dyn Handoff<S::Group> + Send + Sync>>> {
let handoff_guard = self.handoff.lock().unwrap();

let handoff_info = handoff_guard
Expand All @@ -943,7 +949,10 @@ impl<S: Suite> Instance<S> {

/// Creates a handoff for the next handoff epoch. If a handoff already
/// exists, the existing one is returned.
fn get_or_create_handoff(&self, status: &Status) -> Result<Arc<Handoff<S::Group>>> {
fn get_or_create_handoff(
&self,
status: &Status,
) -> Result<Arc<Box<dyn Handoff<S::Group> + Send + Sync>>> {
// Make sure to lock the handoff so that we don't create two handoffs
// for the same epoch.
let mut handoff_guard = self.handoff.lock().unwrap();
Expand All @@ -965,8 +974,21 @@ impl<S: Suite> Instance<S> {
shareholders.push(x);
}
let kind = Self::handoff_kind(status);
let handoff = Handoff::new(threshold, me, shareholders, kind)?;
let handoff = Arc::new(handoff);
let handoff: Arc<Box<dyn Handoff<S::Group> + Send + Sync>> = match kind {
HandoffKind::DealingPhase => {
Arc::new(Box::new(DealingPhase::new(threshold, me, shareholders)?))
}
HandoffKind::CommitteeUnchanged => Arc::new(Box::new(CommitteeUnchanged::new(
threshold,
me,
shareholders,
)?)),
HandoffKind::CommitteeChanged => Arc::new(Box::new(CommitteeChanged::new(
threshold,
me,
shareholders,
)?)),
};

// If the committee hasn't changed, we need the latest shareholder
// to randomize its share.
Expand Down
Loading

0 comments on commit 7aeb763

Please sign in to comment.