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 17 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
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,
WhitelistedParaId,
>(
PhantomData<(
UniversalLocation,
EthereumNetwork,
OutboundQueue,
AgentHashedDescription,
ConvertAssetId,
WhitelistedParaId,
)>,
);

impl<UniversalLocation, EthereumNetwork, OutboundQueue, AgentHashedDescription, ConvertAssetId>
ExportXcm
impl<
UniversalLocation,
EthereumNetwork,
OutboundQueue,
AgentHashedDescription,
ConvertAssetId,
WhitelistedParaId,
> ExportXcm
for EthereumBlobExporter<
UniversalLocation,
EthereumNetwork,
OutboundQueue,
AgentHashedDescription,
ConvertAssetId,
WhitelistedParaId,
>
where
UniversalLocation: Get<InteriorLocation>,
EthereumNetwork: Get<NetworkId>,
OutboundQueue: SendMessage<Balance = u128>,
AgentHashedDescription: ConvertLocation<H256>,
ConvertAssetId: MaybeEquivalence<TokenId, Location>,
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) == WhitelistedParaId::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