Skip to content

Commit

Permalink
secret-sharing/src/churp: Verify the number of shareholders
Browse files Browse the repository at this point in the history
  • Loading branch information
peternose committed Sep 10, 2024
1 parent 6cb0497 commit c9a6c45
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 13 deletions.
18 changes: 18 additions & 0 deletions secret-sharing/src/churp/handoff.rs
Original file line number Diff line number Diff line change
Expand Up @@ -169,12 +169,21 @@ where
/// Creates a new handoff where the given shareholders will generate
/// a random secret and receive corresponding secret shares.
pub fn new(threshold: u8, me: G::Scalar, shareholders: Vec<G::Scalar>) -> Result<Self> {
// The number of shareholders must be at least threshold t + 2,
// ensuring that even if t Byzantine dealers reveal their secret,
// an honest shareholder cannot compute the combined bivariate
// polynomial.
if shareholders.len() < threshold as usize + 2 {
return Err(Error::NotEnoughShareholders.into());
}

let share_distribution = DimensionSwitch::new_full_share_distribution(
threshold,
me,
shareholders,
HandoffKind::DealingPhase,
)?;

share_distribution.skip_accumulating()?;
share_distribution.start_merging(None)?;

Expand Down Expand Up @@ -219,12 +228,17 @@ where
/// Creates a new handoff where the secret shares of the given shareholders
/// will be randomized.
pub fn new(threshold: u8, me: G::Scalar, shareholders: Vec<G::Scalar>) -> Result<Self> {
if shareholders.len() < threshold as usize + 1 {
return Err(Error::NotEnoughShareholders.into());
}

let share_distribution = DimensionSwitch::new_full_share_distribution(
threshold,
me,
shareholders,
HandoffKind::CommitteeUnchanged,
)?;

share_distribution.skip_accumulating()?;

Ok(Self { share_distribution })
Expand Down Expand Up @@ -278,6 +292,10 @@ where
/// Creates a new handoff where the shared secret will be transferred
/// to a new committee composed of the given shareholders.
pub fn new(threshold: u8, me: G::Scalar, shareholders: Vec<G::Scalar>) -> Result<Self> {
if shareholders.len() < threshold as usize + 1 {
return Err(Error::NotEnoughShareholders.into());
}

let share_reduction = DimensionSwitch::new_share_reduction(
threshold,
me,
Expand Down
17 changes: 4 additions & 13 deletions secret-sharing/src/churp/switch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -494,16 +494,7 @@ where
handoff: HandoffKind,
shareholder: Option<Arc<Shareholder<G>>>,
) -> Result<Self> {
// During the dealing phase, the number of shares must be at least
// threshold + 2, ensuring that even if t Byzantine dealers reveal
// their secret, an honest shareholder cannot compute the combined
// bivariate polynomial.
let min = match handoff {
HandoffKind::DealingPhase => threshold as usize + 2,
HandoffKind::CommitteeUnchanged => 1,
HandoffKind::CommitteeChanged => 1,
};
if shareholders.len() < min {
if shareholders.is_empty() {
return Err(Error::NotEnoughShareholders.into());
}

Expand Down Expand Up @@ -775,13 +766,13 @@ mod tests {
let me = prepare_shareholder(1);
let shareholders = prepare_shareholders(&[1, 2, 3]);

// Dealing phase requires at least threshold + 2 dealers.
// There should be at least 1 shareholder.
let res = BivariateShares::<Group>::new(
threshold,
me,
shareholders.clone(),
vec![],
DimensionSwitchKind::ShareReduction,
HandoffKind::DealingPhase,
hkind,
None,
);
assert!(res.is_err());
Expand Down

0 comments on commit c9a6c45

Please sign in to comment.