Skip to content

Commit 12ade05

Browse files
authored
feat: CRP-2618 Allow zero pre_signatures_to_create_in_advance in vetKD ChainKeyConfig (#5014)
VetKd does not use pre-signatures, and the corresponding config parameter is ignored. This PR adapts a registry invariant to allow chain keys that do not require pre-signatures to be configured with zero pre-signatures to create in advance. Once this change is rolled out to the mainnet registry, we can update system tests to configure vetKD keys with zero pre-signatures.
1 parent ebd5875 commit 12ade05

File tree

7 files changed

+63
-12
lines changed

7 files changed

+63
-12
lines changed

rs/consensus/dkg/src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1575,7 +1575,7 @@ mod tests {
15751575
.with_chain_key_config(ChainKeyConfig {
15761576
key_configs: vec![KeyConfig {
15771577
key_id: MasterPublicKeyId::VetKd(key_id.clone()),
1578-
pre_signatures_to_create_in_advance: 20,
1578+
pre_signatures_to_create_in_advance: 0,
15791579
max_queue_size: 20,
15801580
}],
15811581
signature_request_timeout_ns: None,
@@ -2066,7 +2066,7 @@ mod tests {
20662066
ChainKeyConfig {
20672067
key_configs: vec![KeyConfig {
20682068
key_id: MasterPublicKeyId::VetKd(test_vet_key()),
2069-
pre_signatures_to_create_in_advance: 20,
2069+
pre_signatures_to_create_in_advance: 0,
20702070
max_queue_size: 20,
20712071
}],
20722072
signature_request_timeout_ns: None,

rs/consensus/dkg/src/utils.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -197,15 +197,15 @@ mod tests {
197197
curve: VetKdCurve::Bls12_381_G2,
198198
name: String::from("first_vet_kd_key"),
199199
}),
200-
pre_signatures_to_create_in_advance: 50,
200+
pre_signatures_to_create_in_advance: 0,
201201
max_queue_size: 50,
202202
},
203203
KeyConfig {
204204
key_id: MasterPublicKeyId::VetKd(VetKdKeyId {
205205
curve: VetKdCurve::Bls12_381_G2,
206206
name: String::from("second_vet_kd_key"),
207207
}),
208-
pre_signatures_to_create_in_advance: 50,
208+
pre_signatures_to_create_in_advance: 0,
209209
max_queue_size: 50,
210210
},
211211
],

rs/consensus/tests/framework/mod.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,11 @@ pub fn setup_subnet<R: Rng + CryptoRng>(
7070
.iter()
7171
.map(|key_id| KeyConfig {
7272
key_id: key_id.clone(),
73-
pre_signatures_to_create_in_advance: 4,
73+
pre_signatures_to_create_in_advance: if key_id.requires_pre_signatures() {
74+
4
75+
} else {
76+
0
77+
},
7478
max_queue_size: 40,
7579
})
7680
.collect(),

rs/consensus/vetkd/src/test_utils.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,14 +87,14 @@ pub(super) fn make_chain_key_config() -> ChainKeyConfig {
8787
};
8888
let key_config_1 = KeyConfig {
8989
key_id: MasterPublicKeyId::VetKd(VetKdKeyId::from_str("bls12_381_g2:some_key").unwrap()),
90-
pre_signatures_to_create_in_advance: 1,
90+
pre_signatures_to_create_in_advance: 0,
9191
max_queue_size: 3,
9292
};
9393
let key_config_2 = KeyConfig {
9494
key_id: MasterPublicKeyId::VetKd(
9595
VetKdKeyId::from_str("bls12_381_g2:some_other_key").unwrap(),
9696
),
97-
pre_signatures_to_create_in_advance: 1,
97+
pre_signatures_to_create_in_advance: 0,
9898
max_queue_size: 3,
9999
};
100100

rs/registry/canister/src/invariants/crypto.rs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -294,16 +294,19 @@ fn check_chain_key_configs(snapshot: &RegistrySnapshot) -> Result<(), InvariantC
294294

295295
let mut key_ids = BTreeSet::new();
296296
for key_config in chain_key_config.key_configs {
297-
if key_config.pre_signatures_to_create_in_advance == 0 {
297+
let key_id = key_config.key_id.clone();
298+
if key_config.pre_signatures_to_create_in_advance == 0
299+
&& key_id.requires_pre_signatures()
300+
{
298301
return Err(InvariantCheckError {
299302
msg: format!(
300-
"`pre_signatures_to_create_in_advance` of subnet {:} cannot be zero.",
301-
subnet_id,
303+
"`pre_signatures_to_create_in_advance` for key {} of subnet {:} cannot be zero.",
304+
key_id, subnet_id,
302305
),
303306
source: None,
304307
});
305308
}
306-
if !key_ids.insert(key_config.key_id.clone()) {
309+
if !key_ids.insert(key_id) {
307310
return Err(InvariantCheckError {
308311
msg: format!(
309312
"ChainKeyConfig of subnet {:} contains multiple entries for key ID {}.",

rs/registry/canister/src/invariants/crypto/tests.rs

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -642,6 +642,16 @@ mod chain_key_enabled_subnet_lists {
642642
pre_signatures_to_create_in_advance: Some(456),
643643
max_queue_size: Some(100),
644644
},
645+
KeyConfigPb {
646+
key_id: Some(MasterPublicKeyIdPb {
647+
key_id: Some(master_public_key_id::KeyId::Vetkd(pb::VetKdKeyId {
648+
curve: 1,
649+
name: "vetkd_key".to_string(),
650+
})),
651+
}),
652+
pre_signatures_to_create_in_advance: Some(0),
653+
max_queue_size: Some(100),
654+
},
645655
],
646656
signature_request_timeout_ns: Some(10_000),
647657
idkg_key_rotation_period_ms: Some(20_000),
@@ -680,7 +690,7 @@ mod chain_key_enabled_subnet_lists {
680690

681691
#[test]
682692
#[should_panic(
683-
expected = "`pre_signatures_to_create_in_advance` of subnet ya35z-hhham-aaaaa-aaaap-yai cannot be zero."
693+
expected = "`pre_signatures_to_create_in_advance` for key ecdsa:Secp256k1:ecdsa_key of subnet ya35z-hhham-aaaaa-aaaap-yai cannot be zero."
684694
)]
685695
fn should_fail_if_pre_signatures_is_zero() {
686696
let mut config = invariant_compliant_chain_key_config();
@@ -730,6 +740,19 @@ mod chain_key_enabled_subnet_lists {
730740
check_chain_key_config_invariant(config);
731741
}
732742

743+
#[test]
744+
#[should_panic(expected = "Unable to convert 2 to a VetKdCurve")]
745+
fn should_fail_if_unkown_vetkd_curve() {
746+
let mut config = invariant_compliant_chain_key_config();
747+
config.key_configs[1].key_id = Some(MasterPublicKeyIdPb {
748+
key_id: Some(master_public_key_id::KeyId::Vetkd(pb::VetKdKeyId {
749+
curve: 2,
750+
name: "vetkd_key".to_string(),
751+
})),
752+
});
753+
check_chain_key_config_invariant(config);
754+
}
755+
733756
#[test]
734757
#[should_panic(expected = "Unable to convert Unspecified to an EcdsaCurve")]
735758
fn should_fail_if_unspecified_ecdsa_curve() {
@@ -756,6 +779,19 @@ mod chain_key_enabled_subnet_lists {
756779
check_chain_key_config_invariant(config);
757780
}
758781

782+
#[test]
783+
#[should_panic(expected = "Unable to convert Unspecified to a VetKdCurve")]
784+
fn should_fail_if_unspecified_vetkd_curve() {
785+
let mut config = invariant_compliant_chain_key_config();
786+
config.key_configs[1].key_id = Some(MasterPublicKeyIdPb {
787+
key_id: Some(master_public_key_id::KeyId::Vetkd(pb::VetKdKeyId {
788+
curve: 0,
789+
name: "vetkd_key".to_string(),
790+
})),
791+
});
792+
check_chain_key_config_invariant(config);
793+
}
794+
759795
#[test]
760796
#[should_panic(
761797
expected = "ChainKeyConfig of subnet ya35z-hhham-aaaaa-aaaap-yai contains multiple entries for key ID schnorr:Bip340Secp256k1:schnorr_key."

rs/types/management_canister_types/src/lib.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2578,6 +2578,14 @@ impl MasterPublicKeyId {
25782578
Self::VetKd(_) => false,
25792579
}
25802580
}
2581+
2582+
/// Check whether this type of [`MasterPublicKeyId`] requires pre-signatures
2583+
pub fn requires_pre_signatures(&self) -> bool {
2584+
match self {
2585+
Self::Ecdsa(_) | Self::Schnorr(_) => true,
2586+
Self::VetKd(_) => false,
2587+
}
2588+
}
25812589
}
25822590

25832591
impl FromStr for MasterPublicKeyId {

0 commit comments

Comments
 (0)