Skip to content

Commit

Permalink
Merge branch 'mirroring-leon/ecdsa_cleanup' into 'master'
Browse files Browse the repository at this point in the history
chore(github-sync): PR#282 / chore(CON13-02): Remove `make_ecdsa_signing_subnet_list_key` from the codebase

[GitHub PR 282](#282) (branch: leon/ecdsa_cleanup) 

See merge request dfinity-lab/public/ic!20135
  • Loading branch information
marko-k0 committed Jul 1, 2024
2 parents 29e5e14 + 5c588fd commit 1d669af
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 43 deletions.
61 changes: 40 additions & 21 deletions rs/consensus/tests/framework/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ pub use types::{
use ic_crypto_temp_crypto::{NodeKeysToGenerate, TempCryptoComponent, TempCryptoComponentGeneric};
use ic_crypto_test_utils_ni_dkg::{initial_dkg_transcript, InitialNiDkgConfig};
use ic_interfaces_registry::RegistryClient;
use ic_management_canister_types::{EcdsaCurve, EcdsaKeyId, MasterPublicKeyId};
use ic_management_canister_types::{
EcdsaCurve, EcdsaKeyId, MasterPublicKeyId, SchnorrAlgorithm, SchnorrKeyId,
};
use ic_protobuf::registry::subnet::v1::{CatchUpPackageContents, InitialNiDkgTranscriptRecord};
use ic_registry_client_fake::FakeRegistryClient;
use ic_registry_client_helpers::crypto::CryptoRegistry;
Expand Down Expand Up @@ -56,19 +58,33 @@ pub fn setup_subnet<R: Rng + CryptoRng>(
let registry_version = RegistryVersion::from(initial_version);
let data_provider = Arc::new(ProtoRegistryDataProvider::new());
let registry_client = Arc::new(FakeRegistryClient::new(Arc::clone(&data_provider) as Arc<_>));
let ecdsa_key_id = EcdsaKeyId {
curve: EcdsaCurve::Secp256k1,
name: "test_key".to_string(),
};

let threshold_key_ids = vec![
MasterPublicKeyId::Ecdsa(EcdsaKeyId {
curve: EcdsaCurve::Secp256k1,
name: "ecdsa_test_key".to_string(),
}),
MasterPublicKeyId::Schnorr(SchnorrKeyId {
algorithm: SchnorrAlgorithm::Ed25519,
name: "ed25519_test_key".to_string(),
}),
MasterPublicKeyId::Schnorr(SchnorrKeyId {
algorithm: SchnorrAlgorithm::Bip340Secp256k1,
name: "bip340_test_key".to_string(),
}),
];

let subnet_record = SubnetRecordBuilder::from(node_ids)
.with_dkg_interval_length(19)
.with_chain_key_config(ChainKeyConfig {
key_configs: vec![KeyConfig {
key_id: MasterPublicKeyId::Ecdsa(ecdsa_key_id.clone()),
pre_signatures_to_create_in_advance: 4,
max_queue_size: 40,
}],
key_configs: threshold_key_ids
.iter()
.map(|key_id| KeyConfig {
key_id: key_id.clone(),
pre_signatures_to_create_in_advance: 4,
max_queue_size: 40,
})
.collect(),
..ChainKeyConfig::default()
})
.build();
Expand Down Expand Up @@ -177,17 +193,20 @@ pub fn setup_subnet<R: Rng + CryptoRng>(
)
.expect("Could not add node record.");

// Add ECDSA signing subnet to registry
data_provider
.add(
&ic_registry_keys::make_ecdsa_signing_subnet_list_key(&ecdsa_key_id),
registry_version,
Some(ic_protobuf::registry::crypto::v1::EcdsaSigningSubnetList {
subnets: vec![subnet_id_into_protobuf(subnet_id)],
}),
)
.expect("Could not add ECDSA signing subnet list");

// Add threshold signing subnet to registry
for key_id in threshold_key_ids {
data_provider
.add(
&ic_registry_keys::make_chain_key_signing_subnet_list_key(&key_id),
registry_version,
Some(
ic_protobuf::registry::crypto::v1::ChainKeySigningSubnetList {
subnets: vec![subnet_id_into_protobuf(subnet_id)],
},
),
)
.expect("Could not add chain key signing subnet list");
}
registry_client.reload();
registry_client.update_to_latest_version();

Expand Down
22 changes: 0 additions & 22 deletions rs/registry/keys/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,6 @@ pub const DATA_CENTER_KEY_PREFIX: &str = "data_center_record_";
pub const ECDSA_SIGNING_SUBNET_LIST_KEY_PREFIX: &str = "key_id_";
pub const CHAIN_KEY_SIGNING_SUBNET_LIST_KEY_PREFIX: &str = "master_public_key_id_";

pub fn make_ecdsa_signing_subnet_list_key(key_id: &EcdsaKeyId) -> String {
format!("{}{}", ECDSA_SIGNING_SUBNET_LIST_KEY_PREFIX, key_id)
}

pub fn get_ecdsa_key_id_from_signing_subnet_list_key(
signing_subnet_list_key: &str,
) -> Result<EcdsaKeyId, RegistryClientError> {
Expand Down Expand Up @@ -443,24 +439,6 @@ mod tests {
assert!(parsed.is_none());
}

#[test]
fn ecdsa_signing_subnet_list_key_round_trips() {
for curve in EcdsaCurve::iter() {
for name in ["secp256k1", "", "other_key", "other key", "other:key"] {
let key_id = EcdsaKeyId {
curve,
name: name.to_string(),
};
let signing_subnet_list_key = make_ecdsa_signing_subnet_list_key(&key_id);
assert_eq!(
get_ecdsa_key_id_from_signing_subnet_list_key(&signing_subnet_list_key)
.unwrap(),
key_id
);
}
}
}

#[test]
fn ecdsa_signing_subnet_list_bad_key_id_error_message() {
let bad_key = "key_without_curve";
Expand Down

0 comments on commit 1d669af

Please sign in to comment.