diff --git a/crates/client/entropy_metadata.scale b/crates/client/entropy_metadata.scale index 5b41ba1bf..a9c157862 100644 Binary files a/crates/client/entropy_metadata.scale and b/crates/client/entropy_metadata.scale differ diff --git a/crates/threshold-signature-server/src/user/api.rs b/crates/threshold-signature-server/src/user/api.rs index ae17834fb..9655fe0da 100644 --- a/crates/threshold-signature-server/src/user/api.rs +++ b/crates/threshold-signature-server/src/user/api.rs @@ -419,7 +419,9 @@ pub async fn confirm_registered( // TODO: Understand this better, potentially use sign_and_submit_default // or other method under sign_and_* if who.encode() == NETWORK_PARENT_KEY.encode() { - let jump_start_request = entropy::tx().registry().confirm_jump_start(); + let jump_start_request = entropy::tx().registry().confirm_jump_start( + entropy::runtime_types::bounded_collections::bounded_vec::BoundedVec(verifying_key), + ); submit_transaction(api, rpc, signer, &jump_start_request, Some(nonce)).await?; } else { let confirm_register_request = entropy::tx().registry().confirm_register( diff --git a/crates/threshold-signature-server/src/user/tests.rs b/crates/threshold-signature-server/src/user/tests.rs index 2911d19e6..908237e4a 100644 --- a/crates/threshold-signature-server/src/user/tests.rs +++ b/crates/threshold-signature-server/src/user/tests.rs @@ -800,7 +800,13 @@ async fn test_jumpstart_network() { let key_share: Option = entropy_kvdb::kv_manager::helpers::deserialize(&response_key); assert_eq!(key_share.is_some(), true); + let jump_start_progress_query = entropy::storage().registry().jump_start_progress(); + let jump_start_progress = + query_chain(&api, &rpc, jump_start_progress_query, None).await.unwrap().unwrap(); + let verifying_key = + key_share.unwrap().0.verifying_key().to_encoded_point(true).as_bytes().to_vec(); + assert_eq!(jump_start_progress.verifying_key.unwrap().0, verifying_key); clean_tests(); } diff --git a/pallets/registry/src/benchmarking.rs b/pallets/registry/src/benchmarking.rs index 5e800cbc5..12eaf5b36 100644 --- a/pallets/registry/src/benchmarking.rs +++ b/pallets/registry/src/benchmarking.rs @@ -82,6 +82,7 @@ benchmarks! { let c in 0 .. SIGNING_PARTY_SIZE as u32; let sig_req_account: T::AccountId = whitelisted_caller(); let validator_account: T::AccountId = whitelisted_caller(); + let expected_verifying_key = BoundedVec::default(); let mut accounts = vec![]; for i in 0..SIGNING_PARTY_SIZE { @@ -98,12 +99,13 @@ benchmarks! { >::put(JumpStartDetails { jump_start_status: JumpStartStatus::InProgress(0), confirmations: vec![validators[0].clone()], + verifying_key: None }); let balance = ::Currency::minimum_balance() * 100u32.into(); let _ = ::Currency::make_free_balance_be(&accounts[1], balance); - }: confirm_jump_start(RawOrigin::Signed(accounts[1].clone())) + }: confirm_jump_start(RawOrigin::Signed(accounts[1].clone()), expected_verifying_key) verify { assert_last_event::(Event::::FinishedNetworkJumpStart().into()); } @@ -113,6 +115,7 @@ benchmarks! { let sig_req_account: T::AccountId = whitelisted_caller(); let validator_account: T::AccountId = whitelisted_caller(); let threshold_account: T::AccountId = whitelisted_caller(); + let expected_verifying_key = BoundedVec::default(); // add validators and a registering user for i in 0..SIGNING_PARTY_SIZE { @@ -123,12 +126,13 @@ benchmarks! { >::put(JumpStartDetails { jump_start_status: JumpStartStatus::InProgress(0), confirmations: vec![], + verifying_key: None }); let balance = ::Currency::minimum_balance() * 100u32.into(); let _ = ::Currency::make_free_balance_be(&threshold_account, balance); - }: confirm_jump_start(RawOrigin::Signed(threshold_account.clone())) + }: confirm_jump_start(RawOrigin::Signed(threshold_account.clone()), expected_verifying_key) verify { let validator_stash = pallet_staking_extension::Pallet::::threshold_to_stash(&threshold_account).unwrap(); diff --git a/pallets/registry/src/lib.rs b/pallets/registry/src/lib.rs index 3e702d5ce..565c4a238 100644 --- a/pallets/registry/src/lib.rs +++ b/pallets/registry/src/lib.rs @@ -134,6 +134,7 @@ pub mod pallet { pub struct JumpStartDetails { pub jump_start_status: JumpStartStatus, pub confirmations: Vec, + pub verifying_key: Option, } #[pallet::genesis_config] @@ -261,6 +262,7 @@ pub mod pallet { NoProgramSet, TooManyModifiableKeys, MismatchedVerifyingKeyLength, + MismatchedVerifyingKey, NotValidator, JumpStartProgressNotReady, JumpStartNotInProgress, @@ -305,6 +307,7 @@ pub mod pallet { JumpStartProgress::::put(JumpStartDetails { jump_start_status: JumpStartStatus::InProgress(converted_block_number), confirmations: vec![], + verifying_key: None, }); Self::deposit_event(Event::StartedNetworkJumpStart()); Ok(()) @@ -316,7 +319,10 @@ pub mod pallet { ::WeightInfo::confirm_jump_start_confirm(SIGNING_PARTY_SIZE as u32) .max(::WeightInfo::confirm_jump_start_done(SIGNING_PARTY_SIZE as u32)) })] - pub fn confirm_jump_start(origin: OriginFor) -> DispatchResultWithPostInfo { + pub fn confirm_jump_start( + origin: OriginFor, + verifying_key: VerifyingKey, + ) -> DispatchResultWithPostInfo { // check is validator let ts_server_account = ensure_signed(origin)?; @@ -327,12 +333,21 @@ pub mod pallet { ensure!(validators.contains(&validator_stash), Error::::NotValidator); let mut jump_start_info = JumpStartProgress::::get(); + match jump_start_info.verifying_key { + Some(ref key) => { + ensure!(key == &verifying_key, Error::::MismatchedVerifyingKey); + }, + None => { + jump_start_info.verifying_key = Some(verifying_key); + }, + } // check in progress ensure!( matches!(jump_start_info.jump_start_status, JumpStartStatus::InProgress(_)), Error::::JumpStartNotInProgress ); + ensure!( !jump_start_info.confirmations.contains(&validator_stash), Error::::AlreadyConfirmed @@ -350,6 +365,7 @@ pub mod pallet { JumpStartProgress::::put(JumpStartDetails { jump_start_status: JumpStartStatus::Done, confirmations: vec![], + verifying_key: jump_start_info.verifying_key, }); Self::deposit_event(Event::FinishedNetworkJumpStart()); diff --git a/pallets/registry/src/tests.rs b/pallets/registry/src/tests.rs index 631d6279e..4a2def60d 100644 --- a/pallets/registry/src/tests.rs +++ b/pallets/registry/src/tests.rs @@ -91,7 +91,11 @@ fn it_jumps_the_network() { new_test_ext().execute_with(|| { assert_eq!( Registry::jump_start_progress(), - JumpStartDetails { jump_start_status: JumpStartStatus::Ready, confirmations: vec![] }, + JumpStartDetails { + jump_start_status: JumpStartStatus::Ready, + confirmations: vec![], + verifying_key: None + }, "Checks default status of jump start detail" ); assert_ok!(Registry::jump_start_network(RuntimeOrigin::signed(1))); @@ -105,6 +109,7 @@ fn it_jumps_the_network() { JumpStartDetails { jump_start_status: JumpStartStatus::InProgress(0), confirmations: vec![], + verifying_key: None }, "Checks that jump start is in progress" ); @@ -121,7 +126,8 @@ fn it_jumps_the_network() { Registry::jump_start_progress(), JumpStartDetails { jump_start_status: JumpStartStatus::InProgress(100), - confirmations: vec![] + confirmations: vec![], + verifying_key: None }, "ensures jump start is called again if too many blocks passed" ); @@ -131,44 +137,64 @@ fn it_jumps_the_network() { #[test] fn it_tests_jump_start_result() { new_test_ext().execute_with(|| { + let expected_verifying_key = BoundedVec::default(); + assert_noop!( - Registry::confirm_jump_start(RuntimeOrigin::signed(1)), + Registry::confirm_jump_start(RuntimeOrigin::signed(1), expected_verifying_key.clone()), Error::::NoThresholdKey ); pallet_staking_extension::ThresholdToStash::::insert(1, 1); pallet_staking_extension::ThresholdToStash::::insert(7, 7); assert_noop!( - Registry::confirm_jump_start(RuntimeOrigin::signed(7)), + Registry::confirm_jump_start(RuntimeOrigin::signed(7), expected_verifying_key.clone()), Error::::NotValidator ); assert_noop!( - Registry::confirm_jump_start(RuntimeOrigin::signed(1)), + Registry::confirm_jump_start(RuntimeOrigin::signed(1), expected_verifying_key.clone()), Error::::JumpStartNotInProgress ); // trigger jump start assert_ok!(Registry::jump_start_network(RuntimeOrigin::signed(1))); - assert_ok!(Registry::confirm_jump_start(RuntimeOrigin::signed(1))); + assert_ok!(Registry::confirm_jump_start( + RuntimeOrigin::signed(1), + expected_verifying_key.clone() + )); assert_eq!( Registry::jump_start_progress(), JumpStartDetails { jump_start_status: JumpStartStatus::InProgress(0), - confirmations: vec![1] + confirmations: vec![1], + verifying_key: Some(expected_verifying_key.clone()) }, "Jump start recieves a confirmation" ); assert_noop!( - Registry::confirm_jump_start(RuntimeOrigin::signed(1)), + Registry::confirm_jump_start(RuntimeOrigin::signed(1), expected_verifying_key.clone()), Error::::AlreadyConfirmed ); + let bad_verifying_key = + BoundedVec::try_from(vec![0; VERIFICATION_KEY_LENGTH as usize]).unwrap(); + assert_noop!( + Registry::confirm_jump_start(RuntimeOrigin::signed(1), bad_verifying_key.clone()), + Error::::MismatchedVerifyingKey + ); + pallet_staking_extension::ThresholdToStash::::insert(2, 2); - assert_ok!(Registry::confirm_jump_start(RuntimeOrigin::signed(2))); + assert_ok!(Registry::confirm_jump_start( + RuntimeOrigin::signed(2), + expected_verifying_key.clone() + )); assert_eq!( Registry::jump_start_progress(), - JumpStartDetails { jump_start_status: JumpStartStatus::Done, confirmations: vec![] }, + JumpStartDetails { + jump_start_status: JumpStartStatus::Done, + confirmations: vec![], + verifying_key: Some(expected_verifying_key) + }, "Jump start in done status after all confirmations" ); });