Skip to content

Commit

Permalink
More improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
Fiono11 committed Apr 10, 2024
1 parent 7c7bb66 commit 3348a57
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 24 deletions.
40 changes: 19 additions & 21 deletions benches/simplpedpop_benchmarks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,9 @@ mod simplpedpop_benches {
Vec<round2::PublicData<Transcript>>,
Vec<round2::PublicMessage>,
) {
let mut participants_public_data_round2 = Vec::new();
let mut participants_private_data_round2 = Vec::new();
let mut participants_public_msgs_round2 = Vec::new();
let mut participants_round2_public_data = Vec::new();
let mut participants_round2_private_data = Vec::new();
let mut participants_round2_public_messages = Vec::new();

for i in 0..participants {
let result = round2::run(
Expand All @@ -59,16 +59,16 @@ mod simplpedpop_benches {
participants_round1_private_messages[i as usize].clone(),
Transcript::new(b"transcript"),
)
.expect("Round 2 should complete without errors");
.expect("Round 2 should complete without errors!");

participants_public_data_round2.push(result.0);
participants_private_data_round2.push(result.1);
participants_public_msgs_round2.push(result.2);
participants_round2_public_data.push(result.0);
participants_round2_private_data.push(result.1);
participants_round2_public_messages.push(result.2);
}

(
participants_public_data_round2,
participants_public_msgs_round2,
participants_round2_public_data,
participants_round2_public_messages,
)
}

Expand All @@ -93,7 +93,7 @@ mod simplpedpop_benches {

for parameters in parameters_list.iter() {
let (private_data, messages, public_data) =
round1::run(parameters, OsRng).expect("Round 1 should complete without errors");
round1::run(parameters, OsRng).expect("Round 1 should complete without errors!");

all_public_messages.push((
parameters.own_identifier(),
Expand Down Expand Up @@ -144,6 +144,11 @@ mod simplpedpop_benches {
participants_round1_private_messages.push(received_private_msgs);
}

for i in 0..participants {
participants_round1_public_messages[i as usize]
.remove(&parameters_list[i as usize].own_identifier());
}

(
parameters_list,
participants_round1_private_data,
Expand All @@ -162,7 +167,7 @@ mod simplpedpop_benches {
.warm_up_time(std::time::Duration::from_secs(2))
.measurement_time(std::time::Duration::from_secs(30));

for &n in [1000].iter() {
for &n in [3, 10, 100].iter() {
let participants = n;
let threshold = (n * 2 + 2) / 3;
let parameters_list = generate_parameters(participants, threshold);
Expand All @@ -182,20 +187,13 @@ mod simplpedpop_benches {
identifiers,
) = round1(participants, threshold);

let mut received_round1_public_messages = participants_round1_public_messages.clone();

for i in 0..participants {
received_round1_public_messages[i as usize]
.remove(&parameters_list[i as usize].own_identifier());
}

group.bench_function(BenchmarkId::new("round2", participants), |b| {
b.iter(|| {
round2::run(
&parameters_list[0],
participants_round1_private_data[0].clone(),
&participants_round1_public_data[0].clone(),
&received_round1_public_messages[0].clone(),
&participants_round1_public_messages[0].clone(),
participants_round1_private_messages[0].clone(),
Transcript::new(b"transcript"),
)
Expand All @@ -208,7 +206,7 @@ mod simplpedpop_benches {
parameters_list.clone(),
participants_round1_private_data.clone(),
participants_round1_public_data.clone(),
received_round1_public_messages.clone(),
participants_round1_public_messages.clone(),
participants_round1_private_messages.clone(),
);

Expand All @@ -230,7 +228,7 @@ mod simplpedpop_benches {
&received_round2_public_messages,
&participants_round2_public_data[0],
&participants_round1_public_data[0],
&received_round1_public_messages[0],
&participants_round1_public_messages[0],
)
.unwrap();
})
Expand Down
14 changes: 11 additions & 3 deletions src/simplpedpop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -931,6 +931,12 @@ pub mod tests {
participants_round1_private_messages.push(received_private_msgs);
}

// Remove own public messages
for i in 0..participants {
participants_round1_public_messages[i as usize]
.remove(&parameters_list[i as usize].own_identifier());
}

(
parameters_list,
participants_round1_private_data,
Expand All @@ -942,19 +948,21 @@ pub mod tests {
}

#[test]
fn test_incorrect_number_of_public_messages_in_round2() {
fn test_incorrect_number_of_round1_public_messages_in_round2() {
let participants: u16 = 5;
let threshold: u16 = 3;

let (
parameters_list,
participants_round1_private_data,
participants_round1_public_data,
participants_round1_public_messages,
mut participants_round1_public_messages,
participants_round1_private_messages,
_identifiers,
) = round1(participants, threshold);

participants_round1_public_messages[0].remove(&2.try_into().unwrap());

let result = round2::run(
&parameters_list[0],
participants_round1_private_data[0].clone(),
Expand All @@ -970,7 +978,7 @@ pub mod tests {
e,
DKGError::IncorrectNumberOfRound1PublicMessages {
expected: participants as usize - 1,
actual: participants as usize
actual: participants as usize - 2,
},
"Expected DKGError::IncorrectNumberOfRound1PublicMessages."
),
Expand Down

0 comments on commit 3348a57

Please sign in to comment.