Skip to content

Commit e0766ea

Browse files
committed
Minor cosmetic adjustments.
1 parent c1ed300 commit e0766ea

File tree

3 files changed

+31
-27
lines changed

3 files changed

+31
-27
lines changed

timeboost-sequencer/src/decrypt.rs

Lines changed: 27 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ use crate::config::DecrypterConfig;
3030
use crate::metrics::SequencerMetrics;
3131

3232
const DKG_AAD: &[u8] = b"dkg";
33+
const THRES_AAD: &[u8] = b"threshold";
34+
3335
type Result<T> = StdResult<T, DecrypterError>;
3436
type DecShare = <DecryptionScheme as ThresholdEncScheme>::DecShare;
3537
type Ciphertext = <DecryptionScheme as ThresholdEncScheme>::Ciphertext;
@@ -53,7 +55,7 @@ enum Protocol {
5355

5456
/// Command sent to Decrypter's background Worker
5557
enum Command {
56-
/// Inform the Worker of a dkg bundle.
58+
/// Inform the Worker of a DKG bundle.
5759
Dkg(DkgBundle),
5860
/// Decrypt all encrypted transactions in the inclusion list.
5961
Decrypt((InclusionList, bool)),
@@ -69,7 +71,7 @@ enum Command {
6971
/// collectively threshold-decrypt encrypted transactions in the inclusion list during the 2nd phase
7072
/// ("Decryption phase") of timeboost.
7173
///
72-
/// The Decrypter also extracts dkg shares from inclusion lists and combines these to obtain keys.
74+
/// The Decrypter also extracts DKG shares from inclusion lists and combines these to obtain keys.
7375
///
7476
/// In timeboost protocol, a decrypter does both the share "decryption" (using its decryption key
7577
/// share), and combiner's "hatching" (using the combiner key).
@@ -94,7 +96,7 @@ pub struct Decrypter {
9496
worker_rx: Receiver<InclusionList>,
9597
/// Worker task handle.
9698
worker: JoinHandle<EndOfPlay>,
97-
/// Set of committees for which dkg bundles have already been submitted.
99+
/// Set of committees for which DKG bundles have already been submitted.
98100
submitted: BTreeSet<CommitteeId>,
99101
/// Pending threshold encryption key material
100102
enc_key: DecryptionKeyCell,
@@ -228,7 +230,7 @@ impl Decrypter {
228230
Ok(())
229231
}
230232

231-
/// Generates and returns a Dkg bundle for the current committee, if not already submitted.
233+
/// Generates and returns a DKG bundle for the current committee, if not already submitted.
232234
///
233235
/// # Returns
234236
/// - `Some(DkgBundle)` if a new dealing was successfully created for the current committee.
@@ -385,12 +387,12 @@ enum WorkerState {
385387
AwaitingHandover(HashMap<PublicKey, ResharingSubset>),
386388
/// Received enough resharing messages to complete the handover.
387389
HandoverComplete(DecryptionKey),
388-
/// Expects to obtain the initial dkg key through dkg bundles.
390+
/// Expects to obtain the initial DKG key through DKG bundles.
389391
///
390-
/// Upon startup the Worker requests dkg messages from remote nodes
392+
/// Upon startup the Worker requests DKG messages from remote nodes
391393
/// such that, if the local node is behind, it will catchup immediately.
392394
DkgPending(HashMap<PublicKey, DkgSubset>),
393-
/// Already completed at least one instance of dkg. Ready for resharing.
395+
/// Already completed at least one instance of DKG. Ready for resharing.
394396
ResharingPending(DecryptionKey),
395397
/// Obtained keys for both the current and next committee.
396398
ResharingComplete(DecryptionKey, DecryptionKey),
@@ -428,13 +430,13 @@ struct Worker {
428430
/// Channel for receiving commands from the parent.
429431
rx: Receiver<Command>,
430432

431-
/// Pending encryption key that will be updated after dkg/resharing is done.
433+
/// Pending encryption key that will be updated after DKG/resharing is done.
432434
enc_key: DecryptionKeyCell,
433435

434436
/// First round where an inclusion list was received (ignore shares for earlier rounds).
435437
first_requested_round: Option<RoundNumber>,
436438

437-
/// Decryption key used for communication between nodes for dkg and resharing.
439+
/// Decryption key used for communication between nodes for DKG and resharing.
438440
dkg_sk: LabeledDkgDecKey,
439441

440442
/// Key material for committee members (shared with Decrypter)
@@ -446,7 +448,7 @@ struct Worker {
446448
/// Number of rounds to retain.
447449
retain: usize,
448450

449-
/// Tracker for dkg bundles received through candidate lists.
451+
/// Tracker for DKG bundles received through candidate lists.
450452
#[builder(default)]
451453
dkg_tracker: BTreeMap<CommitteeId, DkgAccumulator>,
452454

@@ -637,7 +639,7 @@ impl Worker {
637639
Ok(false)
638640
}
639641

640-
/// A request for dkg subset has been received.
642+
/// A request for DKG subset has been received.
641643
async fn on_dkg_request_msg(
642644
&mut self,
643645
src: PublicKey,
@@ -682,7 +684,7 @@ impl Worker {
682684
Ok(())
683685
}
684686

685-
/// A response for dkg subset has been received.
687+
/// A response for DKG subset has been received.
686688
async fn on_dkg_response_msg(&mut self, src: PublicKey, res: SubsetResponse) -> Result<()> {
687689
trace!(node = %self.label, from=%src, %res.committee_id, "received dkg response");
688690
if res.committee_id != self.current {
@@ -1051,7 +1053,7 @@ impl Worker {
10511053
Ok(())
10521054
}
10531055

1054-
/// Catch up by requesting dkg subsets from remote nodes.
1056+
/// Catch up by requesting DKG subsets from remote nodes.
10551057
async fn dkg_catchup(&mut self) -> Result<()> {
10561058
let req = Protocol::DkgRequest(self.current);
10571059
// the round number is ignored by the recieving party, but we don't want to give an
@@ -1131,7 +1133,7 @@ impl Worker {
11311133
<DecryptionScheme as ThresholdEncScheme>::decrypt(
11321134
dec_sk.privkey(),
11331135
&ct,
1134-
&vec![],
1136+
&THRES_AAD.to_vec(),
11351137
)
11361138
.ok() // decryption failure result in None
11371139
})
@@ -1270,13 +1272,12 @@ impl Worker {
12701272
}
12711273

12721274
if let Some(ct) = opt_ct {
1273-
let aad = vec![];
12741275
match DecryptionScheme::combine(
12751276
key_store.committee(),
12761277
dec_sk.combkey(),
12771278
dec_shares,
12781279
&ct,
1279-
&aad,
1280+
&THRES_AAD.to_vec(),
12801281
) {
12811282
Ok(pt) => decrypted.push(Some(pt)),
12821283
// with f+1 decryption shares, which means ciphertext is valid, we just need to
@@ -1476,7 +1477,7 @@ impl DecShareBatch {
14761477
}
14771478
}
14781479

1479-
/// A response with the agreed-upon subset of dkg bundles.
1480+
/// A response with the agreed-upon subset of DKG bundles.
14801481
#[derive(Clone, Debug, Serialize, Deserialize)]
14811482
struct SubsetResponse {
14821483
committee_id: CommitteeId,
@@ -1566,7 +1567,7 @@ pub enum DecrypterError {
15661567
#[error("unknown key: {0}")]
15671568
UnknownKey(PublicKey),
15681569

1569-
#[error("DKG/resharing not yet complete")]
1570+
#[error("dkg/resharing not yet complete")]
15701571
DkgPending,
15711572

15721573
#[error("dkg err: {0}")]
@@ -1615,12 +1616,14 @@ mod tests {
16151616
PriorityBundle, SeqNo, Signer, Timestamp,
16161617
};
16171618

1618-
use crate::{config::DecrypterConfig, decrypt::Decrypter, metrics::SequencerMetrics};
1619+
use crate::{
1620+
config::DecrypterConfig,
1621+
decrypt::{DKG_AAD, Decrypter, THRES_AAD},
1622+
metrics::SequencerMetrics,
1623+
};
16191624

16201625
// Test constants
16211626
const COMMITTEE_SIZE: usize = 5;
1622-
const DKG_AAD: &[u8] = b"dkg";
1623-
const THRESHOLD_AAD: &[u8] = b"threshold";
16241627
const DECRYPTION_ROUND: u64 = 42;
16251628
const TEST_EPOCH: u64 = 42;
16261629
const TEST_CHAIN_ID: u64 = 0;
@@ -1800,7 +1803,7 @@ mod tests {
18001803

18011804
// Test threshold encryption/decryption process
18021805
let sample_plaintext = Plaintext::new(b"fox jumps over the lazy dog".to_vec());
1803-
let threshold_aad = THRESHOLD_AAD.to_vec();
1806+
let threshold_aad = THRES_AAD.to_vec();
18041807
let ciphertext =
18051808
DecryptionScheme::encrypt(&mut rng, expected_pubkey, &sample_plaintext, &threshold_aad)
18061809
.expect("encryption should succeed");
@@ -2198,7 +2201,6 @@ mod tests {
21982201
) -> InclusionList {
21992202
let previous_round = Round::new(round - 1, committee.id());
22002203
let evidence = create_round_evidence(committee, signature_keys, previous_round);
2201-
let empty_aad = vec![];
22022204

22032205
// Encrypt both message types
22042206
let priority_plaintext = Plaintext::new(priority_message.to_vec());
@@ -2208,15 +2210,15 @@ mod tests {
22082210
&mut test_rng(),
22092211
encryption_key,
22102212
&priority_plaintext,
2211-
&empty_aad,
2213+
&THRES_AAD.to_vec(),
22122214
)
22132215
.expect("Priority transaction encryption should succeed");
22142216

22152217
let regular_ciphertext = DecryptionScheme::encrypt(
22162218
&mut test_rng(),
22172219
encryption_key,
22182220
&regular_plaintext,
2219-
&empty_aad,
2221+
&THRES_AAD.to_vec(),
22202222
)
22212223
.expect("Regular transaction encryption should succeed");
22222224

timeboost-types/src/decryption.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,10 +166,11 @@ impl DecryptionKeyCell {
166166

167167
pub async fn read(&self) -> DecryptionKey {
168168
loop {
169+
let fut = self.notify.notified();
169170
if let Some(k) = self.get() {
170171
return k;
171172
}
172-
self.notify.notified().await;
173+
fut.await;
173174
}
174175
}
175176
}

timeboost-utils/src/load_generation.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@ pub fn make_bundle(key: &ThresholdEncKey) -> anyhow::Result<BundleVariant> {
2222
// encrypt bundle
2323
let data = bundle.data();
2424
let plaintext = Plaintext::new(data.to_vec());
25-
let ciphertext = DecryptionScheme::encrypt(&mut rng, key, &plaintext, &vec![])?;
25+
let aad = b"threshold".to_vec();
26+
let ciphertext = DecryptionScheme::encrypt(&mut rng, key, &plaintext, &aad)?;
2627
let encoded = serialize(&ciphertext)?;
2728
bundle.set_encrypted_data(encoded.into());
2829
}

0 commit comments

Comments
 (0)