Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Correct the token claims validation logic CheckTokenClaim #1368

Merged
merged 3 commits into from
Dec 13, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 26 additions & 18 deletions crates/pallet-token-claims/src/signed_ext.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@ 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};

use super::*;
Expand All @@ -18,18 +19,11 @@ impl<T: Config> Pallet<T> {
/// 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<T>) -> 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(),
Expand All @@ -40,14 +34,12 @@ impl<T: Config> Pallet<T> {
&message_params,
ethereum_address,
) {
return Err(TransactionValidityError::Invalid(
InvalidTransaction::BadProof,
));
return InvalidTransaction::BadProof.into();
}

// Check the presence of a claim.
if !<Claims<T>>::contains_key(ethereum_address) {
return Err(TransactionValidityError::Invalid(InvalidTransaction::Call));
return InvalidTransaction::Call.into();
}

// All good, letting through.
Expand Down Expand Up @@ -98,7 +90,23 @@ where
_len: usize,
) -> TransactionValidity {
match call.is_sub_type() {
Some(call) => Pallet::<T>::validate_claim_call(who, call),
// Allow `claim` call.
Some(Call::claim {
ethereum_address,
ethereum_signature,
}) => Pallet::<T>::validate_claim_call(who, ethereum_address, ethereum_signature),
_ => Ok(Default::default()),
}
}

fn validate_unsigned(
call: &Self::Call,
_info: &DispatchInfoOf<Self::Call>,
_len: usize,
) -> TransactionValidity {
match call.is_sub_type() {
// Disallow `claim` call - can't be used as an unsigned tx.
Some(Call::claim { .. }) => InvalidTransaction::Call.into(),
_ => Ok(Default::default()),
}
}
Expand Down