Skip to content

Commit 78ba4ad

Browse files
authored
Merge pull request #3744 from autonomys/restrict_zero_account_transfers
ensure dst_location does not allow xdm transfers to zero account on substrate as well
2 parents 334eff9 + fcc0f09 commit 78ba4ad

File tree

2 files changed

+24
-1
lines changed

2 files changed

+24
-1
lines changed

domains/pallets/transporter/src/lib.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ pub use weights::WeightInfo;
4949
/// Zero EVM address.
5050
/// Used to ensure dst_account is not ZERO address.
5151
const ZERO_EVM_ADDRESS: MultiAccountId = MultiAccountId::AccountId20([0; 20]);
52+
const ZERO_SUBSTRATE_ADDRESS: MultiAccountId = MultiAccountId::AccountId32([0; 32]);
5253

5354
/// Location that either sends or receives transfers between chains.
5455
#[derive(Debug, Encode, Decode, Clone, Eq, PartialEq, TypeInfo, DecodeWithMemTracking)]
@@ -83,7 +84,7 @@ mod pallet {
8384
use crate::weights::WeightInfo;
8485
use crate::{
8586
BalanceOf, Location, MessageIdOf, MultiAccountId, Transfer, TryConvertBack,
86-
ZERO_EVM_ADDRESS,
87+
ZERO_EVM_ADDRESS, ZERO_SUBSTRATE_ADDRESS,
8788
};
8889
#[cfg(not(feature = "std"))]
8990
use alloc::vec::Vec;
@@ -265,6 +266,11 @@ mod pallet {
265266
Error::<T>::InvalidAccountId
266267
);
267268

269+
ensure!(
270+
dst_location.account_id != ZERO_SUBSTRATE_ADDRESS,
271+
Error::<T>::InvalidAccountId
272+
);
273+
268274
// burn transfer amount
269275
let _imbalance = T::Currency::withdraw(
270276
&sender,

domains/pallets/transporter/src/tests.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,23 @@ fn test_transfer_invalid_account_id() {
195195
})
196196
}
197197

198+
#[test]
199+
fn test_transfer_invalid_account_id_substrate() {
200+
new_test_ext().execute_with(|| {
201+
let account = USER_ACCOUNT;
202+
let amount: Balance = 500;
203+
// transfer 500 to dst_chain id 1
204+
let dst_chain_id: ChainId = 1.into();
205+
let dst_location = Location {
206+
chain_id: dst_chain_id,
207+
account_id: MultiAccountId::AccountId32([0; 32]),
208+
};
209+
210+
let res = Transporter::transfer(RuntimeOrigin::signed(account), dst_location, amount);
211+
assert_err!(res, Error::<MockRuntime>::InvalidAccountId)
212+
})
213+
}
214+
198215
#[test]
199216
fn test_transfer_response_revert() {
200217
new_test_ext().execute_with(|| {

0 commit comments

Comments
 (0)