Skip to content

Commit 96fac9a

Browse files
spike
1 parent dde3a9f commit 96fac9a

39 files changed

Lines changed: 292 additions & 304 deletions

consensus/src/simplex/config.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ where
9191
/// Consensus messages can be signed with a cryptosystem that differs from the static
9292
/// participant identity keys exposed in `participants`. For example, we can authenticate peers
9393
/// on the network with [commonware_cryptography::ed25519] keys while signing votes with shares distributed
94-
/// via [commonware_cryptography::bls12381::dkg] (which change each epoch). The scheme implementation is
94+
/// via [commonware_cryptography::bls12381::dkg::feldman_desmedt] (which change each epoch). The scheme implementation is
9595
/// responsible for reusing the exact participant ordering carried by `participants` so that signer indices
9696
/// remain stable across both key spaces; if the order diverges, validators will reject votes as coming from
9797
/// the wrong validator.

consensus/src/simplex/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,7 @@
271271
//!
272272
//! [scheme::bls12381_threshold] employs threshold cryptography (BLS12-381 threshold signatures with a `2f+1` of `3f+1` quorum)
273273
//! to generate succinct consensus certificates (verifiable with just the static public key). This scheme requires instantiating
274-
//! the shared secret via [commonware_cryptography::bls12381::dkg] and resharing whenever participants change.
274+
//! the shared secret via [commonware_cryptography::bls12381::dkg::feldman_desmedt] and resharing whenever participants change.
275275
//!
276276
//! Two (non-attributable) variants are provided:
277277
//!
@@ -296,7 +296,7 @@
296296
//! #### Succinct Certificates
297297
//!
298298
//! All broadcast consensus messages (`notarize(c,v)`, `nullify(v)`, `finalize(c,v)`) contain attestations (partial signatures) for a static
299-
//! public key (derived from a group polynomial that can be recomputed during reconfiguration using [dkg](commonware_cryptography::bls12381::dkg)).
299+
//! public key (derived from a group polynomial that can be recomputed during reconfiguration using [dkg](commonware_cryptography::bls12381::dkg::feldman_desmedt)).
300300
//! As soon as `2f+1` messages are collected, a threshold signature over `notarization(c,v)`, `nullification(v)`, and `finalization(c,v)`
301301
//! can be recovered, respectively. Because the public key is static, any of these certificates can be verified by an external
302302
//! process without following the consensus instance and/or tracking the current set of participants (as is typically required

consensus/src/simplex/scheme/bls12381_threshold/vrf.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -883,7 +883,7 @@ mod tests {
883883
use commonware_codec::{Decode, Encode};
884884
use commonware_cryptography::{
885885
bls12381::{
886-
dkg::{self, deal_anonymous},
886+
dkg::feldman_desmedt as dkg,
887887
primitives::{
888888
group::Scalar,
889889
ops::threshold,
@@ -952,7 +952,7 @@ mod tests {
952952
let mut rng = test_rng();
953953
let participants = ed25519_participants(&mut rng, 5);
954954
let (polynomial, shares) =
955-
deal_anonymous::<V, N3f1>(&mut rng, Default::default(), NZU32!(4));
955+
dkg::deal_anonymous::<V, N3f1>(&mut rng, Default::default(), NZU32!(4));
956956
Scheme::<V>::signer(
957957
NAMESPACE,
958958
participants.keys().clone(),
@@ -976,7 +976,8 @@ mod tests {
976976
fn verifier_polynomial_threshold_must_equal_quorum<V: Variant>() {
977977
let mut rng = test_rng();
978978
let participants = ed25519_participants(&mut rng, 5);
979-
let (polynomial, _) = deal_anonymous::<V, N3f1>(&mut rng, Default::default(), NZU32!(4));
979+
let (polynomial, _) =
980+
dkg::deal_anonymous::<V, N3f1>(&mut rng, Default::default(), NZU32!(4));
980981
Scheme::<V>::verifier(NAMESPACE, participants.keys().clone(), polynomial);
981982
}
982983

cryptography/conformance.toml

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,35 +18,35 @@ hash = "ad245f64a57c96036599647eaf509937173e9de01503a9e6494f29571191ade1"
1818
n_cases = 65536
1919
hash = "ba2d888e6d1050e6a361aa79430c1bb03d90eb8e74b9715b1d7d01c35a495e1d"
2020

21-
["commonware_cryptography::bls12381::dkg::test::conformance::CodecConformance<AckOrReveal<ed25519::PublicKey>>"]
21+
["commonware_cryptography::bls12381::dkg::feldman_desmedt::test::conformance::CodecConformance<AckOrReveal<ed25519::PublicKey>>"]
2222
n_cases = 65536
2323
hash = "97c266fb7821326e6333be0859025c774220c8d010e488d2fd13a743e4135f64"
2424

25-
["commonware_cryptography::bls12381::dkg::test::conformance::CodecConformance<DealerLog<MinPk,ed25519::PublicKey>>"]
25+
["commonware_cryptography::bls12381::dkg::feldman_desmedt::test::conformance::CodecConformance<DealerLog<MinPk,ed25519::PublicKey>>"]
2626
n_cases = 65536
2727
hash = "ef8d69a3cbafc5e3f8f98755337acacc6609e92d3fdee0e4576481190cb421b4"
2828

29-
["commonware_cryptography::bls12381::dkg::test::conformance::CodecConformance<DealerPrivMsg>"]
29+
["commonware_cryptography::bls12381::dkg::feldman_desmedt::test::conformance::CodecConformance<DealerPrivMsg>"]
3030
n_cases = 65536
3131
hash = "2d443ed310b383cab74abec888d0637ab81435779e274ed7be84adc7b10e2f86"
3232

33-
["commonware_cryptography::bls12381::dkg::test::conformance::CodecConformance<DealerPubMsg<MinPk>>"]
33+
["commonware_cryptography::bls12381::dkg::feldman_desmedt::test::conformance::CodecConformance<DealerPubMsg<MinPk>>"]
3434
n_cases = 65536
3535
hash = "0a15ca78d654be68bb78cf58cfd1da568f8f1585878f081735939f02da161b22"
3636

37-
["commonware_cryptography::bls12381::dkg::test::conformance::CodecConformance<DealerResult<ed25519::PublicKey>>"]
37+
["commonware_cryptography::bls12381::dkg::feldman_desmedt::test::conformance::CodecConformance<DealerResult<ed25519::PublicKey>>"]
3838
n_cases = 65536
3939
hash = "1a05e4e910dd186bd81189d79eaf1b4c211012d07f534ddaa38ab9705d80fa62"
4040

41-
["commonware_cryptography::bls12381::dkg::test::conformance::CodecConformance<Output<MinPk,ed25519::PublicKey>>"]
41+
["commonware_cryptography::bls12381::dkg::feldman_desmedt::test::conformance::CodecConformance<Output<MinPk,ed25519::PublicKey>>"]
4242
n_cases = 65536
4343
hash = "b31f32f62da530fb4861e8a46e5068e0c36ed1b509ee5bc758b6ca90a2568ad7"
4444

45-
["commonware_cryptography::bls12381::dkg::test::conformance::CodecConformance<PlayerAck<ed25519::PublicKey>>"]
45+
["commonware_cryptography::bls12381::dkg::feldman_desmedt::test::conformance::CodecConformance<PlayerAck<ed25519::PublicKey>>"]
4646
n_cases = 65536
4747
hash = "0cbb8c8644dffe0be78d1307fb5034dd804921d66799c1aaec3d335b44e9616c"
4848

49-
["commonware_cryptography::bls12381::dkg::test::conformance::CodecConformance<SignedDealerLog<MinPk,ed25519::PrivateKey>>"]
49+
["commonware_cryptography::bls12381::dkg::feldman_desmedt::test::conformance::CodecConformance<SignedDealerLog<MinPk,ed25519::PrivateKey>>"]
5050
n_cases = 65536
5151
hash = "fca94fb3b0df54a6a34edfbb8aeef28490262daf97870e12f869aee6cf7f7e67"
5252

cryptography/fuzz/Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -140,8 +140,8 @@ doc = false
140140
bench = false
141141

142142
[[bin]]
143-
name = "bls12381_golden_dkg"
144-
path = "fuzz_targets/bls12381_golden_dkg.rs"
143+
name = "bls12381_dkg_golden"
144+
path = "fuzz_targets/bls12381_dkg_golden.rs"
145145
test = false
146146
doc = false
147147
bench = false

cryptography/fuzz/fuzz_targets/bls12381_dkg.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
use arbitrary::Arbitrary;
44
use commonware_cryptography::bls12381::{
5-
dkg::FuzzPlan,
5+
dkg::feldman_desmedt::FuzzPlan,
66
primitives::variant::{MinPk, MinSig},
77
};
88
use libfuzzer_sys::fuzz_target;

cryptography/fuzz/fuzz_targets/bls12381_golden_dkg.rs renamed to cryptography/fuzz/fuzz_targets/bls12381_dkg_golden.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#![no_main]
22

33
use arbitrary::Arbitrary;
4-
use commonware_cryptography::bls12381::golden_dkg::{FuzzPlan, Setup};
4+
use commonware_cryptography::bls12381::dkg::golden::{FuzzPlan, Setup};
55
use commonware_parallel::Sequential;
66
use libfuzzer_sys::fuzz_target;
77
use std::{num::NonZeroU32, sync::LazyLock};

cryptography/src/bls12381/benches/bench.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ mod combine_public_keys;
88
mod combine_signatures;
99
mod dkg;
1010
mod evaluate_point;
11-
mod golden_dkg;
1211
mod hash_to_curve;
1312
mod msm;
1413
mod scheme_batch_verify_same_message;
@@ -24,8 +23,8 @@ mod tle_encrypt;
2423

2524
criterion_main!(
2625
batch_to_affine::benches,
27-
dkg::benches,
28-
golden_dkg::benches,
26+
dkg::golden::benches,
27+
dkg::feldman_desmedt::benches,
2928
hash_to_curve::benches,
3029
threshold_recover::benches,
3130
combine_public_keys::benches,
Lines changed: 2 additions & 182 deletions
Original file line numberDiff line numberDiff line change
@@ -1,182 +1,2 @@
1-
use commonware_cryptography::{
2-
bls12381::{
3-
dkg::{deal, Dealer, Info, Logs, Player},
4-
primitives::variant::MinSig,
5-
},
6-
ed25519::{Batch, PrivateKey, PublicKey},
7-
Signer as _,
8-
};
9-
use commonware_math::algebra::Random;
10-
use commonware_parallel::{Rayon, Sequential};
11-
use commonware_utils::{ordered::Set, Faults, N3f1, NZUsize, TryCollect};
12-
use criterion::{criterion_group, BatchSize, Criterion};
13-
use rand::{rngs::StdRng, SeedableRng};
14-
use rand_core::CryptoRngCore;
15-
use std::{collections::BTreeMap, hint::black_box};
16-
17-
type V = MinSig;
18-
19-
struct Bench {
20-
info: Info<V, PublicKey>,
21-
me: PrivateKey,
22-
logs: Logs<V, PublicKey, N3f1>,
23-
}
24-
25-
impl Bench {
26-
fn new(mut rng: impl CryptoRngCore, reshare: bool, n: u32) -> Self {
27-
let private_keys = (0..n)
28-
.map(|_| PrivateKey::random(&mut rng))
29-
.collect::<Vec<_>>();
30-
let me = private_keys.first().unwrap().clone();
31-
let me_pk = me.public_key();
32-
let dealers = private_keys
33-
.iter()
34-
.map(|sk| sk.public_key())
35-
.try_collect::<Set<_>>()
36-
.unwrap();
37-
38-
let (output, shares) = if reshare {
39-
let (o, s) =
40-
deal::<V, PublicKey, N3f1>(&mut rng, Default::default(), dealers.clone()).unwrap();
41-
(Some(o), Some(s))
42-
} else {
43-
(None, None)
44-
};
45-
let players = dealers.clone();
46-
let info = Info::new::<N3f1>(
47-
b"_COMMONWARE_CRYPTOGRAPHY_BLS12381_DKG_BENCH",
48-
0,
49-
output,
50-
Default::default(),
51-
dealers,
52-
players,
53-
)
54-
.unwrap();
55-
56-
// Create player state for every participant
57-
let mut player_states = private_keys
58-
.iter()
59-
.filter_map(|sk| {
60-
let pk = sk.public_key();
61-
if pk == me_pk {
62-
return None;
63-
}
64-
Some((
65-
pk,
66-
Player::<MinSig, PrivateKey>::new(info.clone(), sk.clone()).unwrap(),
67-
))
68-
})
69-
.collect::<BTreeMap<_, _>>();
70-
71-
let mut logs = Logs::<V, PublicKey, N3f1>::new(info.clone());
72-
for sk in private_keys {
73-
let pk = sk.public_key();
74-
let (mut dealer, pub_msg, priv_msgs) = Dealer::start::<N3f1>(
75-
&mut rng,
76-
info.clone(),
77-
sk,
78-
shares
79-
.as_ref()
80-
.and_then(|shares| shares.get_value(&pk).cloned()),
81-
)
82-
.unwrap();
83-
for (target_pk, priv_msg) in priv_msgs {
84-
// The only missing player should be ourselves.
85-
if let Some(player) = player_states.get_mut(&target_pk) {
86-
if let Some(ack) =
87-
player.dealer_message::<N3f1>(pk.clone(), pub_msg.clone(), priv_msg)
88-
{
89-
dealer.receive_player_ack(target_pk.clone(), ack).unwrap();
90-
}
91-
}
92-
}
93-
logs.record(pk, dealer.finalize::<N3f1>().check(&info).unwrap().1);
94-
}
95-
96-
Self { info, me, logs }
97-
}
98-
99-
fn pre_finalize(&self) -> (Player<V, PrivateKey>, Logs<V, PublicKey, N3f1>) {
100-
(
101-
Player::<MinSig, PrivateKey>::new(self.info.clone(), self.me.clone()).unwrap(),
102-
self.logs.clone(),
103-
)
104-
}
105-
}
106-
107-
// Configure contributors based on context
108-
cfg_if::cfg_if! {
109-
if #[cfg(full_bench)] {
110-
const CONTRIBUTORS: &[u32] = &[5, 10, 20, 50, 100, 250, 500];
111-
const CONCURRENCY: &[usize] = &[1, 4, 8];
112-
} else {
113-
const CONTRIBUTORS: &[u32] = &[5, 10, 20, 50];
114-
const CONCURRENCY: &[usize] = &[1];
115-
}
116-
}
117-
118-
fn bench_dkg(c: &mut Criterion, reshare: bool) {
119-
let suffix = if reshare {
120-
"_reshare_recovery"
121-
} else {
122-
"_recovery"
123-
};
124-
let mut rng = StdRng::seed_from_u64(0);
125-
for &n in CONTRIBUTORS {
126-
let t = N3f1::quorum(n);
127-
let bench = Bench::new(&mut rng, reshare, n);
128-
for &concurrency in CONCURRENCY {
129-
let strategy = Rayon::new(NZUsize!(concurrency)).unwrap();
130-
c.bench_function(
131-
&format!(
132-
"{}{}/n={} t={} conc={}",
133-
module_path!(),
134-
suffix,
135-
n,
136-
t,
137-
concurrency,
138-
),
139-
|b| {
140-
b.iter_batched(
141-
|| bench.pre_finalize(),
142-
|(player, logs)| {
143-
let mut finalize_rng = StdRng::seed_from_u64(0);
144-
if concurrency > 1 {
145-
black_box(
146-
player
147-
.finalize::<N3f1, Batch>(&mut finalize_rng, logs, &strategy)
148-
.unwrap(),
149-
);
150-
} else {
151-
black_box(
152-
player
153-
.finalize::<N3f1, Batch>(
154-
&mut finalize_rng,
155-
logs,
156-
&Sequential,
157-
)
158-
.unwrap(),
159-
);
160-
}
161-
},
162-
BatchSize::SmallInput,
163-
);
164-
},
165-
);
166-
}
167-
}
168-
}
169-
170-
fn bench_dkg_recovery(c: &mut Criterion) {
171-
bench_dkg(c, false);
172-
}
173-
174-
fn bench_dkg_reshare_recovery(c: &mut Criterion) {
175-
bench_dkg(c, true);
176-
}
177-
178-
criterion_group! {
179-
name = benches;
180-
config = Criterion::default().sample_size(10);
181-
targets = bench_dkg_recovery, bench_dkg_reshare_recovery
182-
}
1+
pub mod feldman_desmedt;
2+
pub mod golden;

0 commit comments

Comments
 (0)