Skip to content

Commit 3c33555

Browse files
committed
Implementation of SimplPedPoP
This reverts commit 7bf09b5.
1 parent c3b7ae3 commit 3c33555

10 files changed

Lines changed: 2650 additions & 127 deletions

File tree

.DS_Store

6 KB
Binary file not shown.

Cargo.toml

Lines changed: 33 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,17 +22,23 @@ curve25519-dalek = { version = "4.1.0", default-features = false, features = [
2222
"zeroize",
2323
"precomputed-tables",
2424
"legacy_compatibility",
25+
"rand_core",
26+
"serde",
2527
] }
2628
subtle = { version = "2.4.1", default-features = false }
2729
merlin = { version = "3.0.0", default-features = false }
2830
getrandom_or_panic = { version = "0.0.3", default-features = false }
2931
rand_core = { version = "0.6.2", default-features = false }
30-
serde_crate = { version = "1.0.130", package = "serde", default-features = false, optional = true }
32+
serde = { version = "1.0.130", default-features = false, optional = true }
3133
serde_bytes = { version = "0.11.5", default-features = false, optional = true }
3234
cfg-if = { version = "1.0.0", optional = true }
3335
sha2 = { version = "0.10.7", default-features = false }
3436
failure = { version = "0.1.8", default-features = false, optional = true }
35-
zeroize = { version = "1.6", default-features = false, features = ["zeroize_derive"] }
37+
zeroize = { version = "1.6", default-features = false, features = [
38+
"zeroize_derive",
39+
] }
40+
derive-getters = "0.3.0"
41+
chacha20poly1305 = { version = "0.10.1", default-features = false }
3642

3743
[dev-dependencies]
3844
rand = "0.8.5"
@@ -47,17 +53,38 @@ serde_json = "1.0.68"
4753
name = "schnorr_benchmarks"
4854
harness = false
4955

56+
[[bench]]
57+
name = "simplpedpop_benchmarks"
58+
harness = false
59+
required-features = ["alloc", "aead"]
60+
5061
[features]
5162
default = ["std", "getrandom"]
5263
preaudit_deprecated = []
5364
nightly = []
54-
alloc = ["curve25519-dalek/alloc", "rand_core/alloc", "getrandom_or_panic/alloc", "serde_bytes/alloc"]
55-
std = ["alloc", "getrandom", "serde_bytes/std", "rand_core/std", "getrandom_or_panic/std"]
65+
alloc = [
66+
"curve25519-dalek/alloc",
67+
"rand_core/alloc",
68+
"getrandom_or_panic/alloc",
69+
"serde_bytes/alloc",
70+
]
71+
std = [
72+
"alloc",
73+
"getrandom",
74+
"serde_bytes/std",
75+
"rand_core/std",
76+
"getrandom_or_panic/std",
77+
"chacha20poly1305/std",
78+
]
5679
asm = ["sha2/asm"]
57-
serde = ["serde_crate", "serde_bytes", "cfg-if"]
80+
serde = ["dep:serde", "serde_bytes", "cfg-if"]
5881
# We cannot make getrandom a direct dependency because rand_core makes
5982
# getrandom a feature name, which requires forwarding.
60-
getrandom = ["rand_core/getrandom", "getrandom_or_panic/getrandom", "aead?/getrandom"]
83+
getrandom = [
84+
"rand_core/getrandom",
85+
"getrandom_or_panic/getrandom",
86+
"aead?/getrandom",
87+
]
6188
# We thus cannot forward the wasm-bindgen feature of getrandom,
6289
# but our consumers could depend upon getrandom and activate its
6390
# wasm-bindgen feature themselve, which works due to cargo features

benches/simplpedpop_benchmarks.rs

Lines changed: 221 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,221 @@
1+
use criterion::{criterion_group, criterion_main, Criterion};
2+
3+
mod simplpedpop_benches {
4+
use std::collections::{BTreeMap, BTreeSet};
5+
6+
use super::*;
7+
use criterion::BenchmarkId;
8+
use merlin::Transcript;
9+
use rand_core::OsRng;
10+
use schnorrkel::{
11+
identifier::Identifier,
12+
simplpedpop::{
13+
round1::{self, PrivateData, PublicData, PublicMessage},
14+
round2::{self, Messages},
15+
round3, Identifiers, Parameters,
16+
},
17+
};
18+
19+
fn generate_parameters(max_signers: u16, min_signers: u16) -> Vec<Parameters> {
20+
(1..=max_signers)
21+
.map(|_| Parameters::new(max_signers, min_signers))
22+
.collect()
23+
}
24+
25+
fn round1(
26+
participants: u16,
27+
threshold: u16,
28+
) -> (
29+
Vec<Parameters>,
30+
Vec<PrivateData>,
31+
Vec<PublicData>,
32+
Vec<BTreeSet<PublicMessage>>,
33+
) {
34+
let parameters_list = generate_parameters(participants, threshold);
35+
36+
let mut participants_round1_private_data = Vec::new();
37+
let mut participants_round1_public_data = Vec::new();
38+
let mut all_public_messages_vec = Vec::new();
39+
40+
for parameters in &parameters_list {
41+
let (private_data, public_message, public_data) =
42+
round1::run(parameters.clone(), OsRng).unwrap();
43+
participants_round1_private_data.push(private_data);
44+
participants_round1_public_data.push(public_data);
45+
all_public_messages_vec.push(public_message);
46+
}
47+
48+
let mut received_round1_public_messages: Vec<BTreeSet<round1::PublicMessage>> = Vec::new();
49+
50+
for (i, own_message) in all_public_messages_vec.iter().enumerate() {
51+
let mut messages_for_participant = all_public_messages_vec
52+
.iter()
53+
.enumerate()
54+
.filter(|&(j, _)| i != j)
55+
.map(|(_, message)| message.clone())
56+
.collect::<BTreeSet<_>>();
57+
58+
received_round1_public_messages.push(messages_for_participant);
59+
}
60+
61+
(
62+
parameters_list,
63+
participants_round1_private_data,
64+
participants_round1_public_data,
65+
received_round1_public_messages,
66+
)
67+
}
68+
69+
fn round2(
70+
parameters_list: &Vec<Parameters>,
71+
participants_round1_private_data: Vec<PrivateData>,
72+
participants_round1_public_data: &Vec<PublicData>,
73+
participants_round1_public_messages: &Vec<BTreeSet<PublicMessage>>,
74+
) -> (
75+
Vec<round2::PublicData<Transcript>>,
76+
Vec<Messages>,
77+
Vec<Identifiers>,
78+
Vec<Identifier>,
79+
) {
80+
let mut participants_round2_public_data = Vec::new();
81+
let mut participants_round2_public_messages = Vec::new();
82+
let mut participants_set_of_participants = Vec::new();
83+
let mut identifiers_vec = Vec::new();
84+
85+
for i in 0..*parameters_list[0].participants() {
86+
let result = round2::run(
87+
participants_round1_private_data[i as usize].clone(),
88+
&participants_round1_public_data[i as usize].clone(),
89+
participants_round1_public_messages[i as usize].clone(),
90+
Transcript::new(b"simplpedpop"),
91+
)
92+
.expect("Round 2 should complete without errors!");
93+
94+
participants_round2_public_data.push(result.0.clone());
95+
participants_round2_public_messages.push(result.1);
96+
participants_set_of_participants.push(result.0.identifiers().clone());
97+
identifiers_vec.push(*result.0.identifiers().own_identifier());
98+
}
99+
100+
(
101+
participants_round2_public_data,
102+
participants_round2_public_messages,
103+
participants_set_of_participants,
104+
identifiers_vec,
105+
)
106+
}
107+
108+
fn benchmark_simplpedpop(c: &mut Criterion) {
109+
let mut group = c.benchmark_group("SimplPedPoP");
110+
111+
group
112+
.sample_size(10)
113+
.warm_up_time(std::time::Duration::from_secs(2))
114+
.measurement_time(std::time::Duration::from_secs(30));
115+
116+
for &n in [3, 10, 100].iter() {
117+
let participants = n;
118+
let threshold = (n * 2 + 2) / 3;
119+
let parameters_list = generate_parameters(participants, threshold);
120+
121+
group.bench_function(BenchmarkId::new("round1", participants), |b| {
122+
b.iter(|| {
123+
round1::run(parameters_list[0].clone(), OsRng).unwrap();
124+
})
125+
});
126+
127+
let (
128+
parameters_list,
129+
participants_round1_private_data,
130+
participants_round1_public_data,
131+
participants_round1_public_messages,
132+
) = round1(participants, threshold);
133+
134+
group.bench_function(BenchmarkId::new("round2", participants), |b| {
135+
b.iter(|| {
136+
round2::run(
137+
participants_round1_private_data[0].clone(),
138+
&participants_round1_public_data[0],
139+
participants_round1_public_messages[0].clone(),
140+
Transcript::new(b"simplpedpop"),
141+
)
142+
.unwrap();
143+
})
144+
});
145+
146+
let (
147+
participants_round2_public_data,
148+
participants_round2_messages,
149+
participants_sets_of_participants,
150+
identifiers_vec,
151+
) = round2(
152+
&parameters_list,
153+
participants_round1_private_data.clone(),
154+
&participants_round1_public_data,
155+
&participants_round1_public_messages,
156+
);
157+
158+
let participants_round2_public_messages: Vec<round2::PublicMessage> =
159+
participants_round2_messages
160+
.iter()
161+
.map(|msg| msg.public_message().clone())
162+
.collect();
163+
164+
let participants_round2_private_messages: Vec<
165+
BTreeMap<Identifier, round2::PrivateMessage>,
166+
> = participants_round2_messages
167+
.iter()
168+
.map(|msg| msg.private_messages().clone())
169+
.collect();
170+
171+
let received_round2_public_messages = participants_round2_public_messages
172+
.iter()
173+
.enumerate()
174+
.filter(|(index, _msg)| {
175+
identifiers_vec[*index]
176+
!= *participants_sets_of_participants[0].own_identifier()
177+
})
178+
.map(|(index, msg)| (identifiers_vec[index], msg.clone()))
179+
.collect::<BTreeMap<Identifier, round2::PublicMessage>>();
180+
181+
let mut round2_private_messages: Vec<BTreeMap<Identifier, round2::PrivateMessage>> =
182+
Vec::new();
183+
184+
for participants in participants_sets_of_participants.iter() {
185+
let mut messages_for_participant = BTreeMap::new();
186+
187+
for (i, round_messages) in participants_round2_private_messages.iter().enumerate() {
188+
if let Some(message) = round_messages.get(&participants.own_identifier()) {
189+
messages_for_participant.insert(identifiers_vec[i], message.clone());
190+
}
191+
}
192+
193+
round2_private_messages.push(messages_for_participant);
194+
}
195+
196+
group.bench_function(BenchmarkId::new("round3", participants), |b| {
197+
b.iter(|| {
198+
round3::run(
199+
&received_round2_public_messages,
200+
&participants_round2_public_data[0],
201+
&participants_round1_public_data[0],
202+
participants_round1_private_data[0].clone(),
203+
&round2_private_messages[0],
204+
)
205+
.unwrap();
206+
})
207+
});
208+
}
209+
210+
group.finish();
211+
}
212+
213+
criterion_group! {
214+
name = simplpedpop_benches;
215+
config = Criterion::default();
216+
targets =
217+
benchmark_simplpedpop,
218+
}
219+
}
220+
221+
criterion_main!(simplpedpop_benches::simplpedpop_benches);

0 commit comments

Comments
 (0)