From 940b6508431cf9110dfc0613ea3810aa22b8f378 Mon Sep 17 00:00:00 2001 From: Jesse Abramowitz Date: Thu, 3 Oct 2024 15:08:27 -0400 Subject: [PATCH] update --- crates/client/entropy_metadata.scale | Bin 208976 -> 209745 bytes crates/shared/src/types.rs | 2 +- .../src/validator/api.rs | 42 +++++++++++------- pallets/propagation/src/lib.rs | 2 +- pallets/staking/src/lib.rs | 12 ++--- pallets/staking/src/tests.rs | 2 +- 6 files changed, 36 insertions(+), 24 deletions(-) diff --git a/crates/client/entropy_metadata.scale b/crates/client/entropy_metadata.scale index d6d04ba7e8d3ffb04850718250248c8224e0d25a..fc8ad56a388d91257356f7f5260314e9a5d266de 100644 GIT binary patch delta 5489 zcmai24_H-Iw%===1NR)bCuc3))oR^i~Jg2wLxj16J_r32s_wIA{ z*=z0f_qW$NCqA?H{HHy%TK79g_O*wOy&lHyzV>=qzcbJ8*L{Ac-{o=7t<=j_6$SKw zUM>p(nZ+|^fZq0d_ zrB-J0Y(6nA?fKhpTwakp$*tdex6f7K*1f*70GZ45vYF;DFn!i6(F{)|KY!|}?EX+8 zWTh>X8tWi^a{LmOF5nZOBrVq6kFMG`l!AEu7xwk!3HP;I7_82$eKD3Dlg%+VlWiqP2UvH z5@Nulu}2O_f~T1wKcBPMoDYo`=Pf!aJr1Mb0^PR}66nPJFdHsX)JAaez*8NuV1wz! z&Z?@~nRA>~PIsBkY{5qBHbOkzwFz#+5E~uX1b3loqp$~{5FGT+2jCiJmbe+l&=U{9 z-B(PF1C^SZAZvVtEhul4?XtWPHdEWkzlbQlL4I-!?eyEt>?-Gj5JRC4!u;4|Yu$kK zxkwFCoDUW0w&o3AB^c`-gt8FY)&%ou+%KRFvuw>JbCM{d8zK&GhwTX2=JxY2=STDQ zTyx7jo5-^%(!w1?I|7XekjiUJ)fc4!?n=^ycI67%Zo| zpMY{Gp<_?L4b<~A#8KZ~7)#ktLJT;K+n$7r2s+*RG;9G^kjvK|h=yv4+Xa71sjz4sHJ_aFcIr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;y%E4w z(4&U^8cP8BsA4ZxiUWp=)M3Lp>Vkb(1~5WxA~XUw{kG@vl+5r~)?gf~RbRs*;?#+? zNC5HF{36~%gJzIgDoHKZBjx8FA{FBiL$yRC@L} z-fKuRN`mwOb-#pBbon?NlR+sb(8fOmkDkC3$W*IO;Nv1>sS$7B2xMQ5{T*(SS8H59 zx38dz0LIeGzr!u;lu;_~;_JpsDrSOP{aVEfz*XUoZ?U<2&3GG~z%lTPlZ;e}`u<7W zicqR9XvQeyV90L4ne4r%T5uK*CtL6#zCy^Y=!a@5YsF_cBjtDT9PC%S-o^dEkZ(PW zA98XmYQyVrM!n|`XfSd#&1vWCJx}Y~ah=#@>{eUa@x2iC|IUxOg!WSX$1J#?{`N86 z(&FsKIlK=CjOyg`xDENQujT?5vIzR%0xsaPD__JE(_Uk|EOC;XL!bx*4#cdBIEE1} zyojeERZZ%|UWwy!>=m3SX306~k}DWM2IKNI#>7cWx^XUpu(KQQg|+HC-RNOV)Ty6h zs2Ecq&k#)6?!saSzUAOs04XG~NL}$6PL{Al4(vE(rrp=M4wS0ub=(O2voz)gW-v&3 zH(1#!diDmkFjf!sap+a6XZp}R4ECzCzQZ#ie5tw(Vm*UZhvMTLka40I1AI+MmBgFS zt%zo3&@KiKMTo08Y1H}%@gA-HUl=AHhY)&dxR}CV zwGJ0+AVSSGiKjSXY5YiWoXM@IdFi8@85*XMWUyZxm} zO5)@o1^+?ix>A*$(}JrYKc|+nZ&(iulj{eT!9?F3+!T# z#GZ+d7t5s@MLJE_, + 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" );