Skip to content

Commit

Permalink
secret-sharing/src/churp: Rename some methods and fields
Browse files Browse the repository at this point in the history
Rename shareholders to pending_shareholders, replace word
randomize with proactivize and fix the names of some
methods.
  • Loading branch information
peternose committed Apr 3, 2024
1 parent 77992b9 commit 9a8a097
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 27 deletions.
8 changes: 4 additions & 4 deletions secret-sharing/src/churp/handoff.rs
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ where
}

/// Adds the given switch point to share reduction.
pub fn adds_share_reduction_switch_point(
pub fn add_share_reduction_switch_point(
&self,
id: Shareholder,
bij: D::PrimeField,
Expand Down Expand Up @@ -247,7 +247,7 @@ where
}

/// Adds the given switch point to full share distribution.
pub fn adds_full_share_distribution_switch_point(
pub fn add_full_share_distribution_switch_point(
&self,
id: Shareholder,
bij: D::PrimeField,
Expand Down Expand Up @@ -522,7 +522,7 @@ mod tests {
assert!(handoff.needs_share_reduction_switch_point(bob).unwrap());
let bij = player.switch_point(alice.clone()).unwrap();
let done = handoff
.adds_share_reduction_switch_point(bob.clone(), bij)
.add_share_reduction_switch_point(bob.clone(), bij)
.unwrap();

if i + 1 < num_points {
Expand Down Expand Up @@ -582,7 +582,7 @@ mod tests {
.unwrap());
let bij = player.switch_point(alice.clone()).unwrap();
let done = handoff
.adds_full_share_distribution_switch_point(bob.clone(), bij)
.add_full_share_distribution_switch_point(bob.clone(), bij)
.unwrap();

if i + 1 < num_points {
Expand Down
4 changes: 2 additions & 2 deletions secret-sharing/src/churp/player.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ where
.unwrap_or(D::Group::identity())
}

/// Creates a new player with a randomized state.
pub fn randomize(
/// Creates a new player with a proactivized secret polynomial.
pub fn proactivize(
&self,
p: &Polynomial<D::PrimeField>,
vm: &VerificationMatrix<D::Group>,
Expand Down
37 changes: 16 additions & 21 deletions secret-sharing/src/churp/switch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ where

let done = shares.add_bivariate_share(id, q, vm)?;
if done {
let player = shares.randomize_player()?;
let player = shares.proactivize_player()?;
let player = Arc::new(player);
*state = DimensionSwitchState::Serving(player);
}
Expand Down Expand Up @@ -377,12 +377,7 @@ where
bijs,
})
}
}

impl<D> SwitchPoints<D>
where
D: DealerParams,
{
/// Checks if a switch point is required from the given shareholder.
fn needs_point(&self, id: &Shareholder) -> bool {
if self.shareholders.len() >= self.n {
Expand Down Expand Up @@ -470,9 +465,9 @@ where
zero_hole: bool,

/// A set of shareholders providing bivariate shares.
committee: HashSet<Shareholder>,
/// A set of shareholders whose bivariate share still needs to be received.
shareholders: HashSet<Shareholder>,
/// A set of shareholders whose bivariate share still needs to be received.
pending_shareholders: HashSet<Shareholder>,

/// The sum of the received bivariate shares.
p: Option<Polynomial<D::PrimeField>>,
Expand Down Expand Up @@ -512,7 +507,7 @@ where

let rows = threshold as usize + 1;
let cols = 2 * threshold as usize + 1;
let committee = shareholders.clone();
let pending_shareholders = shareholders.clone();
let zero_hole = handoff.require_zero_hole();

Ok(Self {
Expand All @@ -522,8 +517,8 @@ where
rows,
cols,
zero_hole,
committee,
shareholders,
pending_shareholders,
p: None,
vm: None,
player,
Expand All @@ -532,7 +527,7 @@ where

/// Checks if a bivariate share is needed from the given shareholder.
fn needs_bivariate_share(&self, id: &Shareholder) -> bool {
self.shareholders.contains(id)
self.pending_shareholders.contains(id)
}

/// Verifies and adds the given bivariate share.
Expand All @@ -545,10 +540,10 @@ where
q: Polynomial<D::PrimeField>,
vm: VerificationMatrix<D::Group>,
) -> Result<bool> {
if !self.committee.contains(&id) {
if !self.shareholders.contains(&id) {
return Err(Error::UnknownShareholder.into());
}
if !self.shareholders.contains(&id) {
if !self.pending_shareholders.contains(&id) {
return Err(Error::DuplicateShareholder.into());
}

Expand Down Expand Up @@ -590,16 +585,16 @@ where
};
self.vm = Some(vm);

self.shareholders.remove(&id);
let done = self.shareholders.is_empty();
self.pending_shareholders.remove(&id);
let done = self.pending_shareholders.is_empty();

Ok(done)
}

/// Randomizes the player with the combined polynomial and verification
/// Proactivizes the player with the combined polynomial and verification
/// matrix.
fn randomize_player(&mut self) -> Result<Player<D>> {
if !self.shareholders.is_empty() {
fn proactivize_player(&mut self) -> Result<Player<D>> {
if !self.pending_shareholders.is_empty() {
return Err(Error::NotEnoughBivariateShares.into());
}

Expand All @@ -609,7 +604,7 @@ where
let vm = self.vm.take().unwrap();

let player = match &self.player {
Some(player) => player.randomize(&p, &vm)?,
Some(player) => player.proactivize(&p, &vm)?,
None => Player::new(p, vm),
};

Expand Down Expand Up @@ -851,7 +846,7 @@ mod tests {
sh += 1;

// Try to collect the polynomial and verification matrix.
let res = bs.randomize_player();
let res = bs.proactivize_player();
assert!(res.is_err());
unsafe {
assert_eq!(
Expand All @@ -877,7 +872,7 @@ mod tests {
);

// Try to collect the polynomial and verification matrix again.
let res = bs.randomize_player();
let res = bs.proactivize_player();
assert!(res.is_ok());
}
}
Expand Down

0 comments on commit 9a8a097

Please sign in to comment.