Skip to content

Commit 9bdc678

Browse files
committed
Refactor types for cryptographic schemes.
1 parent bb04633 commit 9bdc678

File tree

19 files changed

+285
-483
lines changed

19 files changed

+285
-483
lines changed

tests/src/tests/timeboost.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ use timeboost::builder::CertifierConfig;
2222
use timeboost::config::{ChainConfig, ParentChain};
2323
use timeboost::crypto::prelude::DkgDecKey;
2424
use timeboost::sequencer::{Sequencer, SequencerConfig};
25-
use timeboost::types::{BlockNumber, BundleVariant, DecryptionKeyCell, KeyStore, Transaction};
25+
use timeboost::types::{BlockNumber, BundleVariant, KeyStore, ThresholdKeyCell, Transaction};
2626
use timeboost_utils::load_generation::make_bundle;
2727
use tokio::sync::broadcast;
2828
use tokio::time::{Duration, sleep};
@@ -33,7 +33,7 @@ async fn make_configs<R>(
3333
size: NonZeroUsize,
3434
recover_index: R,
3535
) -> (
36-
Vec<DecryptionKeyCell>,
36+
Vec<ThresholdKeyCell>,
3737
Vec<(SequencerConfig, CertifierConfig)>,
3838
)
3939
where
@@ -97,7 +97,7 @@ where
9797
let recover_index = recover_index.into();
9898

9999
for (i, (kpair, xpair, dkg_sk, sa, da, pa)) in parts.into_iter().enumerate() {
100-
let enc_key = DecryptionKeyCell::new();
100+
let enc_key = ThresholdKeyCell::new();
101101
let conf = SequencerConfig::builder()
102102
.sign_keypair(kpair.clone())
103103
.dh_keypair(xpair.clone())
@@ -143,7 +143,7 @@ where
143143
}
144144

145145
/// Generate random bundles at a fixed frequency.
146-
async fn gen_bundles(enc_key: DecryptionKeyCell, tx: broadcast::Sender<BundleVariant>) {
146+
async fn gen_bundles(enc_key: ThresholdKeyCell, tx: broadcast::Sender<BundleVariant>) {
147147
loop {
148148
let Ok(b) = make_bundle(enc_key.read().await.pubkey()) else {
149149
warn!("Failed to generate bundle");

tests/src/tests/timeboost/handover.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ use test_utils::ports::alloc_ports;
1818
use timeboost::config::{ChainConfig, ParentChain};
1919
use timeboost::crypto::prelude::DkgDecKey;
2020
use timeboost::sequencer::SequencerConfig;
21-
use timeboost::types::{DecryptionKeyCell, KeyStore};
21+
use timeboost::types::{KeyStore, ThresholdKeyCell};
2222
use timeboost_utils::types::logging::init_logging;
2323
use tokio::select;
2424
use tokio::sync::{broadcast, mpsc};
@@ -131,7 +131,7 @@ where
131131
.map(|(i, sk)| (i as u8, sk.into())),
132132
);
133133

134-
let enc_key = DecryptionKeyCell::new();
134+
let enc_key = ThresholdKeyCell::new();
135135

136136
sign_keys
137137
.into_iter()

tests/src/tests/timeboost/timeboost_handover.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,10 @@ use cliquenet::{Address, AddressableCommittee};
1010
use multisig::{Certificate, Committee, CommitteeId, Keypair, x25519};
1111
use sailfish::types::{ConsensusTime, RoundNumber, Timestamp};
1212
use timeboost::builder::Certifier;
13-
use timeboost::config::{CERTIFIER_PORT_OFFSET, ChainConfig, DECRYPTER_PORT_OFFSET, ParentChain};
13+
use timeboost::config::{CERTIFIER_PORT_OFFSET, ChainConfig, DECRYPTER_PORT_OFFSET};
1414
use timeboost::crypto::prelude::DkgDecKey;
1515
use timeboost::sequencer::{Output, SequencerConfig};
16-
use timeboost::types::{Block, BlockInfo, BundleVariant, DecryptionKeyCell, KeyStore};
16+
use timeboost::types::{Block, BlockInfo, BundleVariant, KeyStore, ThresholdKeyCell};
1717
use timeboost_utils::types::logging::init_logging;
1818
use tokio::select;
1919
use tokio::sync::broadcast::error::RecvError;
@@ -35,8 +35,8 @@ enum Cmd {
3535

3636
/// Run a handover test between the current and the next set of nodes.
3737
async fn run_handover(
38-
curr: Vec<(DecryptionKeyCell, SequencerConfig, CertifierConfig)>,
39-
next: Vec<(DecryptionKeyCell, SequencerConfig, CertifierConfig)>,
38+
curr: Vec<(ThresholdKeyCell, SequencerConfig, CertifierConfig)>,
39+
next: Vec<(ThresholdKeyCell, SequencerConfig, CertifierConfig)>,
4040
) {
4141
const NEXT_COMMITTEE_DELAY: u64 = 15;
4242
const NUM_OF_BLOCKS_PER_EPOCH: usize = 50;
@@ -288,11 +288,11 @@ async fn run_handover(
288288
/// Create sequencer configs.
289289
async fn mk_configs(
290290
id: CommitteeId,
291-
prev: &[(DecryptionKeyCell, SequencerConfig, CertifierConfig)],
291+
prev: &[(ThresholdKeyCell, SequencerConfig, CertifierConfig)],
292292
keep: usize,
293293
add: NonZeroUsize,
294294
set_prev: bool,
295-
) -> Vec<(DecryptionKeyCell, SequencerConfig, CertifierConfig)> {
295+
) -> Vec<(ThresholdKeyCell, SequencerConfig, CertifierConfig)> {
296296
let sign_keys = prev
297297
.iter()
298298
.take(keep)
@@ -391,7 +391,7 @@ async fn mk_configs(
391391
let sa = &sf_addrs[i];
392392
let da = &de_addrs[i];
393393
let pa = &cert_addrs[i];
394-
let enc_key = DecryptionKeyCell::new();
394+
let enc_key = ThresholdKeyCell::new();
395395
let conf = SequencerConfig::builder()
396396
.sign_keypair(kpair.clone())
397397
.dh_keypair(xpair.clone())
@@ -443,7 +443,7 @@ async fn mk_configs(
443443

444444
struct TestConfig {
445445
committee_id: CommitteeId,
446-
prev_configs: Vec<(DecryptionKeyCell, SequencerConfig, CertifierConfig)>,
446+
prev_configs: Vec<(ThresholdKeyCell, SequencerConfig, CertifierConfig)>,
447447
keep: usize,
448448
add: NonZeroUsize,
449449
set_prev: bool,
@@ -462,7 +462,7 @@ impl TestConfig {
462462

463463
fn with_prev_configs(
464464
mut self,
465-
prev: &[(DecryptionKeyCell, SequencerConfig, CertifierConfig)],
465+
prev: &[(ThresholdKeyCell, SequencerConfig, CertifierConfig)],
466466
) -> Self {
467467
self.prev_configs = prev.to_vec();
468468
self
@@ -483,7 +483,7 @@ impl TestConfig {
483483
self
484484
}
485485

486-
async fn build(self) -> Vec<(DecryptionKeyCell, SequencerConfig, CertifierConfig)> {
486+
async fn build(self) -> Vec<(ThresholdKeyCell, SequencerConfig, CertifierConfig)> {
487487
mk_configs(
488488
self.committee_id,
489489
&self.prev_configs,

timeboost-crypto/Cargo.toml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@ version.workspace = true
55
edition.workspace = true
66
rust-version.workspace = true
77

8+
[features]
9+
default = []
10+
bench = []
11+
812
[dependencies]
913
aes-gcm = { workspace = true }
1014
anyhow = { workspace = true }
@@ -42,7 +46,9 @@ serde_json = { workspace = true }
4246
[[bench]]
4347
name = "decryption"
4448
harness = false
49+
required-features = ["bench"]
4550

4651
[[bench]]
4752
name = "vess"
4853
harness = false
54+
required-features = ["bench"]

timeboost-crypto/benches/decryption.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@ use multisig::{Committee, KeyId, Keypair};
1212
use sha2::{Digest, Sha256};
1313
use spongefish::{DigestBridge, DuplexSpongeInterface};
1414
use timeboost_crypto::{
15-
Plaintext, sg_encryption::ShoupGennaro, traits::threshold_enc::ThresholdEncScheme,
15+
ShoupGennaro,
16+
prelude::{Plaintext, ThresholdEncScheme},
1617
};
1718

1819
const KB: usize = 1 << 10;

0 commit comments

Comments
 (0)