Skip to content

Commit

Permalink
TODO: Fix or ignore api tests
Browse files Browse the repository at this point in the history
  • Loading branch information
cygnusv committed Sep 20, 2024
1 parent 5d9bc8d commit 704bdc0
Show file tree
Hide file tree
Showing 4 changed files with 141 additions and 97 deletions.
195 changes: 98 additions & 97 deletions ferveo/src/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1065,110 +1065,111 @@ mod test_ferveo_api {
#[test_case(4, 4; "number of shares (validators) is a power of 2")]
#[test_case(7, 7; "number of shares (validators) is not a power of 2")]
#[test_case(4, 6; "number of validators greater than the number of shares")]
fn test_dkg_simple_tdec_share_refresh(
shares_num: u32,
validators_num: u32,
fn test_api_dkg_simple_tdec_share_refresh(
_shares_num: u32,
_validators_num: u32,
) {
let rng = &mut StdRng::seed_from_u64(0);
let security_threshold = shares_num / 2 + 1;
let (
messages,
_validators,
validator_keypairs,
dkgs,
ciphertext_header,
old_shared_secret,
) = make_share_update_test_inputs(
shares_num,
validators_num,
rng,
security_threshold,
);

// Each participant prepares an update for each other participant
let share_updates = dkgs
.iter()
.map(|validator_dkg| {
let share_update =
ShareRefreshUpdate::create_share_updates(validator_dkg)
.unwrap();
(validator_dkg.me().address.clone(), share_update)
})
.collect::<HashMap<_, _>>();
// let rng = &mut StdRng::seed_from_u64(0);
// let security_threshold = shares_num / 2 + 1;
// let (
// messages,
// _validators,
// validator_keypairs,
// dkgs,
// ciphertext_header,
// old_shared_secret,
// ) = make_share_update_test_inputs(
// shares_num,
// validators_num,
// rng,
// security_threshold,
// );

// Participants share updates and update their shares
// // Each participant prepares an update for each other participant
// let share_updates = dkgs
// .iter()
// .map(|validator_dkg| {
// let share_update =
// ShareRefreshUpdate::create_share_updates(validator_dkg)
// .unwrap();
// (validator_dkg.me().address.clone(), share_update)
// })
// .collect::<HashMap<_, _>>();

// Now, every participant separately:
let updated_shares: Vec<_> = dkgs
.iter()
.map(|validator_dkg| {
// Current participant receives updates from other participants
let updates_for_participant: Vec<_> = share_updates
.values()
.map(|updates| {
updates.get(&validator_dkg.me().share_index).unwrap()
})
.cloned()
.collect();

// Each validator uses their decryption key to update their share
let validator_keypair = validator_keypairs
.get(validator_dkg.me().share_index as usize)
.unwrap();
// // Participants share updates and update their shares

// And creates updated private key shares
// We need an aggregate for that
let aggregate = validator_dkg
.clone()
.aggregate_transcripts(&messages)
.unwrap();
assert!(aggregate.verify(validators_num, &messages).unwrap());
// // Now, every participant separately:
// let updated_shares: Vec<_> = dkgs
// .iter()
// .map(|validator_dkg| {
// // Current participant receives updates from other participants
// let updates_for_participant: Vec<_> = share_updates
// .values()
// .map(|updates| {
// updates.get(&validator_dkg.me().share_index).unwrap()
// })
// .cloned()
// .collect();

aggregate
.get_private_key_share(
validator_keypair,
validator_dkg.me().share_index,
)
.unwrap()
.create_updated_private_key_share_for_refresh(
&updates_for_participant,
)
.unwrap()
})
.collect();
// // Each validator uses their decryption key to update their share
// let validator_keypair = validator_keypairs
// .get(validator_dkg.me().share_index as usize)
// .unwrap();

// Participants create decryption shares
let mut decryption_shares: Vec<DecryptionShareSimple> =
validator_keypairs
.iter()
.zip_eq(dkgs.iter())
.map(|(validator_keypair, validator_dkg)| {
let pks = updated_shares
.get(validator_dkg.me().share_index as usize)
.unwrap()
.clone()
.into_private_key_share();
pks.create_decryption_share_simple(
validator_dkg,
&ciphertext_header,
validator_keypair,
AAD,
)
.unwrap()
})
// We only need `security_threshold` shares to be able to decrypt
.take(security_threshold as usize)
.collect();
decryption_shares.shuffle(rng);
// // And creates updated private key shares
// // We need an aggregate for that
// let aggregate = validator_dkg
// .clone()
// .aggregate_transcripts(&messages)
// .unwrap();
// assert!(aggregate.verify(validators_num, &messages).unwrap());

let decryption_shares =
&decryption_shares[..security_threshold as usize];
assert_eq!(decryption_shares.len(), security_threshold as usize);
// aggregate
// .get_private_key_share(
// validator_keypair,
// validator_dkg.me().share_index,
// )
// .unwrap()
// .create_updated_private_key_share_for_refresh(
// &updates_for_participant,
// )
// .unwrap()
// })
// .collect();

let new_shared_secret = combine_shares_simple(decryption_shares);
assert_eq!(
old_shared_secret, new_shared_secret,
"Shared secret reconstruction failed"
);
// // Participants create decryption shares
// let mut decryption_shares: Vec<DecryptionShareSimple> =
// validator_keypairs
// .iter()
// .zip_eq(dkgs.iter())
// .map(|(validator_keypair, validator_dkg)| {
// let pks = updated_shares
// .get(validator_dkg.me().share_index as usize)
// .unwrap()
// .clone()
// .into_private_key_share();
// pks.create_decryption_share_simple(
// validator_dkg,
// &ciphertext_header,
// validator_keypair,
// AAD,
// )
// .unwrap()
// })
// // We only need `security_threshold` shares to be able to decrypt
// .take(security_threshold as usize)
// .collect();
// decryption_shares.shuffle(rng);

// let decryption_shares =
// &decryption_shares[..security_threshold as usize];
// assert_eq!(decryption_shares.len(), security_threshold as usize);

// let new_shared_secret = combine_shares_simple(decryption_shares);
// assert_eq!(
// old_shared_secret, new_shared_secret,
// "Shared secret reconstruction failed"
// );
assert!(false);
}
}
2 changes: 2 additions & 0 deletions ferveo/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,8 @@ mod test_dkg_full {
use super::*;
use crate::test_common::*;

// type ScalarField =
// <ark_bls12_381::Bls12_381 as ark_ec::pairing::Pairing>::ScalarField;
type G2 = <ark_bls12_381::Bls12_381 as ark_ec::pairing::Pairing>::G2;

pub fn create_shared_secret_simple_tdec(
Expand Down
16 changes: 16 additions & 0 deletions ferveo/src/pvss.rs
Original file line number Diff line number Diff line change
Expand Up @@ -429,6 +429,22 @@ impl<E: Pairing, T: Aggregate> PubliclyVerifiableSS<E, T> {

Ok(refreshed_aggregate_transcript)
}

// pub fn handover(&self, index: u32, handover_transcript: &HandoverTranscript<E>) -> Result<Self> {

// let shares_after_handover = self.shares.clone();

// let new_share = ;

// shares_after_handover[index] = new_share;

// Ok(Self {
// coeffs: self.coeffs.clone(), // TODO: Make sure they're just the same
// shares: shares_after_handover,
// sigma: self.sigma,
// phantom: Default::default(),
// })
// }
}

#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq)]
Expand Down
25 changes: 25 additions & 0 deletions ferveo/src/refresh.rs
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,31 @@ impl<E: Pairing> UpdatableBlindedKeyShare<E> {
)
.map_err(|e| e.into())
}

// pub fn blind_for_handover(
// &self,
// incoming_validator_keypair: &Keypair<E>,
// ) -> Self {
// let new_blinding_factor = incoming_validator_keypair.decryption_key;
// Self(BlindedKeyShare {
// validator_public_key: self.0.validator_public_key, // FIXME
// blinded_key_share: self.0.multiply_by(new_blinding_factor),
// })
// }

// pub fn unblind_for_handover(
// &self,
// outgoing_validator_keypair: &Keypair<E>,
// ) -> Self {
// let inverse_factor = outgoing_validator_keypair
// .decryption_key
// .inverse()
// .expect("Validator decryption key must have an inverse");
// Self(BlindedKeyShare {
// validator_public_key: self.0.validator_public_key, // FIXME
// blinded_key_share: self.0.multiply_by(inverse_factor),
// })
// }
}

/// An update to a private key share generated by a participant in a share refresh operation.
Expand Down

0 comments on commit 704bdc0

Please sign in to comment.