Skip to content

Commit

Permalink
Update structure
Browse files Browse the repository at this point in the history
  • Loading branch information
Fiono11 committed Apr 29, 2024
2 parents 3c33555 + be37c50 commit 14ecc14
Show file tree
Hide file tree
Showing 13 changed files with 3,476 additions and 221 deletions.
22 changes: 12 additions & 10 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ zeroize = { version = "1.6", default-features = false, features = [
] }
derive-getters = "0.3.0"
chacha20poly1305 = { version = "0.10.1", default-features = false }
hex = { version = "0.4", default-features = true, optional = true }

[dev-dependencies]
rand = "0.8.5"
Expand All @@ -54,11 +55,19 @@ name = "schnorr_benchmarks"
harness = false

[[bench]]
name = "simplpedpop_benchmarks"
harness = false
name = "olaf_benchmarks"
required-features = ["alloc", "aead"]

[features]
std = [
"alloc",
"getrandom",
"serde_bytes/std",
"rand_core/std",
"getrandom_or_panic/std",
"chacha20poly1305/std",
"hex/std",
]
default = ["std", "getrandom"]
preaudit_deprecated = []
nightly = []
Expand All @@ -68,14 +77,6 @@ alloc = [
"getrandom_or_panic/alloc",
"serde_bytes/alloc",
]
std = [
"alloc",
"getrandom",
"serde_bytes/std",
"rand_core/std",
"getrandom_or_panic/std",
"chacha20poly1305/std",
]
asm = ["sha2/asm"]
serde = ["dep:serde", "serde_bytes", "cfg-if"]
# We cannot make getrandom a direct dependency because rand_core makes
Expand All @@ -93,3 +94,4 @@ getrandom = [
# See https://github.com/rust-lang/cargo/issues/9210
# and https://github.com/w3f/schnorrkel/issues/65#issuecomment-786923588
aead = ["dep:aead"]
cheater-detection = []
114 changes: 93 additions & 21 deletions benches/simplpedpop_benchmarks.rs → benches/olaf_benchmarks.rs
Original file line number Diff line number Diff line change
@@ -1,20 +1,22 @@
use criterion::{criterion_group, criterion_main, Criterion};

mod simplpedpop_benches {
use std::collections::{BTreeMap, BTreeSet};

mod olaf_benches {
use super::*;
use criterion::BenchmarkId;
use merlin::Transcript;
use rand_core::OsRng;
use schnorrkel::{
use schnorrkel::olaf::{
errors::DKGResult,
identifier::Identifier,
keys::{GroupPublicKey, GroupPublicKeyShare},
simplpedpop::{
round1::{self, PrivateData, PublicData, PublicMessage},
round2::{self, Messages},
round2,
round2::Messages,
round3, Identifiers, Parameters,
},
};
use std::collections::{BTreeMap, BTreeSet};

fn generate_parameters(max_signers: u16, min_signers: u16) -> Vec<Parameters> {
(1..=max_signers)
Expand All @@ -33,27 +35,40 @@ mod simplpedpop_benches {
) {
let parameters_list = generate_parameters(participants, threshold);

let mut all_public_messages_vec = Vec::new();
let mut participants_round1_private_data = Vec::new();
let mut participants_round1_public_data = Vec::new();
let mut all_public_messages_vec = Vec::new();

for parameters in &parameters_list {
for i in 0..parameters_list.len() {
let (private_data, public_message, public_data) =
round1::run(parameters.clone(), OsRng).unwrap();
participants_round1_private_data.push(private_data);
round1::run(parameters_list[i as usize].clone(), OsRng)
.expect("Round 1 should complete without errors!");

all_public_messages_vec.push(public_message.clone());
participants_round1_public_data.push(public_data);
all_public_messages_vec.push(public_message);
participants_round1_private_data.push(private_data);
}

let mut received_round1_public_messages: Vec<BTreeSet<round1::PublicMessage>> = Vec::new();
let mut received_round1_public_messages: Vec<BTreeSet<PublicMessage>> = Vec::new();

for (i, own_message) in all_public_messages_vec.iter().enumerate() {
let mut messages_for_participant = all_public_messages_vec
.iter()
.enumerate()
.filter(|&(j, _)| i != j)
.map(|(_, message)| message.clone())
.collect::<BTreeSet<_>>();
let mut all_public_messages = BTreeSet::new();

for i in 0..participants {
all_public_messages.insert(all_public_messages_vec[i as usize].clone());
}

// Iterate through each participant to create a set of messages excluding their own.
for i in 0..participants as usize {
let own_message = PublicMessage::new(&participants_round1_public_data[i]);

let mut messages_for_participant = BTreeSet::new();

for message in &all_public_messages {
if &own_message != message {
// Exclude the participant's own message.
messages_for_participant.insert(message.clone());
}
}

received_round1_public_messages.push(messages_for_participant);
}
Expand All @@ -72,7 +87,7 @@ mod simplpedpop_benches {
participants_round1_public_data: &Vec<PublicData>,
participants_round1_public_messages: &Vec<BTreeSet<PublicMessage>>,
) -> (
Vec<round2::PublicData<Transcript>>,
Vec<round2::PublicData>,
Vec<Messages>,
Vec<Identifiers>,
Vec<Identifier>,
Expand Down Expand Up @@ -105,6 +120,63 @@ mod simplpedpop_benches {
)
}

fn round3(
participants_sets_of_participants: &Vec<Identifiers>,
participants_round2_public_messages: &Vec<round2::PublicMessage>,
participants_round2_public_data: &Vec<round2::PublicData>,
participants_round1_public_data: &Vec<round1::PublicData>,
participants_round1_private_data: Vec<round1::PrivateData>,
participants_round2_private_messages: Vec<BTreeMap<Identifier, round2::PrivateMessage>>,
identifiers_vec: &Vec<Identifier>,
) -> DKGResult<
Vec<(
GroupPublicKey,
BTreeMap<Identifier, GroupPublicKeyShare>,
round3::PrivateData,
)>,
> {
let mut participant_data_round3 = Vec::new();

for i in 0..participants_sets_of_participants.len() {
let received_round2_public_messages = participants_round2_public_messages
.iter()
.enumerate()
.filter(|(index, _msg)| {
identifiers_vec[*index]
!= *participants_sets_of_participants[i as usize].own_identifier()
})
.map(|(index, msg)| (identifiers_vec[index], msg.clone()))
.collect::<BTreeMap<Identifier, round2::PublicMessage>>();

let mut round2_private_messages: Vec<BTreeMap<Identifier, round2::PrivateMessage>> =
Vec::new();

for participants in participants_sets_of_participants.iter() {
let mut messages_for_participant = BTreeMap::new();

for (i, round_messages) in participants_round2_private_messages.iter().enumerate() {
if let Some(message) = round_messages.get(&participants.own_identifier()) {
messages_for_participant.insert(identifiers_vec[i], message.clone());
}
}

round2_private_messages.push(messages_for_participant);
}

let result = round3::run(
&received_round2_public_messages,
&participants_round2_public_data[i as usize],
&participants_round1_public_data[i as usize],
participants_round1_private_data[i as usize].clone(),
&round2_private_messages[i as usize],
)?;

participant_data_round3.push(result);
}

Ok(participant_data_round3)
}

fn benchmark_simplpedpop(c: &mut Criterion) {
let mut group = c.benchmark_group("SimplPedPoP");

Expand Down Expand Up @@ -211,11 +283,11 @@ mod simplpedpop_benches {
}

criterion_group! {
name = simplpedpop_benches;
name = olaf_benches;
config = Criterion::default();
targets =
benchmark_simplpedpop,
}
}

criterion_main!(simplpedpop_benches::simplpedpop_benches);
criterion_main!(olaf_benches::olaf_benches);
77 changes: 0 additions & 77 deletions src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
// Display) should be snake cased, for some reason.
#![allow(non_snake_case)]

use crate::identifier::Identifier;
use core::fmt;
use core::fmt::Display;

Expand Down Expand Up @@ -160,79 +159,3 @@ where
{
E::custom(err)
}

/// A result for the SimplPedPoP protocol.
pub type DKGResult<T> = Result<T, DKGError>;

/// An error ocurred during the execution of the SimplPedPoP protocol.
#[derive(Debug, Clone, Eq, PartialEq)]
pub enum DKGError {
/// Invalid Proof of Possession.
InvalidProofOfPossession(SignatureError),
/// Invalid certificate.
InvalidCertificate(SignatureError),
/// Threshold cannot be greater than the number of participants.
ExcessiveThreshold,
/// Threshold must be at least 2.
InsufficientThreshold,
/// Number of participants is invalid.
InvalidNumberOfParticipants,
/// Secret share verification failed.
InvalidSecretShare(Identifier),
/// Invalid secret.
InvalidSecret,
/// Unknown identifier in round 2 public messages.
UnknownIdentifierRound2PublicMessages(Identifier),
/// Unknown identifier in round 2 private messages.
UnknownIdentifierRound2PrivateMessages(Identifier),
/// Unknown identifier.
UnknownIdentifier,
/// Shared public key mismatch.
SharedPublicKeyMismatch,
/// Identifier cannot be a zero scalar.
InvalidIdentifier,
/// Incorrect number of identifiers.
IncorrectNumberOfIdentifiers {
/// The expected value.
expected: usize,
/// The actual value.
actual: usize,
},
/// Incorrect number of private messages.
IncorrectNumberOfPrivateMessages {
/// The expected value.
expected: usize,
/// The actual value.
actual: usize,
},
/// Incorrect number of round 1 public messages.
IncorrectNumberOfRound1PublicMessages {
/// The expected value.
expected: usize,
/// The actual value.
actual: usize,
},
/// Incorrect number of round 2 public messages.
IncorrectNumberOfRound2PublicMessages {
/// The expected value.
expected: usize,
/// The actual value.
actual: usize,
},
/// Incorrect number of round 2 private messages.
IncorrectNumberOfRound2PrivateMessages {
/// The expected value.
expected: usize,
/// The actual value.
actual: usize,
},
/// Decryption error when decrypting an encrypted secret share.
DecryptionError(chacha20poly1305::Error),
/// Incorrect number of coefficient commitments.
InvalidSecretPolynomialCommitment {
/// The expected value.
expected: usize,
/// The actual value.
actual: usize,
},
}
6 changes: 1 addition & 5 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -245,15 +245,11 @@ pub mod cert;
pub mod context;
pub mod derive;
pub mod errors;
pub mod identifier;
pub mod sign;
pub mod vrf;

#[cfg(all(feature = "alloc", feature = "aead"))]
pub mod polynomial;

#[cfg(all(feature = "alloc", feature = "aead"))]
pub mod simplpedpop;
pub mod olaf;

#[cfg(all(feature = "aead", feature = "getrandom"))]
pub mod aead;
Expand Down
Loading

0 comments on commit 14ecc14

Please sign in to comment.