Skip to content

Commit d289b8c

Browse files
authored
Merge pull request #486 from EspressoSystems/ak/sg-cleanup
Refactor types for cryptographic schemes.
2 parents bc55a98 + 44ffa42 commit d289b8c

File tree

20 files changed

+285
-504
lines changed

20 files changed

+285
-504
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: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ version.workspace = true
55
edition.workspace = true
66
rust-version.workspace = true
77

8+
[features]
9+
bench = []
10+
811
[dependencies]
912
aes-gcm = { workspace = true }
1013
anyhow = { workspace = true }
@@ -42,7 +45,9 @@ serde_json = { workspace = true }
4245
[[bench]]
4346
name = "decryption"
4447
harness = false
48+
required-features = ["bench"]
4549

4650
[[bench]]
4751
name = "vess"
4852
harness = false
53+
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;

timeboost-crypto/src/cp_proof.rs

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -27,26 +27,6 @@ where
2727
_hash: PhantomData<D>,
2828
}
2929

30-
pub struct CPParameters<C, D>
31-
where
32-
C: CurveGroup,
33-
D: DuplexSpongeInterface,
34-
{
35-
_hash: PhantomData<D>,
36-
pub generator: C,
37-
pub io_pattern: DomainSeparator<D>,
38-
}
39-
40-
impl<C: CurveGroup, D: DuplexSpongeInterface> Clone for CPParameters<C, D> {
41-
fn clone(&self) -> Self {
42-
Self {
43-
_hash: PhantomData,
44-
generator: self.generator,
45-
io_pattern: self.io_pattern.clone(),
46-
}
47-
}
48-
}
49-
5030
/// Tuple (g, g_hat, h, h_hat)
5131
///
5232
/// subject to proving: DLOG_{g}(g_hat) == DLOG_{h}(h_hat)

0 commit comments

Comments
 (0)