Skip to content

Commit

Permalink
fix: prevent precomputed shares from being created with inapprioriate…
Browse files Browse the repository at this point in the history
… variant
  • Loading branch information
piotr-roslaniec committed Jan 19, 2024
1 parent e79b4e5 commit f283187
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 2 deletions.
10 changes: 8 additions & 2 deletions ferveo/src/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,14 @@ impl AggregatedTranscript {
aad: &[u8],
validator_keypair: &Keypair,
) -> Result<DecryptionSharePrecomputed> {
if dkg.0.dkg_params.shares_num()
!= dkg.0.dkg_params.security_threshold()
{
return Err(Error::InvalidDkgParametersForPrecomputedVariant(
dkg.0.dkg_params.shares_num(),
dkg.0.dkg_params.security_threshold(),
));
}
let domain_points: Vec<_> = dkg
.0
.domain
Expand Down Expand Up @@ -455,8 +463,6 @@ mod test_ferveo_api {
let rng = &mut StdRng::seed_from_u64(0);

// In precomputed variant, the security threshold is equal to the number of shares
// TODO: Refactor DKG constructor to not require security threshold or this case.
// Or figure out a different way to simplify the precomputed variant API.
let security_threshold = shares_num;

let (messages, validators, validator_keypairs) =
Expand Down
5 changes: 5 additions & 0 deletions ferveo/src/bindings_python.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,11 @@ impl From<FerveoPythonError> for PyErr {
"{index}"
))
},
Error::InvalidDkgParametersForPrecomputedVariant(num_shares, security_threshold) => {
InvalidDkgParameters::new_err(format!(
"num_shares: {num_shares}, security_threshold: {security_threshold}"
))
},
},
_ => default(),
}
Expand Down
4 changes: 4 additions & 0 deletions ferveo/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,10 @@ pub enum Error {
/// Failed to access a share for a given share index
#[error("Invalid share index: {0}")]
InvalidShareIndex(u32),

/// Failed to produce a precomputed variant decryption share
#[error("Invalid DKG parameters for precomputed variant: number of shares {0}, threshold {1}")]
InvalidDkgParametersForPrecomputedVariant(u32, u32),
}

pub type Result<T> = std::result::Result<T, Error>;
Expand Down

0 comments on commit f283187

Please sign in to comment.