Skip to content

Commit 855be4a

Browse files
authored
Merge pull request #441 from EspressoSystems/ak/key-reshare
Introduce resharing and committee switch in Decrypter
2 parents 22910f6 + 9f4976e commit 855be4a

File tree

32 files changed

+1632
-687
lines changed

32 files changed

+1632
-687
lines changed

Cargo.lock

Lines changed: 4 additions & 10 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,10 @@ rust-version = "1.85.0"
2828
[workspace.dependencies]
2929
aes-gcm = { version = "0.10.3" }
3030
alloy = { version = "1.0", features = ["default", "arbitrary", "k256", "serde", "rlp"] }
31-
alloy-signer = "1.0"
32-
alloy-chains = "0.2"
3331
# derive feature is not exposed via `alloy`, thus has to explicitly declare here
3432
alloy-rlp = { version = "0.3.12", features = ["derive"] }
3533
anyhow = "1.0.89"
36-
arbitrary = "1.4.1"
34+
arbitrary = { version = "1", features = ["derive"] }
3735
arbtest = "0.3.2"
3836
ark-bls12-381 = "0.5"
3937
ark-bn254 = "0.5"

multisig/Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ bincode = { workspace = true }
1414
bs58 = { workspace = true }
1515
committable = { workspace = true }
1616
constant_time_eq = { workspace = true }
17-
data-encoding = { workspace = true }
1817
ed25519-compact = { workspace = true }
1918
either = { workspace = true }
2019
rayon = { workspace = true }

sailfish-types/Cargo.toml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,10 @@ edition.workspace = true
66
rust-version.workspace = true
77

88
[dependencies]
9-
arbitrary = { workspace = true, optional = true }
9+
arbitrary = { workspace = true, optional = true, features = ["derive"] }
1010
arrayvec = { workspace = true }
1111
async-trait = { workspace = true }
1212
bincode = { workspace = true }
13-
bytes = { workspace = true }
1413
committable = { workspace = true }
1514
multisig = { path = "../multisig" }
1615
serde = { workspace = true }

sailfish/src/coordinator.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,11 @@ impl<T: Committable, C: Comm<T> + Send> Coordinator<T, C> {
115115
matches!(self.state, State::Running | State::AwaitHandover)
116116
}
117117

118+
/// Is this coordinator started in a handover state?
119+
pub fn awaits_handover(&self) -> bool {
120+
matches!(self.state, State::AwaitHandover)
121+
}
122+
118123
/// The public key of this coordinator.
119124
pub fn public_key(&self) -> PublicKey {
120125
self.key

tests/src/tests/timeboost.rs

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@ use multisig::{Committee, x25519};
1313
use sailfish_types::UNKNOWN_COMMITTEE_ID;
1414
use timeboost::types::BundleVariant;
1515
use timeboost_builder::CertifierConfig;
16-
use timeboost_crypto::prelude::{DkgDecKey, ThresholdEncKeyCell};
16+
use timeboost_crypto::prelude::DkgDecKey;
1717
use timeboost_sequencer::SequencerConfig;
18-
use timeboost_types::{ChainConfig, DkgKeyStore};
18+
use timeboost_types::{ChainConfig, DecryptionKeyCell, KeyStore};
1919
use timeboost_utils::load_generation::make_bundle;
2020
use tokio::sync::broadcast;
2121
use tokio::time::{Duration, sleep};
@@ -25,7 +25,10 @@ use url::Url;
2525
fn make_configs<R>(
2626
size: NonZeroUsize,
2727
recover_index: R,
28-
) -> (ThresholdEncKeyCell, Vec<(SequencerConfig, CertifierConfig)>)
28+
) -> (
29+
Vec<DecryptionKeyCell>,
30+
Vec<(SequencerConfig, CertifierConfig)>,
31+
)
2932
where
3033
R: Into<Option<usize>>,
3134
{
@@ -77,7 +80,7 @@ where
7780
.map(|(kp, xp, _, _, _, pa, ..)| (kp.public_key(), xp.public_key(), pa.clone())),
7881
);
7982

80-
let dkg_keystore = DkgKeyStore::new(
83+
let key_store = KeyStore::new(
8184
committee.clone(),
8285
parts
8386
.iter()
@@ -86,23 +89,22 @@ where
8689
);
8790

8891
let mut cfgs = Vec::new();
92+
let mut enc_keys = Vec::new();
8993
let recover_index = recover_index.into();
9094

91-
let enc_key = ThresholdEncKeyCell::new();
92-
9395
for (i, (kpair, xpair, dkg_sk, sa, da, pa)) in parts.into_iter().enumerate() {
96+
let enc_key = DecryptionKeyCell::new();
9497
let conf = SequencerConfig::builder()
9598
.sign_keypair(kpair.clone())
9699
.dh_keypair(xpair.clone())
97100
.dkg_key(dkg_sk)
98-
.dkg_keystore(dkg_keystore.clone())
99101
.sailfish_addr(sa)
100102
.decrypt_addr(da)
101103
.sailfish_committee(sailfish_committee.clone())
102-
.decrypt_committee(decrypt_committee.clone())
104+
.decrypt_committee((decrypt_committee.clone(), key_store.clone()))
103105
.recover(recover_index.map(|r| r == i).unwrap_or(false))
104106
.leash_len(100)
105-
.threshold_enc_key(enc_key.clone())
107+
.threshold_dec_key(enc_key.clone())
106108
.chain_config(ChainConfig::new(
107109
1,
108110
"https://theserversroom.com/ethereum/54cmzzhcj1o/"
@@ -118,16 +120,17 @@ where
118120
.address(pa)
119121
.committee(produce_committee.clone())
120122
.build();
123+
enc_keys.push(enc_key);
121124
cfgs.push((conf, pcf));
122125
}
123126

124-
(enc_key, cfgs)
127+
(enc_keys, cfgs)
125128
}
126129

127130
/// Generate random bundles at a fixed frequency.
128-
async fn gen_bundles(enc_key: ThresholdEncKeyCell, tx: broadcast::Sender<BundleVariant>) {
131+
async fn gen_bundles(enc_key: DecryptionKeyCell, tx: broadcast::Sender<BundleVariant>) {
129132
loop {
130-
let Ok(b) = make_bundle(&enc_key) else {
133+
let Ok(b) = make_bundle(enc_key.read().await.pubkey()) else {
131134
warn!("Failed to generate bundle");
132135
continue;
133136
};

tests/src/tests/timeboost/block_order.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ async fn block_order() {
2727
init_logging();
2828

2929
let num = NonZeroUsize::new(5).unwrap();
30-
let (enc_key, cfg) = make_configs(num, RECOVER_INDEX);
30+
let (enc_keys, cfg) = make_configs(num, RECOVER_INDEX);
3131

3232
let mut rxs = Vec::new();
3333
let mut tasks = JoinSet::new();
@@ -74,10 +74,11 @@ async fn block_order() {
7474
rxs.push(rx)
7575
}
7676

77-
enc_key.read().await;
78-
tracing::info!("DKG done");
77+
for enc_key in &enc_keys {
78+
enc_key.read().await;
79+
}
7980

80-
tasks.spawn(gen_bundles(enc_key, bcast.clone()));
81+
tasks.spawn(gen_bundles(enc_keys[0].clone(), bcast.clone()));
8182

8283
// Collect all outputs:
8384
let mut outputs: Vec<Vec<BlockInfo>> = vec![Vec::new(); num.get()];

tests/src/tests/timeboost/handover.rs

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@ use sailfish::consensus::Consensus;
1414
use sailfish::rbc::Rbc;
1515
use sailfish::types::{ConsensusTime, RoundNumber, Timestamp};
1616
use sailfish::{Coordinator, Event};
17-
use timeboost_crypto::prelude::{DkgDecKey, ThresholdEncKeyCell};
17+
use timeboost_crypto::prelude::DkgDecKey;
1818
use timeboost_sequencer::SequencerConfig;
19-
use timeboost_types::{ChainConfig, DkgKeyStore};
19+
use timeboost_types::{ChainConfig, DecryptionKeyCell, KeyStore};
2020
use timeboost_utils::types::logging::init_logging;
2121
use tokio::select;
2222
use tokio::sync::{broadcast, mpsc};
@@ -119,15 +119,15 @@ where
119119
.map(|_| DkgDecKey::generate())
120120
.collect::<Vec<_>>();
121121

122-
let dkg_keystore = DkgKeyStore::new(
122+
let key_store = KeyStore::new(
123123
committee.clone(),
124124
dkg_keys
125125
.iter()
126126
.enumerate()
127127
.map(|(i, sk)| (i as u8, sk.into())),
128128
);
129129

130-
let enc_key = ThresholdEncKeyCell::new();
130+
let enc_key = DecryptionKeyCell::new();
131131

132132
sign_keys
133133
.into_iter()
@@ -140,17 +140,19 @@ where
140140
.sign_keypair(k)
141141
.dh_keypair(x)
142142
.dkg_key(dkg_key)
143-
.dkg_keystore(dkg_keystore.clone())
144143
.sailfish_addr(sa)
145144
.decrypt_addr(da)
146145
.sailfish_committee(sf_committee.clone())
147-
.decrypt_committee(de_committee.clone())
146+
.decrypt_committee((de_committee.clone(), key_store.clone()))
148147
.maybe_previous_sailfish_committee(
149148
set_prev.then(|| prev[0].sailfish_committee().clone()),
150149
)
150+
.maybe_previous_decrypt_committee(
151+
set_prev.then(|| prev[0].decrypt_committee().clone()),
152+
)
151153
.recover(false)
152154
.leash_len(100)
153-
.threshold_enc_key(enc_key.clone())
155+
.threshold_dec_key(enc_key.clone())
154156
.chain_config(ChainConfig::new(
155157
1,
156158
"https://theserversroom.com/ethereum/54cmzzhcj1o/"

tests/src/tests/timeboost/transaction_order.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ async fn transaction_order() {
2828
init_logging();
2929

3030
let num = NonZeroUsize::new(5).unwrap();
31-
let (enc_key, cfg) = make_configs(num, RECOVER_INDEX);
31+
let (enc_keys, cfg) = make_configs(num, RECOVER_INDEX);
3232

3333
let mut rxs = Vec::new();
3434
let mut tasks = JoinSet::new();
@@ -73,10 +73,11 @@ async fn transaction_order() {
7373
rxs.push(rx)
7474
}
7575

76-
enc_key.read().await;
77-
tracing::info!("DKG done");
76+
for enc_key in &enc_keys {
77+
enc_key.read().await;
78+
}
7879

79-
tasks.spawn(gen_bundles(enc_key, bcast.clone()));
80+
tasks.spawn(gen_bundles(enc_keys[0].clone(), bcast.clone()));
8081

8182
for _ in 0..NUM_OF_TRANSACTIONS {
8283
let first = rxs[0].recv().await.unwrap();

timeboost-builder/Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ robusta = { path = "../robusta" }
1919
serde = { workspace = true }
2020
smallvec = { workspace = true }
2121
thiserror = { workspace = true }
22-
timeboost-proto = { path = "../timeboost-proto" }
2322
timeboost-types = { path = "../timeboost-types" }
2423
tokio = { workspace = true }
2524
tokio-util = { workspace = true }

0 commit comments

Comments
 (0)