Skip to content

Commit

Permalink
Akilesh/cggmp work edits to make cggmp work with fs-dkr (ZenGo-X#9)
Browse files Browse the repository at this point in the history
  • Loading branch information
akileshtangella authored Oct 22, 2022
1 parent 594637c commit edfbb25
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
13 changes: 7 additions & 6 deletions src/refresh_message.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ use zk_paillier::zkproofs::{DLogStatement, NiCorrectKeyProof, SALT_STRING};
// Everything here can be broadcasted
#[derive(Debug, Clone, Deserialize, Serialize)]
pub struct RefreshMessage<E: Curve, H: Digest + Clone> {
pub(crate) old_party_index: u16,
pub(crate) party_index: u16,
pdl_proof_vec: Vec<PDLwSlackProof<E, H>>,
range_proofs: Vec<AliceProof<E, H>>,
Expand All @@ -43,6 +44,7 @@ pub struct RefreshMessage<E: Curve, H: Digest + Clone> {

impl<E: Curve, H: Digest + Clone> RefreshMessage<E, H> {
pub fn distribute(
old_party_index: u16,
local_key: &mut LocalKey<E>,
new_n: u16,
) -> FsDkrResult<(RefreshMessage<E, H>, DecryptionKey)> {
Expand Down Expand Up @@ -113,6 +115,7 @@ impl<E: Curve, H: Digest + Clone> RefreshMessage<E, H> {

Ok((
RefreshMessage {
old_party_index,
party_index: local_key.i,
pdl_proof_vec,
range_proofs,
Expand Down Expand Up @@ -189,12 +192,10 @@ impl<E: Curve, H: Digest + Clone> RefreshMessage<E, H> {
.map(|k| refresh_messages[k].points_encrypted_vec[(party_index - 1) as usize].clone())
.collect();

let mut indices: Vec<u16> = (0..(parameters.threshold + 1) as usize)
.map(|i| refresh_messages[i].party_index - 1)
let indices: Vec<u16> = (0..(parameters.threshold + 1) as usize)
.map(|i| refresh_messages[i].old_party_index - 1)
.collect();

indices.sort();

// optimization - one decryption
let li_vec: Vec<_> = (0..parameters.threshold as usize + 1)
.map(|i| {
Expand Down Expand Up @@ -299,11 +300,11 @@ impl<E: Curve, H: Digest + Clone> RefreshMessage<E, H> {
);
}
}

let old_party_index = key.i;
key.i = *old_to_new_map.get(&key.i).unwrap();
key.n = new_n;

RefreshMessage::distribute(key, new_n as u16)
RefreshMessage::distribute(old_party_index, key, new_n as u16)
}

pub fn collect(
Expand Down
4 changes: 2 additions & 2 deletions src/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ mod tests {
// TODO: Verify this is correct
let new_n = keys.len() as u16;
for key in keys.iter_mut() {
let (refresh_message, new_dk) = RefreshMessage::distribute(key, new_n).unwrap();
let (refresh_message, new_dk) = RefreshMessage::distribute(key.i, key, new_n).unwrap();
refresh_messages.push(refresh_message.clone());
new_dks.insert(refresh_message.party_index.into(), new_dk);
party_key.insert(refresh_message.party_index.into(), key.clone());
Expand Down Expand Up @@ -300,7 +300,7 @@ mod tests {
let keys_len = keys.len();
for key in keys.iter_mut() {
let (refresh_message, new_dk) =
RefreshMessage::distribute(key, keys_len as u16).unwrap();
RefreshMessage::distribute(key.i, key, keys_len as u16).unwrap();
broadcast_vec.push(refresh_message);
new_dks.push(new_dk);
}
Expand Down

0 comments on commit edfbb25

Please sign in to comment.