From 3e6be8c8420e139c7043c5f0f2fb7fb9f6ee4fff Mon Sep 17 00:00:00 2001 From: MOZGIII Date: Thu, 12 Dec 2024 14:11:54 -0300 Subject: [PATCH 1/3] Correct the token claims validation logic CheckTokenClaim --- crates/pallet-token-claims/src/signed_ext.rs | 36 +++++++++++++------- 1 file changed, 23 insertions(+), 13 deletions(-) diff --git a/crates/pallet-token-claims/src/signed_ext.rs b/crates/pallet-token-claims/src/signed_ext.rs index 542959068..d595d2268 100644 --- a/crates/pallet-token-claims/src/signed_ext.rs +++ b/crates/pallet-token-claims/src/signed_ext.rs @@ -9,6 +9,7 @@ use frame_support::{ traits::IsSubType, unsigned::{TransactionValidity, TransactionValidityError}, }; +use primitives_ethereum::{EcdsaSignature, EthereumAddress}; use sp_runtime::traits::{DispatchInfoOf, SignedExtension}; use super::*; @@ -18,18 +19,11 @@ impl Pallet { /// Validate that the `claim` is correct and should be allowed for inclusion. /// /// Implement the flood protection logic. - fn validate_claim_call(who: &T::AccountId, call: &Call) -> TransactionValidity { - // Check if the call matches. - let (ethereum_address, ethereum_signature) = match call { - // Allow `claim` call. - Call::claim { - ethereum_address, - ethereum_signature, - } => (ethereum_address, ethereum_signature), - // Deny all unknown calls. - _ => return Err(TransactionValidityError::Invalid(InvalidTransaction::Call)), - }; - + fn validate_claim_call( + who: &T::AccountId, + ethereum_address: &EthereumAddress, + ethereum_signature: &EcdsaSignature, + ) -> TransactionValidity { // Check the signature. let message_params = EthereumSignatureMessageParams { account_id: who.clone(), @@ -98,7 +92,23 @@ where _len: usize, ) -> TransactionValidity { match call.is_sub_type() { - Some(call) => Pallet::::validate_claim_call(who, call), + // Allow `claim` call. + Some(Call::claim { + ethereum_address, + ethereum_signature, + }) => Pallet::::validate_claim_call(who, ethereum_address, ethereum_signature), + _ => Ok(Default::default()), + } + } + + fn validate_unsigned( + call: &Self::Call, + _info: &DispatchInfoOf, + _len: usize, + ) -> TransactionValidity { + match call.is_sub_type() { + // Disallow `claim` call - can't be used an unsigned tx. + Some(Call::claim { .. }) => InvalidTransaction::Call.into(), _ => Ok(Default::default()), } } From bff0e977511067e62f41d597bc092ab43fcdb6b6 Mon Sep 17 00:00:00 2001 From: MOZGIII Date: Thu, 12 Dec 2024 14:40:55 -0300 Subject: [PATCH 2/3] Fix comment --- crates/pallet-token-claims/src/signed_ext.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/pallet-token-claims/src/signed_ext.rs b/crates/pallet-token-claims/src/signed_ext.rs index d595d2268..566e18ef2 100644 --- a/crates/pallet-token-claims/src/signed_ext.rs +++ b/crates/pallet-token-claims/src/signed_ext.rs @@ -107,7 +107,7 @@ where _len: usize, ) -> TransactionValidity { match call.is_sub_type() { - // Disallow `claim` call - can't be used an unsigned tx. + // Disallow `claim` call - can't be used as an unsigned tx. Some(Call::claim { .. }) => InvalidTransaction::Call.into(), _ => Ok(Default::default()), } From 8ba3dd220231de670202bf8977e2954b1f91ad9f Mon Sep 17 00:00:00 2001 From: MOZGIII Date: Thu, 12 Dec 2024 15:49:09 -0300 Subject: [PATCH 3/3] Compact the notations TransactionValidityError notations --- crates/pallet-token-claims/src/signed_ext.rs | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/crates/pallet-token-claims/src/signed_ext.rs b/crates/pallet-token-claims/src/signed_ext.rs index 566e18ef2..d5151600a 100644 --- a/crates/pallet-token-claims/src/signed_ext.rs +++ b/crates/pallet-token-claims/src/signed_ext.rs @@ -7,7 +7,7 @@ use frame_support::{ pallet_prelude::*, sp_runtime, traits::IsSubType, - unsigned::{TransactionValidity, TransactionValidityError}, + unsigned::TransactionValidity, }; use primitives_ethereum::{EcdsaSignature, EthereumAddress}; use sp_runtime::traits::{DispatchInfoOf, SignedExtension}; @@ -34,14 +34,12 @@ impl Pallet { &message_params, ethereum_address, ) { - return Err(TransactionValidityError::Invalid( - InvalidTransaction::BadProof, - )); + return InvalidTransaction::BadProof.into(); } // Check the presence of a claim. if !>::contains_key(ethereum_address) { - return Err(TransactionValidityError::Invalid(InvalidTransaction::Call)); + return InvalidTransaction::Call.into(); } // All good, letting through.