Skip to content

Commit

Permalink
preparing for refactor 4
Browse files Browse the repository at this point in the history
  • Loading branch information
cygnusv committed Apr 1, 2024
1 parent 4100a81 commit d00dbc5
Showing 1 changed file with 51 additions and 51 deletions.
102 changes: 51 additions & 51 deletions ferveo/src/refresh.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,41 +93,41 @@ impl<E: Pairing> PrivateKeyShare<E> {
// Perhaps RecoveryShare, or something
/// From the PSS paper, section 4.2.4, (https://link.springer.com/content/pdf/10.1007/3-540-44750-4_27.pdf)
/// `x_r` is the point at which the share is to be recovered
pub fn recover_share_from_updated_private_shares(
// TODO: Consider hiding x_r from the public API
x_r: &DomainPoint<E>,
domain_points: &HashMap<u32, DomainPoint<E>>,
// TODO: recovery_shares?
updated_shares: &HashMap<u32, UpdatedPrivateKeyShare<E>>,
) -> Result<PrivateKeyShare<E>> {
// Pick the domain points and updated shares according to share index
let mut domain_points_ = vec![];
let mut updated_shares_ = vec![];
for share_index in updated_shares.keys().sorted() {
domain_points_.push(
*domain_points
.get(share_index)
.ok_or(Error::InvalidShareIndex(*share_index))?,
);
updated_shares_.push(
updated_shares
.get(share_index)
.ok_or(Error::InvalidShareIndex(*share_index))?
.0
.clone(),
);
}

// Interpolate new shares to recover y_r
// TODO: check if this logic is repeated a bunch of times in other places
let lagrange = lagrange_basis_at::<E>(&domain_points_, x_r);
let prods =
zip_eq(updated_shares_, lagrange).map(|(y_j, l)| y_j.0.mul(l));
let y_r = prods.fold(E::G2::zero(), |acc, y_j| acc + y_j);
Ok(PrivateKeyShare(ferveo_tdec::PrivateKeyShare(
y_r.into_affine(),
)))
}
// pub fn recover_share_from_updated_private_shares(
// // TODO: Consider hiding x_r from the public API
// x_r: &DomainPoint<E>,
// domain_points: &HashMap<u32, DomainPoint<E>>,
// // TODO: recovery_shares?
// updated_shares: &HashMap<u32, UpdatedPrivateKeyShare<E>>,
// ) -> Result<PrivateKeyShare<E>> {
// // Pick the domain points and updated shares according to share index
// let mut domain_points_ = vec![];
// let mut updated_shares_ = vec![];
// for share_index in updated_shares.keys().sorted() {
// domain_points_.push(
// *domain_points
// .get(share_index)
// .ok_or(Error::InvalidShareIndex(*share_index))?,
// );
// updated_shares_.push(
// updated_shares
// .get(share_index)
// .ok_or(Error::InvalidShareIndex(*share_index))?
// .0
// .clone(),
// );
// }

// // Interpolate new shares to recover y_r
// // TODO: check if this logic is repeated a bunch of times in other places
// let lagrange = lagrange_basis_at::<E>(&domain_points_, x_r);
// let prods =
// zip_eq(updated_shares_, lagrange).map(|(y_j, l)| y_j.0.mul(l));
// let y_r = prods.fold(E::G2::zero(), |acc, y_j| acc + y_j);
// Ok(PrivateKeyShare(ferveo_tdec::PrivateKeyShare(
// y_r.into_affine(),
// )))
// }

pub fn create_decryption_share_simple(
&self,
Expand Down Expand Up @@ -673,14 +673,14 @@ mod tests_refresh {
(share_index, UpdatedPrivateKeyShare(share))
})
.collect::<HashMap<u32, _>>();
let new_shared_private_key =
PrivateKeyShare::recover_share_from_updated_private_shares(
&ScalarField::zero(),
domain_points,
&updated_private_key_shares,
)
.unwrap();
assert_eq!(shared_private_key, new_shared_private_key.0);
// let new_shared_private_key =
// PrivateKeyShare::recover_share_from_updated_private_shares(
// &ScalarField::zero(),
// domain_points,
// &updated_private_key_shares,
// )
// .unwrap();
assert_ne!(shared_private_key, shared_private_key);
}

/// Ñ parties (where t <= Ñ <= N) jointly execute a "share refresh" algorithm.
Expand Down Expand Up @@ -798,13 +798,13 @@ mod tests_refresh {
.collect::<HashMap<u32, DomainPoint<E>>>();

// Finally, let's recreate the shared private key from the refreshed shares
let new_shared_private_key =
PrivateKeyShare::recover_share_from_updated_private_shares(
&ScalarField::zero(),
&domain_points,
&refreshed_shares,
)
.unwrap();
assert_eq!(shared_private_key, new_shared_private_key.0);
// let new_shared_private_key =
// PrivateKeyShare::recover_share_from_updated_private_shares(
// &ScalarField::zero(),
// &domain_points,
// &refreshed_shares,
// )
// .unwrap();
assert_ne!(shared_private_key, shared_private_key);
}
}

0 comments on commit d00dbc5

Please sign in to comment.