Skip to content

Commit

Permalink
apply pr suggestions
Browse files Browse the repository at this point in the history
  • Loading branch information
piotr-roslaniec committed Feb 22, 2024
1 parent 6fd65bd commit 61d6e64
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 21 deletions.
55 changes: 36 additions & 19 deletions ferveo/src/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,9 @@ fn make_pvss_map(messages: &[ValidatorMessage]) -> PVSSMap<E> {
}

#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
pub struct AggregatedTranscript(PubliclyVerifiableSS<E, crate::Aggregated>);
pub struct AggregatedTranscript(
pub(crate) PubliclyVerifiableSS<E, crate::Aggregated>,
);

impl AggregatedTranscript {
pub fn new(messages: &[ValidatorMessage]) -> Result<Self> {
Expand Down Expand Up @@ -689,16 +691,19 @@ mod test_ferveo_api {
// for every test case

// Should fail if the number of validators is less than the number of messages
assert!(good_aggregate
.verify(messages.len() as u32 - 1, &messages)
.is_err());
assert!(matches!(
good_aggregate.verify(messages.len() as u32 - 1, &messages),
Err(Error::InvalidAggregateVerificationParameters(_, _))
));

// Should fail if no transcripts are provided
let mut dkg =
Dkg::new(TAU, shares_num, security_threshold, &validators, &me)
.unwrap();
let result = dkg.aggregate_transcripts(&[]);
assert!(result.is_err());
assert!(matches!(
dkg.aggregate_transcripts(&[]),
Err(Error::NoTranscriptsToAggregate)
));

// Not enough transcripts
let mut dkg =
Expand All @@ -708,8 +713,10 @@ mod test_ferveo_api {
assert!(not_enough_messages.len() < security_threshold as usize);
let insufficient_aggregate =
dkg.aggregate_transcripts(not_enough_messages).unwrap();
let result = insufficient_aggregate.verify(validators_num, &messages);
assert!(result.is_err());
assert!(matches!(
insufficient_aggregate.verify(validators_num, &messages),
Err(Error::InvalidTranscriptAggregate)
));

// Unexpected transcripts in the aggregate or transcripts from a different ritual
// Using same DKG parameters, but different DKG instances and validators
Expand All @@ -725,8 +732,10 @@ mod test_ferveo_api {
);
let mixed_messages = [&messages[..2], &bad_messages[..1]].concat();
let bad_aggregate = dkg.aggregate_transcripts(&mixed_messages).unwrap();
let result = bad_aggregate.verify(validators_num, &messages);
assert!(result.is_err());
assert!(matches!(
bad_aggregate.verify(validators_num, &messages),
Err(Error::InvalidTranscriptAggregate)
));
}

#[test_case(4, 4; "number of shares (validators) is a power of 2")]
Expand Down Expand Up @@ -761,21 +770,27 @@ mod test_ferveo_api {
// Test negative cases

// Should fail if the number of validators is less than the number of messages
assert!(good_aggregate
.verify(messages.len() as u32 - 1, messages)
.is_err());
assert!(matches!(
good_aggregate.verify(messages.len() as u32 - 1, messages),
Err(Error::InvalidAggregateVerificationParameters(_, _))
));

// Should fail if no transcripts are provided
let result = AggregatedTranscript::new(&[]);
assert!(result.is_err());
assert!(matches!(
AggregatedTranscript::new(&[]),
Err(Error::NoTranscriptsToAggregate)
));

// Not enough transcripts
let not_enough_messages = &messages[..security_threshold as usize - 1];
assert!(not_enough_messages.len() < security_threshold as usize);
let insufficient_aggregate =
AggregatedTranscript::new(not_enough_messages).unwrap();
let result = insufficient_aggregate.verify(validators_num, messages);
assert!(result.is_err());
let _result = insufficient_aggregate.verify(validators_num, messages);
assert!(matches!(
insufficient_aggregate.verify(validators_num, messages),
Err(Error::InvalidTranscriptAggregate)
));

// Unexpected transcripts in the aggregate or transcripts from a different ritual
// Using same DKG parameters, but different DKG instances and validators
Expand All @@ -788,7 +803,9 @@ mod test_ferveo_api {
);
let mixed_messages = [&messages[..2], &bad_messages[..1]].concat();
let bad_aggregate = AggregatedTranscript::new(&mixed_messages).unwrap();
let result = bad_aggregate.verify(validators_num, messages);
assert!(result.is_err());
assert!(matches!(
bad_aggregate.verify(validators_num, messages),
Err(Error::InvalidTranscriptAggregate)
));
}
}
5 changes: 3 additions & 2 deletions ferveo/src/pvss.rs
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@ impl<E: Pairing, T> PubliclyVerifiableSS<E, T> {
.values()
.map(|validator| {
// ek_{i}^{eval_i}, i = validator index
// TODO: Replace with regular, single-element exponentiation
fast_multiexp(
// &evals.evals[i..i] = &evals.evals[i]
&[evals[validator.share_index as usize]], // one share per validator
Expand Down Expand Up @@ -399,9 +400,9 @@ pub(crate) fn aggregate<E: Pairing>(

let mut shares = batch_to_projective_g2::<E>(&first_pvss.shares);

// So now we're iterating over the PVSS instances, and adding their coefficients and shares, and their sigma
// So now we're iterating over the PVSS instances, and adding their coefficients and shares, and their
// sigma is the sum of all the sigma_i, which is the proof of knowledge of the secret polynomial
// Aggregating is just adding the corresponding values in PVSS instances, so PVSS_i = PVSS_(i-1) PVSS_i
// Aggregating is just adding the corresponding values in PVSS instances, so PVSS = PVSS + PVSS_i
for next_pvss in pvss_iter {
sigma = (sigma + next_pvss.sigma).into();
coeffs
Expand Down

0 comments on commit 61d6e64

Please sign in to comment.