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

Open
wants to merge 14 commits into
base: master
Choose a base branch
from
Open
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,4 @@ substrate.code-workspace
target/
*.scale
justfile
python-venv
21 changes: 16 additions & 5 deletions bridges/snowbridge/primitives/router/src/outbound/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,31 +26,41 @@ pub struct EthereumBlobExporter<
OutboundQueue,
AgentHashedDescription,
ConvertAssetId,
AssetHubParaId,
>(
PhantomData<(
UniversalLocation,
EthereumNetwork,
OutboundQueue,
AgentHashedDescription,
ConvertAssetId,
AssetHubParaId,
)>,
);

impl<UniversalLocation, EthereumNetwork, OutboundQueue, AgentHashedDescription, ConvertAssetId>
ExportXcm
impl<
UniversalLocation,
EthereumNetwork,
OutboundQueue,
AgentHashedDescription,
ConvertAssetId,
AssetHubParaId,
> ExportXcm
for EthereumBlobExporter<
UniversalLocation,
EthereumNetwork,
OutboundQueue,
AgentHashedDescription,
ConvertAssetId,
AssetHubParaId,
>
where
UniversalLocation: Get<InteriorLocation>,
EthereumNetwork: Get<NetworkId>,
OutboundQueue: SendMessage<Balance = u128>,
AgentHashedDescription: ConvertLocation<H256>,
ConvertAssetId: MaybeEquivalence<TokenId, Location>,
AssetHubParaId: Get<ParaId>,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
AssetHubParaId: Get<ParaId>,
WhitelistedParaId: Get<ParaId>,

{
type Ticket = (Vec<u8>, XcmHash);

Expand Down Expand Up @@ -94,11 +104,12 @@ where
return Err(SendError::NotApplicable)
}

// Check the location here can only be AssetHub sovereign
let para_id = match local_sub.as_slice() {
[Parachain(para_id)] => *para_id,
[Parachain(para_id)] if ParaId::from(*para_id) == AssetHubParaId::get() => *para_id,
_ => {
log::error!(target: "xcm::ethereum_blob_exporter", "could not get parachain id from universal source '{local_sub:?}'.");
return Err(SendError::NotApplicable)
log::debug!(target: "xcm::ethereum_blob_exporter", "only supports Asset Hub root location as the universal source '{local_sub:?}'.");
return Err(SendError::NotApplicable);
},
};

Expand Down
17 changes: 17 additions & 0 deletions bridges/snowbridge/primitives/router/src/outbound/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ parameter_types! {
UniversalLocation: InteriorLocation = [GlobalConsensus(RelayNetwork::get()), Parachain(1013)].into();
const BridgedNetwork: NetworkId = Ethereum{ chain_id: 1 };
const NonBridgedNetwork: NetworkId = Ethereum{ chain_id: 2 };
pub AssetHubParaId: ParaId = ParaId::from(1000);
}

struct MockOkOutboundQueue;
Expand Down Expand Up @@ -86,6 +87,7 @@ fn exporter_validate_with_unknown_network_yields_not_applicable() {
MockOkOutboundQueue,
AgentIdOf,
MockTokenIdConvert,
AssetHubParaId,
>::validate(network, channel, &mut universal_source, &mut destination, &mut message);
assert_eq!(result, Err(XcmSendError::NotApplicable));
}
Expand All @@ -105,6 +107,7 @@ fn exporter_validate_with_invalid_destination_yields_missing_argument() {
MockOkOutboundQueue,
AgentIdOf,
MockTokenIdConvert,
AssetHubParaId,
>::validate(network, channel, &mut universal_source, &mut destination, &mut message);
assert_eq!(result, Err(XcmSendError::MissingArgument));
}
Expand All @@ -127,6 +130,7 @@ fn exporter_validate_with_x8_destination_yields_not_applicable() {
MockOkOutboundQueue,
AgentIdOf,
MockTokenIdConvert,
AssetHubParaId,
>::validate(network, channel, &mut universal_source, &mut destination, &mut message);
assert_eq!(result, Err(XcmSendError::NotApplicable));
}
Expand All @@ -146,6 +150,7 @@ fn exporter_validate_without_universal_source_yields_missing_argument() {
MockOkOutboundQueue,
AgentIdOf,
MockTokenIdConvert,
AssetHubParaId,
>::validate(network, channel, &mut universal_source, &mut destination, &mut message);
assert_eq!(result, Err(XcmSendError::MissingArgument));
}
Expand All @@ -165,6 +170,7 @@ fn exporter_validate_without_global_universal_location_yields_not_applicable() {
MockOkOutboundQueue,
AgentIdOf,
MockTokenIdConvert,
AssetHubParaId,
>::validate(network, channel, &mut universal_source, &mut destination, &mut message);
assert_eq!(result, Err(XcmSendError::NotApplicable));
}
Expand All @@ -184,6 +190,7 @@ fn exporter_validate_without_global_bridge_location_yields_not_applicable() {
MockOkOutboundQueue,
AgentIdOf,
MockTokenIdConvert,
AssetHubParaId,
>::validate(network, channel, &mut universal_source, &mut destination, &mut message);
assert_eq!(result, Err(XcmSendError::NotApplicable));
}
Expand All @@ -204,6 +211,7 @@ fn exporter_validate_with_remote_universal_source_yields_not_applicable() {
MockOkOutboundQueue,
AgentIdOf,
MockTokenIdConvert,
AssetHubParaId,
>::validate(network, channel, &mut universal_source, &mut destination, &mut message);
assert_eq!(result, Err(XcmSendError::NotApplicable));
}
Expand All @@ -223,6 +231,7 @@ fn exporter_validate_without_para_id_in_source_yields_not_applicable() {
MockOkOutboundQueue,
AgentIdOf,
MockTokenIdConvert,
AssetHubParaId,
>::validate(network, channel, &mut universal_source, &mut destination, &mut message);
assert_eq!(result, Err(XcmSendError::NotApplicable));
}
Expand All @@ -243,6 +252,7 @@ fn exporter_validate_complex_para_id_in_source_yields_not_applicable() {
MockOkOutboundQueue,
AgentIdOf,
MockTokenIdConvert,
AssetHubParaId,
>::validate(network, channel, &mut universal_source, &mut destination, &mut message);
assert_eq!(result, Err(XcmSendError::NotApplicable));
}
Expand All @@ -263,6 +273,7 @@ fn exporter_validate_without_xcm_message_yields_missing_argument() {
MockOkOutboundQueue,
AgentIdOf,
MockTokenIdConvert,
AssetHubParaId,
>::validate(network, channel, &mut universal_source, &mut destination, &mut message);
assert_eq!(result, Err(XcmSendError::MissingArgument));
}
Expand Down Expand Up @@ -310,6 +321,7 @@ fn exporter_validate_with_max_target_fee_yields_unroutable() {
MockOkOutboundQueue,
AgentIdOf,
MockTokenIdConvert,
AssetHubParaId,
>::validate(network, channel, &mut universal_source, &mut destination, &mut message);

assert_eq!(result, Err(XcmSendError::Unroutable));
Expand Down Expand Up @@ -337,6 +349,7 @@ fn exporter_validate_with_unparsable_xcm_yields_unroutable() {
MockOkOutboundQueue,
AgentIdOf,
MockTokenIdConvert,
AssetHubParaId,
>::validate(network, channel, &mut universal_source, &mut destination, &mut message);

assert_eq!(result, Err(XcmSendError::Unroutable));
Expand Down Expand Up @@ -383,6 +396,7 @@ fn exporter_validate_xcm_success_case_1() {
MockOkOutboundQueue,
AgentIdOf,
MockTokenIdConvert,
AssetHubParaId,
>::validate(network, channel, &mut universal_source, &mut destination, &mut message);

assert!(result.is_ok());
Expand All @@ -396,6 +410,7 @@ fn exporter_deliver_with_submit_failure_yields_unroutable() {
MockErrOutboundQueue,
AgentIdOf,
MockTokenIdConvert,
AssetHubParaId,
>::deliver((hex!("deadbeef").to_vec(), XcmHash::default()));
assert_eq!(result, Err(XcmSendError::Transport("other transport error")))
}
Expand Down Expand Up @@ -1208,6 +1223,7 @@ fn exporter_validate_with_invalid_dest_does_not_alter_destination() {
MockOkOutboundQueue,
AgentIdOf,
MockTokenIdConvert,
AssetHubParaId,
>::validate(
network, channel, &mut universal_source_wrapper, &mut dest_wrapper, &mut msg_wrapper
);
Expand Down Expand Up @@ -1261,6 +1277,7 @@ fn exporter_validate_with_invalid_universal_source_does_not_alter_universal_sour
MockOkOutboundQueue,
AgentIdOf,
MockTokenIdConvert,
AssetHubParaId,
>::validate(
network, channel, &mut universal_source_wrapper, &mut dest_wrapper, &mut msg_wrapper
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ mod claim_assets;
mod register_bridged_assets;
mod send_xcm;
mod snowbridge;
mod snowbridge_edge_case;
mod teleport;
mod transact;

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
Loading
Loading