From fdf78b7f88eaea5854e0bccaff210b60d4b18464 Mon Sep 17 00:00:00 2001 From: Gav Date: Fri, 18 Aug 2023 14:57:14 +0200 Subject: [PATCH 1/4] Bound number of assets which can be withdrawn to pay for execution. --- xcm/xcm-builder/src/barriers.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/xcm/xcm-builder/src/barriers.rs b/xcm/xcm-builder/src/barriers.rs index 6996c7145528..3d8f20b9ab9f 100644 --- a/xcm/xcm-builder/src/barriers.rs +++ b/xcm/xcm-builder/src/barriers.rs @@ -80,9 +80,9 @@ impl> ShouldExecute for AllowTopLevelPaidExecutionFro .matcher() .match_next_inst(|inst| match inst { ReceiveTeleportedAsset(..) | - WithdrawAsset(..) | ReserveAssetDeposited(..) | ClaimAsset { .. } => Ok(()), + WithdrawAsset(ref assets) if assets.len() < 2 => Ok(()), _ => Err(ProcessMessageError::BadFormat), })? .skip_inst_while(|inst| matches!(inst, ClearOrigin))? From 0c8a3bca0dbe61961e9fafe2fd1d328b3a9dae75 Mon Sep 17 00:00:00 2001 From: command-bot <> Date: Fri, 18 Aug 2023 14:49:40 +0000 Subject: [PATCH 2/4] ".git/.scripts/commands/fmt/fmt.sh" --- xcm/xcm-builder/src/barriers.rs | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/xcm/xcm-builder/src/barriers.rs b/xcm/xcm-builder/src/barriers.rs index 3d8f20b9ab9f..09eeb00988f8 100644 --- a/xcm/xcm-builder/src/barriers.rs +++ b/xcm/xcm-builder/src/barriers.rs @@ -79,9 +79,8 @@ impl> ShouldExecute for AllowTopLevelPaidExecutionFro instructions[..end] .matcher() .match_next_inst(|inst| match inst { - ReceiveTeleportedAsset(..) | - ReserveAssetDeposited(..) | - ClaimAsset { .. } => Ok(()), + ReceiveTeleportedAsset(..) | ReserveAssetDeposited(..) | ClaimAsset { .. } => + Ok(()), WithdrawAsset(ref assets) if assets.len() < 2 => Ok(()), _ => Err(ProcessMessageError::BadFormat), })? From 304267cefb7a8eeb139d80c0fecc915ae90d70a7 Mon Sep 17 00:00:00 2001 From: Francisco Aguirre Date: Mon, 21 Aug 2023 17:54:25 -0300 Subject: [PATCH 3/4] Include ClaimAsset in limiting the assets --- xcm/xcm-builder/src/barriers.rs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/xcm/xcm-builder/src/barriers.rs b/xcm/xcm-builder/src/barriers.rs index 09eeb00988f8..32f028362e44 100644 --- a/xcm/xcm-builder/src/barriers.rs +++ b/xcm/xcm-builder/src/barriers.rs @@ -72,6 +72,7 @@ impl> ShouldExecute for AllowTopLevelPaidExecutionFro ); ensure!(T::contains(origin), ProcessMessageError::Unsupported); + let max_assets_for_buy_execution = 1; // We will read up to 5 instructions. This allows up to 3 `ClearOrigin` instructions. We // allow for more than one since anything beyond the first is a no-op and it's conceivable // that composition of operations might result in more than one being appended. @@ -79,9 +80,10 @@ impl> ShouldExecute for AllowTopLevelPaidExecutionFro instructions[..end] .matcher() .match_next_inst(|inst| match inst { - ReceiveTeleportedAsset(..) | ReserveAssetDeposited(..) | ClaimAsset { .. } => + ReceiveTeleportedAsset(..) | ReserveAssetDeposited(..) => Ok(()), + WithdrawAsset(ref assets) if assets.len() <= max_assets_for_buy_execution => Ok(()), + ClaimAsset { ref assets, .. } if assets.len() <= max_assets_for_buy_execution => Ok(()), - WithdrawAsset(ref assets) if assets.len() < 2 => Ok(()), _ => Err(ProcessMessageError::BadFormat), })? .skip_inst_while(|inst| matches!(inst, ClearOrigin))? From 1b34ff98e87d6c355f4be0fc3c56289ea900070f Mon Sep 17 00:00:00 2001 From: Francisco Aguirre Date: Mon, 21 Aug 2023 20:27:04 -0300 Subject: [PATCH 4/4] Change max assets to constant --- xcm/xcm-builder/src/barriers.rs | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/xcm/xcm-builder/src/barriers.rs b/xcm/xcm-builder/src/barriers.rs index 32f028362e44..353e111b813b 100644 --- a/xcm/xcm-builder/src/barriers.rs +++ b/xcm/xcm-builder/src/barriers.rs @@ -52,6 +52,8 @@ impl ShouldExecute for TakeWeightCredit { } } +const MAX_ASSETS_FOR_BUY_EXECUTION: usize = 1; + /// Allows execution from `origin` if it is contained in `T` (i.e. `T::Contains(origin)`) taking /// payments into account. /// @@ -72,7 +74,6 @@ impl> ShouldExecute for AllowTopLevelPaidExecutionFro ); ensure!(T::contains(origin), ProcessMessageError::Unsupported); - let max_assets_for_buy_execution = 1; // We will read up to 5 instructions. This allows up to 3 `ClearOrigin` instructions. We // allow for more than one since anything beyond the first is a no-op and it's conceivable // that composition of operations might result in more than one being appended. @@ -81,8 +82,8 @@ impl> ShouldExecute for AllowTopLevelPaidExecutionFro .matcher() .match_next_inst(|inst| match inst { ReceiveTeleportedAsset(..) | ReserveAssetDeposited(..) => Ok(()), - WithdrawAsset(ref assets) if assets.len() <= max_assets_for_buy_execution => Ok(()), - ClaimAsset { ref assets, .. } if assets.len() <= max_assets_for_buy_execution => + WithdrawAsset(ref assets) if assets.len() <= MAX_ASSETS_FOR_BUY_EXECUTION => Ok(()), + ClaimAsset { ref assets, .. } if assets.len() <= MAX_ASSETS_FOR_BUY_EXECUTION => Ok(()), _ => Err(ProcessMessageError::BadFormat), })?