diff --git a/crates/client/entropy_metadata.scale b/crates/client/entropy_metadata.scale index d6d04ba7e..fc8ad56a3 100644 Binary files a/crates/client/entropy_metadata.scale and b/crates/client/entropy_metadata.scale differ diff --git a/crates/shared/src/types.rs b/crates/shared/src/types.rs index c96910380..b67ce04bf 100644 --- a/crates/shared/src/types.rs +++ b/crates/shared/src/types.rs @@ -56,7 +56,7 @@ pub struct OcwMessageDkg { #[derive(Clone, Encode, Decode, Debug, Eq, PartialEq, TypeInfo)] pub struct OcwMessageReshare { // Stash address of new signer - pub new_signer: Vec, + pub new_signers: Vec>, pub block_number: BlockNumber, } diff --git a/crates/threshold-signature-server/src/validator/api.rs b/crates/threshold-signature-server/src/validator/api.rs index fa7a8f880..4bcb47535 100644 --- a/crates/threshold-signature-server/src/validator/api.rs +++ b/crates/threshold-signature-server/src/validator/api.rs @@ -28,6 +28,7 @@ use crate::{ AppState, }; use axum::{body::Bytes, extract::State, http::StatusCode}; +use blake2::{Blake2s256, Digest}; use entropy_kvdb::kv_manager::{helpers::serialize as key_serialize, KvManager}; pub use entropy_protocol::{ decode_verifying_key, @@ -106,7 +107,7 @@ pub async fn new_reshare( .map_err(|e| ValidatorErr::UserError(e.to_string()))?; let old_holder: Option> = - if data.new_signer == my_stash_address.encode() { + if data.new_signers.contains(&my_stash_address.encode()) { None } else { let kvdb_result = app_state.kv_store.kv().get(&hex::encode(NETWORK_PARENT_KEY)).await?; @@ -120,7 +121,7 @@ pub async fn new_reshare( validators_info.iter().cloned().map(|x| PartyId::new(x.tss_account)).collect(); let pruned_old_holders = - prune_old_holders(&api, &rpc, data.new_signer, validators_info.clone()).await?; + prune_old_holders(&api, &rpc, data.new_signers, validators_info.clone()).await?; let old_holders: BTreeSet = pruned_old_holders.into_iter().map(|x| PartyId::new(x.tss_account)).collect(); @@ -273,7 +274,14 @@ pub async fn validate_new_reshare( .await? .ok_or_else(|| ValidatorErr::ChainFetch("Not Currently in a reshare"))?; - if reshare_data.new_signer != chain_data.new_signer + let mut hasher_chain_data = Blake2s256::new(); + hasher_chain_data.update(chain_data.new_signers.encode()); + let chain_data_hash = hasher_chain_data.finalize(); + let mut hasher_verifying_data = Blake2s256::new(); + hasher_verifying_data.update(reshare_data.new_signers.encode()); + let verifying_data_hash = hasher_verifying_data.finalize(); + + if verifying_data_hash != chain_data_hash || chain_data.block_number != reshare_data.block_number { return Err(ValidatorErr::InvalidData); @@ -365,20 +373,24 @@ pub fn check_forbidden_key(key: &str) -> Result<(), ValidatorErr> { pub async fn prune_old_holders( api: &OnlineClient, rpc: &LegacyRpcMethods, - new_signer: Vec, + new_signers: Vec>, validators_info: Vec, ) -> Result, ValidatorErr> { - Ok(if !new_signer.is_empty() { - let address_slice: &[u8; 32] = &new_signer.clone().try_into().unwrap(); - let new_signer_address = AccountId32(*address_slice); - let new_signer_info = &get_validators_info(api, rpc, vec![new_signer_address]) - .await - .map_err(|e| ValidatorErr::UserError(e.to_string()))?[0]; - validators_info - .iter() - .filter(|x| x.tss_account != new_signer_info.tss_account) - .cloned() - .collect() + Ok(if !new_signers.is_empty() { + let mut filtered_validators_info = vec![]; + for new_signer in new_signers { + let address_slice: &[u8; 32] = &new_signer.clone().try_into().unwrap(); + let new_signer_address = AccountId32(*address_slice); + let new_signer_info = &get_validators_info(api, rpc, vec![new_signer_address]) + .await + .map_err(|e| ValidatorErr::UserError(e.to_string()))?[0]; + filtered_validators_info = validators_info + .iter() + .filter(|x| x.tss_account != new_signer_info.tss_account) + .cloned() + .collect::>(); + } + filtered_validators_info } else { validators_info.clone() }) diff --git a/pallets/propagation/src/lib.rs b/pallets/propagation/src/lib.rs index e7542c891..f911de067 100644 --- a/pallets/propagation/src/lib.rs +++ b/pallets/propagation/src/lib.rs @@ -172,7 +172,7 @@ pub mod pallet { BlockNumberFor::::try_into(block_number).unwrap_or_default(); let req_body = OcwMessageReshare { - new_signer: reshare_data.new_signer, + new_signers: reshare_data.new_signers, // subtract 1 from blocknumber since the request is from the last block block_number: converted_block_number.saturating_sub(1), }; diff --git a/pallets/staking/src/lib.rs b/pallets/staking/src/lib.rs index c4eda0802..1723c2e68 100644 --- a/pallets/staking/src/lib.rs +++ b/pallets/staking/src/lib.rs @@ -129,7 +129,7 @@ pub mod pallet { #[derive(Clone, Encode, Decode, Eq, PartialEq, RuntimeDebug, TypeInfo, Default)] pub struct ReshareInfo { - pub new_signer: Vec>, + pub new_signers: Vec>, pub block_number: BlockNumber, } @@ -316,7 +316,7 @@ pub mod pallet { next_signers.push(self.mock_signer_rotate.2[0].clone()); let next_signers = next_signers.to_vec(); NextSigners::::put(NextSignerInfo { next_signers, confirmations: vec![] }); - let new_signer = self + let new_signers = self .mock_signer_rotate .clone() .2 @@ -326,7 +326,7 @@ pub mod pallet { ReshareData::::put(ReshareInfo { // To give enough time for test_reshare setup block_number: TEST_RESHARE_BLOCK_NUMBER.into(), - new_signer, + new_signers, }) } } @@ -719,7 +719,7 @@ pub mod pallet { return Ok(weight); } - let mut new_signer: Vec> = vec![]; + let mut new_signers: Vec> = vec![]; let mut count = 0u32; // removes first signer and pushes new signer to back if total signers not increased @@ -757,7 +757,7 @@ pub mod pallet { } current_signers.push(next_signer_up.clone()); - new_signer.push(next_signer_up.encode()); + new_signers.push(next_signer_up.encode()); } NextSigners::::put(NextSignerInfo { @@ -769,7 +769,7 @@ pub mod pallet { let current_block_number = >::block_number(); let reshare_info = ReshareInfo { block_number: current_block_number + sp_runtime::traits::One::one(), - new_signer, + new_signers, }; ReshareData::::put(reshare_info); diff --git a/pallets/staking/src/tests.rs b/pallets/staking/src/tests.rs index 2d888aace..a9ee6a91e 100644 --- a/pallets/staking/src/tests.rs +++ b/pallets/staking/src/tests.rs @@ -486,7 +486,7 @@ fn it_tests_new_session_handler() { "Check reshare block start at 100 + 1" ); assert_eq!( - Staking::reshare_data().new_signer, + Staking::reshare_data().new_signers, vec![1u64.encode(), 3u64.encode()], "Check reshare next signer up is 3" );