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

Lock down token transfer to AssetHub only #1047

Closed
wants to merge 7 commits into from
Closed
Show file tree
Hide file tree
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
51 changes: 38 additions & 13 deletions parachain/primitives/router/src/outbound/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@ use core::slice::Iter;

use codec::{Decode, Encode};

use frame_support::{ensure, traits::Get};
use frame_support::{
ensure,
traits::{ContainsPair, Get},
};
use snowbridge_core::{
outbound::{AgentExecuteCommand, Command, Message, SendMessage},
ChannelId, ParaId,
Expand All @@ -24,15 +27,31 @@ pub struct EthereumBlobExporter<
EthereumNetwork,
OutboundQueue,
AgentHashedDescription,
>(PhantomData<(UniversalLocation, EthereumNetwork, OutboundQueue, AgentHashedDescription)>);

impl<UniversalLocation, EthereumNetwork, OutboundQueue, AgentHashedDescription> ExportXcm
for EthereumBlobExporter<UniversalLocation, EthereumNetwork, OutboundQueue, AgentHashedDescription>
where
ExportFilter,
>(
PhantomData<(
UniversalLocation,
EthereumNetwork,
OutboundQueue,
AgentHashedDescription,
ExportFilter,
)>,
);

impl<UniversalLocation, EthereumNetwork, OutboundQueue, AgentHashedDescription, ExportFilter>
ExportXcm
for EthereumBlobExporter<
UniversalLocation,
EthereumNetwork,
OutboundQueue,
AgentHashedDescription,
ExportFilter,
> where
UniversalLocation: Get<InteriorMultiLocation>,
EthereumNetwork: Get<NetworkId>,
OutboundQueue: SendMessage<Balance = u128>,
AgentHashedDescription: ConvertLocation<H256>,
ExportFilter: ContainsPair<InteriorMultiLocation, Message>,
{
type Ticket = (Vec<u8>, XcmHash);

Expand All @@ -57,7 +76,7 @@ where
return Err(SendError::NotApplicable)
}

let (local_net, local_sub) = universal_source
let (local_net, local_origin) = universal_source
.take()
.ok_or_else(|| {
log::error!(target: "xcm::ethereum_blob_exporter", "universal source not provided.");
Expand All @@ -74,10 +93,10 @@ where
return Err(SendError::NotApplicable)
}

let para_id = match local_sub {
let para_id = match local_origin {
X1(Parachain(para_id)) => para_id,
_ => {
log::error!(target: "xcm::ethereum_blob_exporter", "could not get parachain id from universal source '{local_sub:?}'.");
log::error!(target: "xcm::ethereum_blob_exporter", "could not get parachain id from universal source '{local_origin:?}'.");
return Err(SendError::MissingArgument)
},
};
Expand All @@ -93,12 +112,12 @@ where
SendError::Unroutable
})?;

// local_sub is relative to the relaychain. No conversion needed.
let local_sub_location: MultiLocation = local_sub.into();
let agent_id = match AgentHashedDescription::convert_location(&local_sub_location) {
// local_origin is relative to the relaychain. No conversion needed.
let local_origin_location: MultiLocation = local_origin.into();
let agent_id = match AgentHashedDescription::convert_location(&local_origin_location) {
Some(id) => id,
None => {
log::error!(target: "xcm::ethereum_blob_exporter", "unroutable due to not being able to create agent id. '{local_sub_location:?}'");
log::error!(target: "xcm::ethereum_blob_exporter", "unroutable due to not being able to create agent id. '{local_origin_location:?}'");
return Err(SendError::Unroutable)
},
};
Expand All @@ -111,6 +130,12 @@ where
command: Command::AgentExecute { agent_id, command: agent_execute_command },
};

// filter out message
if !ExportFilter::contains(&local_origin, &outbound_message) {
log::error!(target: "xcm::ethereum_blob_exporter", "unroutable due to being filtered. '{local_origin:?}'");
return Err(SendError::Unroutable)
}

// validate the message
let (ticket, fee) = OutboundQueue::validate(&outbound_message).map_err(|err| {
log::error!(target: "xcm::ethereum_blob_exporter", "OutboundQueue validation of message failed. {err:?}");
Expand Down
Loading
Loading