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

[Snowbridge]: Ensure source always from AH for exported message #6838

Draft
wants to merge 36 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 2 commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
8a88a8b
Ensure source always from AH
yrong Dec 11, 2024
53ee95e
More tests for edge cases
yrong Dec 11, 2024
525e6a6
Update bridges/snowbridge/primitives/router/src/outbound/mod.rs
yrong Dec 13, 2024
c3b8b88
Update bridges/snowbridge/primitives/router/src/outbound/mod.rs
yrong Dec 13, 2024
a7cb93d
Update bridges/snowbridge/primitives/router/src/outbound/mod.rs
yrong Dec 13, 2024
277d51b
Load AssetHub's ParaId from runtime
yrong Dec 13, 2024
c2a8ba9
More tests
yrong Dec 13, 2024
7192a5a
Add prdoc
yrong Dec 13, 2024
f7b6f3a
Merge branch 'master' into check-souce-from-ah
yrong Dec 13, 2024
62f629b
Fix fmt
yrong Dec 13, 2024
eff2ef2
Merge branch 'check-souce-from-ah' of https://github.com/yrong/polkad…
yrong Dec 13, 2024
f84cc0a
Merge branch 'master' into check-souce-from-ah
yrong Dec 13, 2024
df1e673
Fix the comment
yrong Dec 14, 2024
11f8d57
Merge branch 'master' into check-souce-from-ah
yrong Dec 18, 2024
2bf5bb1
Rename as WhitelistedParaId
yrong Jan 7, 2025
73961f4
Merge branch 'check-souce-from-ah' of https://github.com/yrong/polkad…
yrong Jan 7, 2025
b5d4369
Merge branch 'master' into check-souce-from-ah
yrong Jan 7, 2025
0a51fec
Revert change
yrong Jan 13, 2025
e2e0228
Barrier DenyFirstExportMessageFrom
yrong Jan 13, 2025
7102219
Merge branch 'master' into check-souce-from-ah
yrong Jan 13, 2025
7f529ed
Rename
yrong Jan 14, 2025
ccf9a28
Fix xcm config
yrong Jan 14, 2025
5226eed
Cleanup
yrong Jan 14, 2025
e779308
Update prdoc/pr_6838.prdoc
franciscoaguirre Jan 14, 2025
3a66cdb
More tests
yrong Jan 14, 2025
5f9ea7f
Merge branch 'check-souce-from-ah' of https://github.com/yrong/polkad…
yrong Jan 14, 2025
15ae2b3
Update cumulus/parachains/integration-tests/emulated/tests/bridges/br…
yrong Jan 14, 2025
e792f7d
Cleanup
yrong Jan 14, 2025
d0027ea
Update bridges/snowbridge/primitives/router/src/outbound/barriers.rs
yrong Jan 14, 2025
fcadbd7
Update bridges/snowbridge/primitives/router/src/outbound/barriers.rs
yrong Jan 14, 2025
4b51b60
Update bridges/snowbridge/primitives/router/src/outbound/barriers.rs
yrong Jan 14, 2025
6701841
Update bridges/snowbridge/primitives/router/src/outbound/barriers.rs
yrong Jan 14, 2025
efa5114
Fix format
yrong Jan 14, 2025
f53964b
Merge branch 'master' into check-souce-from-ah
yrong Jan 14, 2025
421b4ef
Fix clippy
yrong Jan 14, 2025
ef72cdf
Merge branch 'master' into check-souce-from-ah
yrong Jan 14, 2025
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
7 changes: 6 additions & 1 deletion bridges/snowbridge/primitives/router/src/outbound/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ use sp_std::{iter::Peekable, marker::PhantomData, prelude::*};
use xcm::prelude::*;
use xcm_executor::traits::{ConvertLocation, ExportXcm};

pub const ASSET_HUB_PARA_ID:u32 = 1000;
acatangiu marked this conversation as resolved.
Show resolved Hide resolved

pub struct EthereumBlobExporter<
UniversalLocation,
EthereumNetwork,
Expand Down Expand Up @@ -94,13 +96,16 @@ where
return Err(SendError::NotApplicable)
}

// Check the location here can only be AssetHub sovereign
ensure!(local_sub.len() == 1, SendError::NotApplicable);
let para_id = match local_sub.as_slice() {
[Parachain(para_id)] => *para_id,
yrong marked this conversation as resolved.
Show resolved Hide resolved
_ => {
log::error!(target: "xcm::ethereum_blob_exporter", "could not get parachain id from universal source '{local_sub:?}'.");
yrong marked this conversation as resolved.
Show resolved Hide resolved
return Err(SendError::NotApplicable)
return Err(SendError::NotApplicable);
},
};
ensure!(para_id == ASSET_HUB_PARA_ID, SendError::NotApplicable);
yrong marked this conversation as resolved.
Show resolved Hide resolved

let source_location = Location::new(1, local_sub.clone());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ mod send_xcm;
mod snowbridge;
mod teleport;
mod transact;
mod snowbridge_edge_case;

pub(crate) fn asset_hub_rococo_location() -> Location {
Location::new(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ use xcm_executor::traits::ConvertLocation;
const INITIAL_FUND: u128 = 5_000_000_000_000;
pub const CHAIN_ID: u64 = 11155111;
pub const WETH: [u8; 20] = hex!("87d1f7fdfEe7f651FaBc8bFCB6E086C278b77A7d");
const ETHEREUM_DESTINATION_ADDRESS: [u8; 20] = hex!("44a57ee2f2FCcb85FDa2B0B18EBD0D8D2333700e");
pub const ETHEREUM_DESTINATION_ADDRESS: [u8; 20] = hex!("44a57ee2f2FCcb85FDa2B0B18EBD0D8D2333700e");
const XCM_FEE: u128 = 100_000_000_000;
const TOKEN_AMOUNT: u128 = 100_000_000_000;

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
// Copyright (C) Parity Technologies (UK) Ltd.
// SPDX-License-Identifier: Apache-2.0

// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
use crate::imports::*;
use bridge_hub_westend_runtime::xcm_config::LocationToAccountId;
use xcm_executor::traits::ConvertLocation;

use crate::tests::snowbridge::{CHAIN_ID,WETH,ETHEREUM_DESTINATION_ADDRESS};

const INITIAL_FUND: u128 = 5_000_000_000_000;
const TOKEN_AMOUNT: u128 = 100_000_000_000;

pub fn bridge_hub() -> Location {
Location::new(1, Parachain(BridgeHubWestend::para_id().into()))
}

pub fn beneficiary() -> Location {
Location::new(0, [AccountKey20 { network: None, key: ETHEREUM_DESTINATION_ADDRESS.into() }])
}

#[test]
fn user_export_message_from_ah_directly_will_fail() {
let sov_account_for_assethub_sender = LocationToAccountId::convert_location(&Location::new(
1,
[
Parachain(AssetHubWestend::para_id().into()),
AccountId32 {
network: Some(ByGenesis(WESTEND_GENESIS_HASH)),
id: AssetHubWestendSender::get().into(),
},
],
))
.unwrap();
BridgeHubWestend::fund_accounts(vec![(sov_account_for_assethub_sender, INITIAL_FUND)]);

AssetHubWestend::execute_with(|| {
type RuntimeEvent = <AssetHubWestend as Chain>::RuntimeEvent;
type RuntimeOrigin = <AssetHubWestend as Chain>::RuntimeOrigin;

let local_fee_asset =
Asset { id: AssetId(Location::parent()), fun: Fungible(1_000_000_000_000) };

let weth_location_reanchored =
Location::new(0, [AccountKey20 { network: None, key: WETH.into() }]);

let weth_asset = Asset {
id: AssetId(weth_location_reanchored.clone()),
fun: Fungible(TOKEN_AMOUNT * 1_000_000_000),
};

assert_ok!(<AssetHubWestend as AssetHubWestendPallet>::PolkadotXcm::send(
RuntimeOrigin::signed(AssetHubWestendSender::get()),
bx!(VersionedLocation::from(bridge_hub())),
bx!(VersionedXcm::from(Xcm(vec![
WithdrawAsset(local_fee_asset.clone().into()),
BuyExecution { fees: local_fee_asset.clone(), weight_limit: Unlimited },
ExportMessage {
network: Ethereum { chain_id: CHAIN_ID },
destination: Here,
xcm: Xcm(vec![
WithdrawAsset(weth_asset.clone().into()),
DepositAsset { assets: Wild(All), beneficiary: beneficiary() },
SetTopic([0; 32]),
]),
},
]))),
));

assert_expected_events!(
AssetHubWestend,
vec![RuntimeEvent::PolkadotXcm(pallet_xcm::Event::Sent{ .. }) => {},]
);
});

BridgeHubWestend::execute_with(|| {
type RuntimeEvent = <BridgeHubWestend as Chain>::RuntimeEvent;
assert_expected_events!(
BridgeHubWestend,
vec![RuntimeEvent::MessageQueue(pallet_message_queue::Event::Processed{ success:false, .. }) => {},]
);
});
}
Loading