@@ -30,6 +30,8 @@ use crate::config::DecrypterConfig;
30
30
use crate :: metrics:: SequencerMetrics ;
31
31
32
32
const DKG_AAD : & [ u8 ] = b"dkg" ;
33
+ const THRES_AAD : & [ u8 ] = b"threshold" ;
34
+
33
35
type Result < T > = StdResult < T , DecrypterError > ;
34
36
type DecShare = <DecryptionScheme as ThresholdEncScheme >:: DecShare ;
35
37
type Ciphertext = <DecryptionScheme as ThresholdEncScheme >:: Ciphertext ;
@@ -53,7 +55,7 @@ enum Protocol {
53
55
54
56
/// Command sent to Decrypter's background Worker
55
57
enum Command {
56
- /// Inform the Worker of a dkg bundle.
58
+ /// Inform the Worker of a DKG bundle.
57
59
Dkg ( DkgBundle ) ,
58
60
/// Decrypt all encrypted transactions in the inclusion list.
59
61
Decrypt ( ( InclusionList , bool ) ) ,
@@ -69,7 +71,7 @@ enum Command {
69
71
/// collectively threshold-decrypt encrypted transactions in the inclusion list during the 2nd phase
70
72
/// ("Decryption phase") of timeboost.
71
73
///
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.
73
75
///
74
76
/// In timeboost protocol, a decrypter does both the share "decryption" (using its decryption key
75
77
/// share), and combiner's "hatching" (using the combiner key).
@@ -94,7 +96,7 @@ pub struct Decrypter {
94
96
worker_rx : Receiver < InclusionList > ,
95
97
/// Worker task handle.
96
98
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.
98
100
submitted : BTreeSet < CommitteeId > ,
99
101
/// Pending threshold encryption key material
100
102
enc_key : DecryptionKeyCell ,
@@ -228,7 +230,7 @@ impl Decrypter {
228
230
Ok ( ( ) )
229
231
}
230
232
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.
232
234
///
233
235
/// # Returns
234
236
/// - `Some(DkgBundle)` if a new dealing was successfully created for the current committee.
@@ -385,12 +387,12 @@ enum WorkerState {
385
387
AwaitingHandover ( HashMap < PublicKey , ResharingSubset > ) ,
386
388
/// Received enough resharing messages to complete the handover.
387
389
HandoverComplete ( DecryptionKey ) ,
388
- /// Expects to obtain the initial dkg key through dkg bundles.
390
+ /// Expects to obtain the initial DKG key through DKG bundles.
389
391
///
390
- /// Upon startup the Worker requests dkg messages from remote nodes
392
+ /// Upon startup the Worker requests DKG messages from remote nodes
391
393
/// such that, if the local node is behind, it will catchup immediately.
392
394
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.
394
396
ResharingPending ( DecryptionKey ) ,
395
397
/// Obtained keys for both the current and next committee.
396
398
ResharingComplete ( DecryptionKey , DecryptionKey ) ,
@@ -428,13 +430,13 @@ struct Worker {
428
430
/// Channel for receiving commands from the parent.
429
431
rx : Receiver < Command > ,
430
432
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.
432
434
enc_key : DecryptionKeyCell ,
433
435
434
436
/// First round where an inclusion list was received (ignore shares for earlier rounds).
435
437
first_requested_round : Option < RoundNumber > ,
436
438
437
- /// Decryption key used for communication between nodes for dkg and resharing.
439
+ /// Decryption key used for communication between nodes for DKG and resharing.
438
440
dkg_sk : LabeledDkgDecKey ,
439
441
440
442
/// Key material for committee members (shared with Decrypter)
@@ -446,7 +448,7 @@ struct Worker {
446
448
/// Number of rounds to retain.
447
449
retain : usize ,
448
450
449
- /// Tracker for dkg bundles received through candidate lists.
451
+ /// Tracker for DKG bundles received through candidate lists.
450
452
#[ builder( default ) ]
451
453
dkg_tracker : BTreeMap < CommitteeId , DkgAccumulator > ,
452
454
@@ -637,7 +639,7 @@ impl Worker {
637
639
Ok ( false )
638
640
}
639
641
640
- /// A request for dkg subset has been received.
642
+ /// A request for DKG subset has been received.
641
643
async fn on_dkg_request_msg (
642
644
& mut self ,
643
645
src : PublicKey ,
@@ -682,7 +684,7 @@ impl Worker {
682
684
Ok ( ( ) )
683
685
}
684
686
685
- /// A response for dkg subset has been received.
687
+ /// A response for DKG subset has been received.
686
688
async fn on_dkg_response_msg ( & mut self , src : PublicKey , res : SubsetResponse ) -> Result < ( ) > {
687
689
trace ! ( node = %self . label, from=%src, %res. committee_id, "received dkg response" ) ;
688
690
if res. committee_id != self . current {
@@ -1051,7 +1053,7 @@ impl Worker {
1051
1053
Ok ( ( ) )
1052
1054
}
1053
1055
1054
- /// Catch up by requesting dkg subsets from remote nodes.
1056
+ /// Catch up by requesting DKG subsets from remote nodes.
1055
1057
async fn dkg_catchup ( & mut self ) -> Result < ( ) > {
1056
1058
let req = Protocol :: DkgRequest ( self . current ) ;
1057
1059
// the round number is ignored by the recieving party, but we don't want to give an
@@ -1131,7 +1133,7 @@ impl Worker {
1131
1133
<DecryptionScheme as ThresholdEncScheme >:: decrypt (
1132
1134
dec_sk. privkey ( ) ,
1133
1135
& ct,
1134
- & vec ! [ ] ,
1136
+ & THRES_AAD . to_vec ( ) ,
1135
1137
)
1136
1138
. ok ( ) // decryption failure result in None
1137
1139
} )
@@ -1270,13 +1272,12 @@ impl Worker {
1270
1272
}
1271
1273
1272
1274
if let Some ( ct) = opt_ct {
1273
- let aad = vec ! [ ] ;
1274
1275
match DecryptionScheme :: combine (
1275
1276
key_store. committee ( ) ,
1276
1277
dec_sk. combkey ( ) ,
1277
1278
dec_shares,
1278
1279
& ct,
1279
- & aad ,
1280
+ & THRES_AAD . to_vec ( ) ,
1280
1281
) {
1281
1282
Ok ( pt) => decrypted. push ( Some ( pt) ) ,
1282
1283
// with f+1 decryption shares, which means ciphertext is valid, we just need to
@@ -1476,7 +1477,7 @@ impl DecShareBatch {
1476
1477
}
1477
1478
}
1478
1479
1479
- /// A response with the agreed-upon subset of dkg bundles.
1480
+ /// A response with the agreed-upon subset of DKG bundles.
1480
1481
#[ derive( Clone , Debug , Serialize , Deserialize ) ]
1481
1482
struct SubsetResponse {
1482
1483
committee_id : CommitteeId ,
@@ -1566,7 +1567,7 @@ pub enum DecrypterError {
1566
1567
#[ error( "unknown key: {0}" ) ]
1567
1568
UnknownKey ( PublicKey ) ,
1568
1569
1569
- #[ error( "DKG /resharing not yet complete" ) ]
1570
+ #[ error( "dkg /resharing not yet complete" ) ]
1570
1571
DkgPending ,
1571
1572
1572
1573
#[ error( "dkg err: {0}" ) ]
@@ -1615,12 +1616,14 @@ mod tests {
1615
1616
PriorityBundle , SeqNo , Signer , Timestamp ,
1616
1617
} ;
1617
1618
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
+ } ;
1619
1624
1620
1625
// Test constants
1621
1626
const COMMITTEE_SIZE : usize = 5 ;
1622
- const DKG_AAD : & [ u8 ] = b"dkg" ;
1623
- const THRESHOLD_AAD : & [ u8 ] = b"threshold" ;
1624
1627
const DECRYPTION_ROUND : u64 = 42 ;
1625
1628
const TEST_EPOCH : u64 = 42 ;
1626
1629
const TEST_CHAIN_ID : u64 = 0 ;
@@ -1800,7 +1803,7 @@ mod tests {
1800
1803
1801
1804
// Test threshold encryption/decryption process
1802
1805
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 ( ) ;
1804
1807
let ciphertext =
1805
1808
DecryptionScheme :: encrypt ( & mut rng, expected_pubkey, & sample_plaintext, & threshold_aad)
1806
1809
. expect ( "encryption should succeed" ) ;
@@ -2198,7 +2201,6 @@ mod tests {
2198
2201
) -> InclusionList {
2199
2202
let previous_round = Round :: new ( round - 1 , committee. id ( ) ) ;
2200
2203
let evidence = create_round_evidence ( committee, signature_keys, previous_round) ;
2201
- let empty_aad = vec ! [ ] ;
2202
2204
2203
2205
// Encrypt both message types
2204
2206
let priority_plaintext = Plaintext :: new ( priority_message. to_vec ( ) ) ;
@@ -2208,15 +2210,15 @@ mod tests {
2208
2210
& mut test_rng ( ) ,
2209
2211
encryption_key,
2210
2212
& priority_plaintext,
2211
- & empty_aad ,
2213
+ & THRES_AAD . to_vec ( ) ,
2212
2214
)
2213
2215
. expect ( "Priority transaction encryption should succeed" ) ;
2214
2216
2215
2217
let regular_ciphertext = DecryptionScheme :: encrypt (
2216
2218
& mut test_rng ( ) ,
2217
2219
encryption_key,
2218
2220
& regular_plaintext,
2219
- & empty_aad ,
2221
+ & THRES_AAD . to_vec ( ) ,
2220
2222
)
2221
2223
. expect ( "Regular transaction encryption should succeed" ) ;
2222
2224
0 commit comments