Skip to content

Commit

Permalink
Some tests fixed: share updating should be done on top of blinded shares
Browse files Browse the repository at this point in the history
As suspected 2 commits ago
  • Loading branch information
cygnusv committed Mar 14, 2024
1 parent 75ed183 commit 6a26e82
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 9 deletions.
10 changes: 10 additions & 0 deletions ferveo-tdec/src/key_share.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ pub struct ShareCommitment<E: Pairing>(
#[serde_as(as = "serialization::SerdeAs")] pub E::G1Affine, // A_{i, \omega_i}
);

// TODO: Improve by adding share commitment here
// TODO: Is this a test utility perhaps?
#[derive(Debug, Copy, Clone)]
pub struct BlindedKeyShare<E: Pairing> {
pub validator_public_key: E::G2Affine, // [b] H
Expand Down Expand Up @@ -52,6 +54,14 @@ impl<E: Pairing> BlindedKeyShare<E> {
// self.blinded_key_share =
// self.blinded_key_share.mul(-*omega_inv).into_affine();
// }
pub fn unblind(
&self,
unblinding_factor: E::ScalarField,
) -> PrivateKeyShare<E> {
PrivateKeyShare::<E>(
self.blinded_key_share.mul(unblinding_factor).into_affine(),
)
}
}

#[serde_as]
Expand Down
10 changes: 6 additions & 4 deletions ferveo-tdec/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -242,13 +242,15 @@ pub mod test_common {
.enumerate()
{
let private_key_share = PrivateKeyShare::<E>(*private_share);
let b = E::ScalarField::one(); // FIXME: rand(rng);
let blinded_key_share: BlindedKeyShare<E> = private_key_share.blind(b);
let blinding_factor = E::ScalarField::rand(rng);
let blinded_key_share: BlindedKeyShare<E> =
private_key_share.blind(blinding_factor);

private_contexts.push(PrivateDecryptionContextSimple::<E> {
index,
setup_params: SetupParams {
b,
b_inv: b.inverse().unwrap(),
b: blinding_factor,
b_inv: blinding_factor.inverse().unwrap(),
g,
h_inv: E::G2Prepared::from(-h.into_group()),
g_inv: E::G1Prepared::from(-g.into_group()),
Expand Down
28 changes: 23 additions & 5 deletions ferveo/src/refresh.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ impl<E: Pairing> PrivateKeyShare<E> {
&self,
share_updates: &[ShareUpdate<E>],
) -> UpdatedPrivateKeyShare<E> {
// TODO: Validate commitments from share update
// TODO: Validate commitments from share update // FIXME: Don't forget!!!!!
let updated_key_share = share_updates
.iter()
.fold(self.0 .0, |acc, delta| (acc + delta.update).into());
Expand Down Expand Up @@ -316,7 +316,8 @@ mod tests_refresh {
use ark_bls12_381::Fr;
use ark_std::{test_rng, UniformRand, Zero};
use ferveo_tdec::{
test_common::setup_simple, PrivateDecryptionContextSimple,
test_common::setup_simple, BlindedKeyShare,
PrivateDecryptionContextSimple,
};
use rand_core::RngCore;
use test_case::{test_case, test_matrix};
Expand Down Expand Up @@ -601,9 +602,26 @@ mod tests_refresh {
.collect();

// And creates a new, refreshed share
let updated_share =
PrivateKeyShare(p.private_key_share.clone())
.create_updated_key_share(&updates_for_participant);
let blinded_key_share =
p.public_decryption_contexts[p.index].blinded_key_share;

// TODO: Encapsulate this somewhere, originally from PrivateKeyShare.create_updated_key_share
// FIXME: Validate commitments from share update, don't forget!!!!!
let updated_blinded_key_share: BlindedKeyShare<E> =
BlindedKeyShare {
validator_public_key: blinded_key_share
.validator_public_key,
blinded_key_share: updates_for_participant.iter().fold(
blinded_key_share.blinded_key_share,
|acc, delta| (acc + delta.update).into(),
),
};

let unblinding_factor = p.setup_params.b_inv;
let updated_share = UpdatedPrivateKeyShare(
updated_blinded_key_share.unblind(unblinding_factor),
);

(p.index as u32, updated_share)
})
// We only need `threshold` refreshed shares to recover the original share
Expand Down

0 comments on commit 6a26e82

Please sign in to comment.