From 6fc0d8f4016289c53cce28e337925014d93eb142 Mon Sep 17 00:00:00 2001 From: Alistair Singh Date: Tue, 19 Dec 2023 21:58:16 +0200 Subject: [PATCH 1/3] wip --- cumulus/parachains/runtimes/assets/asset-hub-rococo/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cumulus/parachains/runtimes/assets/asset-hub-rococo/src/lib.rs b/cumulus/parachains/runtimes/assets/asset-hub-rococo/src/lib.rs index d6956eef7380..59ec83d5e521 100644 --- a/cumulus/parachains/runtimes/assets/asset-hub-rococo/src/lib.rs +++ b/cumulus/parachains/runtimes/assets/asset-hub-rococo/src/lib.rs @@ -371,7 +371,7 @@ impl pallet_assets::Config for Runtime { type CreateOrigin = ForeignCreators< ( FromSiblingParachain>, - snowbridge_router_primitives::inbound::FromEthereumGlobalConsensus, + FromNetwork, ), ForeignCreatorsSovereignAccountOf, AccountId, From f1ab57968a73aa8275a89528096e7336198cd2b0 Mon Sep 17 00:00:00 2001 From: Alistair Singh Date: Tue, 19 Dec 2023 22:39:55 +0200 Subject: [PATCH 2/3] use from network --- .../runtimes/assets/asset-hub-rococo/src/lib.rs | 9 +++++---- .../runtimes/assets/asset-hub-rococo/src/xcm_config.rs | 6 +----- 2 files changed, 6 insertions(+), 9 deletions(-) diff --git a/cumulus/parachains/runtimes/assets/asset-hub-rococo/src/lib.rs b/cumulus/parachains/runtimes/assets/asset-hub-rococo/src/lib.rs index 59ec83d5e521..dcb28deb7c56 100644 --- a/cumulus/parachains/runtimes/assets/asset-hub-rococo/src/lib.rs +++ b/cumulus/parachains/runtimes/assets/asset-hub-rococo/src/lib.rs @@ -30,11 +30,12 @@ pub mod xcm_config; use assets_common::{ foreign_creators::ForeignCreators, local_and_foreign_assets::{LocalAndForeignAssets, MultiLocationConverter}, - matching::FromSiblingParachain, + matching::{FromNetwork, FromSiblingParachain}, AssetIdForTrustBackedAssetsConvert, MultiLocationForAssetId, }; use cumulus_pallet_parachain_system::RelayNumberStrictlyIncreases; use cumulus_primitives_core::AggregateMessageOrigin; +use snowbridge_rococo_common::EthereumNetwork; use sp_api::impl_runtime_apis; use sp_core::{crypto::KeyTypeId, OpaqueMetadata}; use sp_runtime::{ @@ -95,8 +96,8 @@ use polkadot_runtime_common::{BlockHashCount, SlowAdjustingFeeUpdate}; use xcm::latest::prelude::*; use crate::xcm_config::{ - bridging::to_ethereum::EthereumLocation, ForeignCreatorsSovereignAccountOf, - LocalAndForeignAssetsMultiLocationMatcher, TrustBackedAssetsPalletLocation, + ForeignCreatorsSovereignAccountOf, LocalAndForeignAssetsMultiLocationMatcher, + TrustBackedAssetsPalletLocation, }; use weights::{BlockExecutionWeight, ExtrinsicBaseWeight, RocksDbWeight}; @@ -371,7 +372,7 @@ impl pallet_assets::Config for Runtime { type CreateOrigin = ForeignCreators< ( FromSiblingParachain>, - FromNetwork, + FromNetwork, ), ForeignCreatorsSovereignAccountOf, AccountId, diff --git a/cumulus/parachains/runtimes/assets/asset-hub-rococo/src/xcm_config.rs b/cumulus/parachains/runtimes/assets/asset-hub-rococo/src/xcm_config.rs index 0311f03c2abf..7a92fb5413e0 100644 --- a/cumulus/parachains/runtimes/assets/asset-hub-rococo/src/xcm_config.rs +++ b/cumulus/parachains/runtimes/assets/asset-hub-rococo/src/xcm_config.rs @@ -842,8 +842,6 @@ pub mod bridging { use super::*; parameter_types! { - pub EthereumLocation: MultiLocation = MultiLocation::new(2, X1(GlobalConsensus(EthereumNetwork::get()))); - /// User fee for ERC20 token transfer back to Ethereum. /// (initially was calculated by test `OutboundQueue::calculate_fees` - ETH/ROC 1/400 and fee_per_gas 20 GWEI = 2200698000000 + *25%) /// Needs to be more than fee calculated from DefaultFeeConfig FeeConfigRecord in snowbridge:parachain/pallets/outbound-queue/src/lib.rs @@ -863,9 +861,7 @@ pub mod bridging { pub BridgeTable: sp_std::vec::Vec = sp_std::vec![ NetworkExportTableItem::new( EthereumNetwork::get(), - Some(sp_std::vec![ - EthereumLocation::get().interior.split_global().expect("invalid configuration for Ethereum").1, - ]), + Some(sp_std::vec![Junctions::Here]), SiblingBridgeHub::get(), Some(( XcmBridgeHubRouterFeeAssetId::get(), From dd7191526e36a942f593d5364f2ae5e3796a60e0 Mon Sep 17 00:00:00 2001 From: Alistair Singh Date: Wed, 20 Dec 2023 00:09:12 +0200 Subject: [PATCH 3/3] add tests --- .../runtimes/assets/common/src/matching.rs | 93 +++++++++++++++++++ 1 file changed, 93 insertions(+) diff --git a/cumulus/parachains/runtimes/assets/common/src/matching.rs b/cumulus/parachains/runtimes/assets/common/src/matching.rs index c8f8d0a7df70..d6ecc3ec99f0 100644 --- a/cumulus/parachains/runtimes/assets/common/src/matching.rs +++ b/cumulus/parachains/runtimes/assets/common/src/matching.rs @@ -58,6 +58,8 @@ impl> ContainsPair } } +/// Checks if `a` is from the expected global consensus network. Checks that `MultiLocation-a` +/// starts with `MultiLocation-b`, and that network is a foreign consensus system. pub struct FromNetwork( sp_std::marker::PhantomData<(UniversalLocation, ExpectedNetworkId)>, ); @@ -72,6 +74,7 @@ impl, ExpectedNetworkId: Get network_id == ExpectedNetworkId::get(), Err(e) => { @@ -85,6 +88,7 @@ impl, ExpectedNetworkId: Get::contains(&asset, &origin)); + + // asset and origin from local consensus fails + let asset: MultiLocation = ( + Parent, + Parent, + GlobalConsensus(Rococo), + Parachain(1000), + PalletInstance(1), + GeneralIndex(1), + ) + .into(); + let origin: MultiLocation = + (Parent, Parent, GlobalConsensus(Rococo), Parachain(1000)).into(); + assert!(!FromNetwork::::contains(&asset, &origin)); + + // asset and origin from here fails + let asset: MultiLocation = (PalletInstance(1), GeneralIndex(1)).into(); + let origin: MultiLocation = Here.into(); + assert!(!FromNetwork::::contains(&asset, &origin)); + + // asset from different consensus fails + let asset: MultiLocation = ( + Parent, + Parent, + GlobalConsensus(Polkadot), + Parachain(1000), + PalletInstance(1), + GeneralIndex(1), + ) + .into(); + let origin: MultiLocation = + (Parent, Parent, GlobalConsensus(Wococo), Parachain(1000)).into(); + assert!(!FromNetwork::::contains(&asset, &origin)); + + // origin from different consensus fails + let asset: MultiLocation = ( + Parent, + Parent, + GlobalConsensus(Wococo), + Parachain(1000), + PalletInstance(1), + GeneralIndex(1), + ) + .into(); + let origin: MultiLocation = + (Parent, Parent, GlobalConsensus(Polkadot), Parachain(1000)).into(); + assert!(!FromNetwork::::contains(&asset, &origin)); + + // asset and origin from unexpected consensus fails + let asset: MultiLocation = ( + Parent, + Parent, + GlobalConsensus(Polkadot), + Parachain(1000), + PalletInstance(1), + GeneralIndex(1), + ) + .into(); + let origin: MultiLocation = + (Parent, Parent, GlobalConsensus(Polkadot), Parachain(1000)).into(); + assert!(!FromNetwork::::contains(&asset, &origin)); + } +}