Skip to content

Commit cd6cc58

Browse files
committed
chore: rework keygen config
1 parent 2152ebf commit cd6cc58

File tree

9 files changed

+313
-165
lines changed

9 files changed

+313
-165
lines changed

core-client/src/keygen.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,8 @@ pub(crate) async fn do_keygen(
4747
cc_conf.num_majority
4848
};
4949

50-
//NOTE: If we do not use dummy_domain here, then
51-
//this needs changing too in the KeyGenResult command.
50+
// NOTE: If we do not use dummy_domain here, then
51+
// this needs changing too in the KeyGenResult command.
5252
let keyset_config = if shared_config.compressed || shared_config.keyset_type.is_some() {
5353
Some(kms_grpc::kms::v1::KeySetConfig {
5454
keyset_type: shared_config
@@ -58,7 +58,7 @@ pub(crate) async fn do_keygen(
5858
.unwrap_or(kms_grpc::kms::v1::KeySetType::Standard as i32),
5959
standard_keyset_config: Some(kms_grpc::kms::v1::StandardKeySetConfig {
6060
compute_key_type: 0, // CPU
61-
secret_key_config: 0, // Generate
61+
secret_key_config: 0, // Generate all secret keys
6262
compressed_key_config: if shared_config.compressed {
6363
kms_grpc::kms::v1::CompressedKeyConfig::CompressedAll.into()
6464
} else {

core/grpc/proto/kms.v1.proto

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -46,17 +46,24 @@ enum ComputeKeyType {
4646

4747
message KeySetAddedInfo {
4848
// Must be set if KeyGenSecretKeyConfig::UseExistingCompressionSecretKey is used
49-
RequestId compression_keyset_id = 1;
49+
RequestId existing_compression_keyset_id = 1;
50+
51+
// Can be set if KeyGenSecretKeyConfig::UseExistingCompressionSecretKey is used,
52+
// if it's not set then the epoch ID from the KeyGenRequest is used.
53+
RequestId compression_epoch_id = 2;
5054

5155
// Must be set if KeySetType::DecompressionOnly is used
52-
RequestId from_keyset_id_decompression_only = 2;
56+
RequestId from_keyset_id_decompression_only = 3;
5357

5458
// Must be set if KeySetType::DecompressionOnly is used
55-
RequestId to_keyset_id_decompression_only = 3;
59+
RequestId to_keyset_id_decompression_only = 4;
5660

5761
// Must be set if KeyGenSecretKeyConfig::UseExisting is used
58-
RequestId existing_keyset_id = 4;
59-
RequestId existing_epoch_id = 5;
62+
RequestId existing_keyset_id = 5;
63+
64+
// Can be set if KeyGenSecretKeyConfig::UseExisting is used,
65+
// if it's not set then the epoch ID from the KeyGenRequest is used.
66+
RequestId existing_epoch_id = 6;
6067
}
6168

6269
// The keyset configuration message.
@@ -111,9 +118,16 @@ message PartialKeyGenPreprocRequest {
111118
}
112119

113120
enum KeyGenSecretKeyConfig {
114-
// The default must be represented by 0.
121+
// The default must be represented by 0, which is to generate all the secret keys.
115122
GenerateAll = 0;
123+
124+
// Use existing secret shares to generate the keyset, the key ID and epoch ID
125+
// that points to the shares must be given by KeySetAddedInfo.
116126
UseExisting = 1;
127+
128+
// Use the secret share from an existing compression secret key,
129+
// but generate the other shares. The share of the existing compresssion secret key
130+
// must be given by KeySetAddedInfo.
117131
UseExistingCompressionSecretKey = 2;
118132
}
119133

@@ -178,7 +192,8 @@ message KeyGenRequest {
178192
// See https://github.com/zama-ai/kms-internal/issues/2530
179193
RequestId context_id = 7;
180194

181-
// The epoch number placeholder (zama-ai/kms-internal#2743).
195+
// The epoch ID for the key generation, i.e., the shares produced
196+
// under this keygen will be stored and registered under this epoch.
182197
RequestId epoch_id = 8;
183198
}
184199

core/service/src/client/tests/common.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,8 @@ pub(crate) fn compressed_from_existing_keygen_config(
5959
}),
6060
}),
6161
Some(KeySetAddedInfo {
62-
compression_keyset_id: None,
62+
existing_compression_keyset_id: None,
63+
compression_epoch_id: None,
6364
from_keyset_id_decompression_only: None,
6465
to_keyset_id_decompression_only: None,
6566
existing_keyset_id: Some((*existing_keyset_id).into()),
@@ -80,7 +81,8 @@ pub(crate) fn decompression_keygen_config(
8081
standard_keyset_config: None,
8182
}),
8283
Some(KeySetAddedInfo {
83-
compression_keyset_id: None,
84+
existing_compression_keyset_id: None,
85+
compression_epoch_id: None,
8486
from_keyset_id_decompression_only: Some((*from_keyset_id).into()),
8587
to_keyset_id_decompression_only: Some((*to_keyset_id).into()),
8688
existing_keyset_id: None,

core/service/src/client/tests/threshold/key_gen_tests_isolated.rs

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -391,15 +391,10 @@ async fn secure_threshold_keygen_crash_preprocessing_isolated() -> Result<()> {
391391
/// gRPC service layer.
392392
///
393393
/// **Workflow:**
394-
/// 1. Standard keygen (preprocessing + online) to produce secret shares
395-
/// 2. Preprocessing for compressed keygen from existing
394+
/// 1. Standard keygen (preprocessing + online) to produce the first keyset
395+
/// 2. Preprocessing for compressed keygen from existing shares
396396
/// 3. Compressed keygen from existing shares
397-
/// 4. Verify both keygens completed on all parties
398-
///
399-
/// **Requires:**
400-
/// - `slow_tests` feature flag
401-
///
402-
/// **Run with:** `cargo test --lib --features slow_tests,testing secure_threshold_compressed_keygen_from_existing_isolated`
397+
/// 4. Verify both keygens completed on all parties using ddec
403398
#[tokio::test]
404399
#[cfg(feature = "slow_tests")]
405400
async fn secure_threshold_compressed_keygen_from_existing_isolated() -> Result<()> {
@@ -559,13 +554,8 @@ async fn secure_threshold_compressed_keygen_from_existing_isolated() -> Result<(
559554
/// 3. Generate decompression key from keyset 1 to keyset 2 (secure mode with preprocessing)
560555
/// 4. Verify all keys generated successfully
561556
/// 5. Perform public decryption to validate keys are functional
562-
///
563-
/// **Requires:**
564-
/// - `slow_tests` and `insecure` feature flags (PRSS generation at runtime)
565-
///
566-
/// **Run with:** `cargo test --lib --features slow_tests,testing,insecure test_insecure_threshold_decompression_keygen_isolated`
567557
#[tokio::test]
568-
#[cfg(all(feature = "slow_tests", feature = "insecure"))]
558+
#[cfg(feature = "slow_tests")]
569559
async fn test_insecure_threshold_decompression_keygen_isolated() -> Result<()> {
570560
use crate::client::tests::threshold::public_decryption_tests::run_decryption_threshold;
571561
use crate::consts::PUBLIC_STORAGE_PREFIX_THRESHOLD_ALL;
@@ -650,7 +640,8 @@ async fn test_insecure_threshold_decompression_keygen_isolated() -> Result<()> {
650640
standard_keyset_config: None,
651641
}),
652642
keyset_added_info: Some(KeySetAddedInfo {
653-
compression_keyset_id: None,
643+
existing_compression_keyset_id: None,
644+
compression_epoch_id: None,
654645
from_keyset_id_decompression_only: Some(key_id_1.into()),
655646
to_keyset_id_decompression_only: Some(key_id_2.into()),
656647
existing_keyset_id: None,

core/service/src/engine/centralized/central_kms.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -334,7 +334,7 @@ pub fn generate_fhe_keys(
334334
}
335335
}
336336
KeyGenSecretKeyConfig::UseExisting => {
337-
todo!()
337+
anyhow::bail!("This is not implemented yet")
338338
}
339339
};
340340

core/service/src/engine/centralized/service/key_gen.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -294,7 +294,7 @@ pub(crate) async fn key_gen_background<
294294
}
295295
match internal_keyset_config.keyset_config() {
296296
KeySetConfig::Standard(standard_key_set_config) => {
297-
let compression_id = match internal_keyset_config.get_compression_id() {
297+
let compression_id = match internal_keyset_config.get_existing_compression_key_id() {
298298
Ok(compression_id) => compression_id,
299299
Err(e) => {
300300
let _ = update_err_req_in_meta_store(

0 commit comments

Comments
 (0)