Skip to content

Commit 98c6ffc

Browse files
vgeddesclaravanstadenyrongacatangiu
authored
Snowbridge V2 (paritytech#7402)
Implementation of the Snowbridge V2 [specification](https://github.com/paritytech/polkadot-sdk/blob/master/bridges/snowbridge/docs/v2.md). Companion PR for changes on the Ethereum side: Snowfork/snowbridge#1371 # High-level overview The implementation of V2 is additive and does not affect the V1 protocol in any manner. ## BridgeHub * Adds pallet `snowbridge-pallet-inbound-queue-v2` which is responsible for: * Receiving and verifying messages from Ethereum * Converting those messages to XCM * Forwarding the XCMs to AssetHub * Adds pallet `snowbridge-pallet-outbound-queue-v2` which is responsible for: * Receiving XCMs from AH or governance messages from `snowbridge-pallet-system-v2` * Converting those XCMs to messages that can be interpreted on Ethereum (our Gateway contract specifically) * Adds pallet `snowbridge-pallet-system-v2` which is the governance controlplane for V2 * The primitives crates for V1 and V2 have been refactored and consolidated: * Added pallet `snowbridge-inbound-queue-primitives` with all primitives for the inbound path for V1 and V2. * Added pallet `snowbridge-outbound-queue-primitives` with all primitives for the outbound path for V1 and V2. Note that much of the code for the inbound-queue and outbound-queue pallets is derived from the original V1 pallets. ## AssetHub * Adds pallet `snowbridge-pallet-system-frontend`. This pallet acts as a proxy for `snowbridge-pallet-system-v2` on BH, and allows any AH account to interface with the V2 controlplane without having to interact with BH in any manner. ## Supported messaging functionality ### Ethereum->Polkadot * Users can transfer up to 8 ERC20 tokens, as well as native ether * Users can provide an arbitrary xcm message The assets will placed into holding on AH, and the user-supplied XCM is responsible for handling those assets in holding. For reference, see the inbound message [format]( https://github.com/vgeddes/polkadot-sdk/blob/387c72546be38763a2d3c9b52c0f6cc1d8ac707e/bridges/snowbridge/primitives/inbound-queue/src/v2/message.rs#L101). ### Polkadot->Ethereum Users can provide an XCM that includes: * Transfers for up to 7 Polkadot-native or Ethereum-native assets registered on AH. * A single `Transact` instruction to call an Ethereum mainnet contract These XCM instructions are converted to a batch of commands that are executed on the Ethereum side. For reference, see the outbound message [format](https://github.com/vgeddes/polkadot-sdk/blob/387c72546be38763a2d3c9b52c0f6cc1d8ac707e/bridges/snowbridge/primitives/outbound-queue/src/v2/message.rs#L122) ## Relayer Incentivization BH holds wrapped ether that will be used to reward relayers for both the inbound and outbound directions. When a reward is marked as claimable, it can be minted on AH when the beneficiary desires to do so. ### Ethereum->Polkadot Users supply an an arbitrary reward in ether on Ethereum. This is included in the message sent to BH, where it added as a reward for the relayer. The relayer can claim these rewards on AH at a later point using the `pallet-bridge-relayers` API. ### Polkadot->Ethereum Users supply an an arbitrary reward in wrapped ether using their funds on AH. When the message is committed for delivery on BH, this reward is tracked in `outbound_queue_v2::PendingOrders[MessageNonce]` After a relayer has delivered the message to Ethereum and forwarded the delivery receipt back to `outbound-queue-v2`, the reward will be rendered claimable, and the relayer can claim these rewards on AH at a later point using the `pallet-bridge-relayers` API. --------- Signed-off-by: Adrian Catangiu <[email protected]> Co-authored-by: claravanstaden <[email protected]> Co-authored-by: ron <[email protected]> Co-authored-by: Adrian Catangiu <[email protected]>
1 parent b82ef54 commit 98c6ffc

File tree

194 files changed

+15485
-2573
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

194 files changed

+15485
-2573
lines changed

Cargo.lock

Lines changed: 277 additions & 34 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 38 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -49,18 +49,28 @@ members = [
4949
"bridges/snowbridge/pallets/ethereum-client",
5050
"bridges/snowbridge/pallets/ethereum-client/fixtures",
5151
"bridges/snowbridge/pallets/inbound-queue",
52+
"bridges/snowbridge/pallets/inbound-queue-v2",
53+
"bridges/snowbridge/pallets/inbound-queue-v2/fixtures",
5254
"bridges/snowbridge/pallets/inbound-queue/fixtures",
5355
"bridges/snowbridge/pallets/outbound-queue",
54-
"bridges/snowbridge/pallets/outbound-queue/merkle-tree",
56+
"bridges/snowbridge/pallets/outbound-queue-v2",
57+
"bridges/snowbridge/pallets/outbound-queue-v2/runtime-api",
5558
"bridges/snowbridge/pallets/outbound-queue/runtime-api",
5659
"bridges/snowbridge/pallets/system",
60+
"bridges/snowbridge/pallets/system-frontend",
61+
"bridges/snowbridge/pallets/system-v2",
62+
"bridges/snowbridge/pallets/system-v2/runtime-api",
5763
"bridges/snowbridge/pallets/system/runtime-api",
5864
"bridges/snowbridge/primitives/beacon",
5965
"bridges/snowbridge/primitives/core",
6066
"bridges/snowbridge/primitives/ethereum",
61-
"bridges/snowbridge/primitives/router",
67+
"bridges/snowbridge/primitives/inbound-queue",
68+
"bridges/snowbridge/primitives/merkle-tree",
69+
"bridges/snowbridge/primitives/outbound-queue",
70+
"bridges/snowbridge/primitives/verification",
6271
"bridges/snowbridge/runtime/runtime-common",
6372
"bridges/snowbridge/runtime/test-common",
73+
"bridges/snowbridge/test-utils",
6474
"cumulus/bin/pov-validator",
6575
"cumulus/client/cli",
6676
"cumulus/client/collator",
@@ -823,7 +833,14 @@ http = { version = "1.1" }
823833
http-body = { version = "1", default-features = false }
824834
http-body-util = { version = "0.1.2", default-features = false }
825835
hyper = { version = "1.3.1", default-features = false }
826-
hyper-rustls = { version = "0.27.3", default-features = false, features = ["http1", "http2", "logging", "ring", "rustls-native-certs", "tls12"] }
836+
hyper-rustls = { version = "0.27.3", default-features = false, features = [
837+
"http1",
838+
"http2",
839+
"logging",
840+
"ring",
841+
"rustls-native-certs",
842+
"tls12",
843+
] }
827844
hyper-util = { version = "0.1.5", default-features = false }
828845
impl-serde = { version = "0.5.0", default-features = false }
829846
impl-trait-for-tuples = { version = "0.2.2" }
@@ -1149,7 +1166,12 @@ rstest = { version = "0.18.2" }
11491166
rustc-hash = { version = "1.1.0" }
11501167
rustc-hex = { version = "2.1.0", default-features = false }
11511168
rustix = { version = "0.36.7", default-features = false }
1152-
rustls = { version = "0.23.18", default-features = false, features = ["logging", "ring", "std", "tls12"] }
1169+
rustls = { version = "0.23.18", default-features = false, features = [
1170+
"logging",
1171+
"ring",
1172+
"std",
1173+
"tls12",
1174+
] }
11531175
rustversion = { version = "1.0.17" }
11541176
rusty-fork = { version = "0.3.0", default-features = false }
11551177
safe-mix = { version = "1.0", default-features = false }
@@ -1235,18 +1257,28 @@ smoldot-light = { version = "0.9.0", default-features = false }
12351257
snowbridge-beacon-primitives = { path = "bridges/snowbridge/primitives/beacon", default-features = false }
12361258
snowbridge-core = { path = "bridges/snowbridge/primitives/core", default-features = false }
12371259
snowbridge-ethereum = { path = "bridges/snowbridge/primitives/ethereum", default-features = false }
1238-
snowbridge-outbound-queue-merkle-tree = { path = "bridges/snowbridge/pallets/outbound-queue/merkle-tree", default-features = false }
1260+
snowbridge-inbound-queue-primitives = { path = "bridges/snowbridge/primitives/inbound-queue", default-features = false }
1261+
snowbridge-merkle-tree = { path = "bridges/snowbridge/primitives/merkle-tree", default-features = false }
1262+
snowbridge-outbound-queue-primitives = { path = "bridges/snowbridge/primitives/outbound-queue", default-features = false }
12391263
snowbridge-outbound-queue-runtime-api = { path = "bridges/snowbridge/pallets/outbound-queue/runtime-api", default-features = false }
1264+
snowbridge-outbound-queue-v2-runtime-api = { path = "bridges/snowbridge/pallets/outbound-queue-v2/runtime-api", default-features = false }
12401265
snowbridge-pallet-ethereum-client = { path = "bridges/snowbridge/pallets/ethereum-client", default-features = false }
12411266
snowbridge-pallet-ethereum-client-fixtures = { path = "bridges/snowbridge/pallets/ethereum-client/fixtures", default-features = false }
12421267
snowbridge-pallet-inbound-queue = { path = "bridges/snowbridge/pallets/inbound-queue", default-features = false }
12431268
snowbridge-pallet-inbound-queue-fixtures = { path = "bridges/snowbridge/pallets/inbound-queue/fixtures", default-features = false }
1269+
snowbridge-pallet-inbound-queue-v2 = { path = "bridges/snowbridge/pallets/inbound-queue-v2", default-features = false }
1270+
snowbridge-pallet-inbound-queue-v2-fixtures = { path = "bridges/snowbridge/pallets/inbound-queue-v2/fixtures", default-features = false }
12441271
snowbridge-pallet-outbound-queue = { path = "bridges/snowbridge/pallets/outbound-queue", default-features = false }
1272+
snowbridge-pallet-outbound-queue-v2 = { path = "bridges/snowbridge/pallets/outbound-queue-v2", default-features = false }
12451273
snowbridge-pallet-system = { path = "bridges/snowbridge/pallets/system", default-features = false }
1246-
snowbridge-router-primitives = { path = "bridges/snowbridge/primitives/router", default-features = false }
1274+
snowbridge-pallet-system-frontend = { path = "bridges/snowbridge/pallets/system-frontend", default-features = false }
1275+
snowbridge-pallet-system-v2 = { path = "bridges/snowbridge/pallets/system-v2", default-features = false }
12471276
snowbridge-runtime-common = { path = "bridges/snowbridge/runtime/runtime-common", default-features = false }
12481277
snowbridge-runtime-test-common = { path = "bridges/snowbridge/runtime/test-common", default-features = false }
12491278
snowbridge-system-runtime-api = { path = "bridges/snowbridge/pallets/system/runtime-api", default-features = false }
1279+
snowbridge-system-v2-runtime-api = { path = "bridges/snowbridge/pallets/system-v2/runtime-api", default-features = false }
1280+
snowbridge-test-utils = { path = "bridges/snowbridge/test-utils" }
1281+
snowbridge-verification-primitives = { path = "bridges/snowbridge/primitives/verification", default-features = false }
12501282
soketto = { version = "0.8.0" }
12511283
solochain-template-runtime = { path = "templates/solochain/runtime" }
12521284
sp-api = { path = "substrate/primitives/api", default-features = false }

bridges/chains/chain-asset-hub-rococo/Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ sp-core = { workspace = true }
2323

2424
# Bridge Dependencies
2525
bp-xcm-bridge-hub-router = { workspace = true }
26+
testnet-parachains-constants = { features = ["rococo"], workspace = true }
2627

2728
# Polkadot dependencies
2829
xcm = { workspace = true }
@@ -35,5 +36,6 @@ std = [
3536
"frame-support/std",
3637
"scale-info/std",
3738
"sp-core/std",
39+
"testnet-parachains-constants/std",
3840
"xcm/std",
3941
]

bridges/chains/chain-asset-hub-rococo/src/lib.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ use codec::{Decode, Encode};
2424
use scale_info::TypeInfo;
2525

2626
pub use bp_xcm_bridge_hub_router::XcmBridgeHubRouterCall;
27+
use testnet_parachains_constants::rococo::currency::UNITS;
2728
use xcm::latest::prelude::*;
2829

2930
/// `AssetHubRococo` Runtime `Call` enum.
@@ -45,6 +46,8 @@ pub enum Call {
4546
frame_support::parameter_types! {
4647
/// Some sane weight to execute `xcm::Transact(pallet-xcm-bridge-hub-router::Call::report_bridge_status)`.
4748
pub const XcmBridgeHubRouterTransactCallMaxWeight: frame_support::weights::Weight = frame_support::weights::Weight::from_parts(200_000_000, 6144);
49+
/// Should match the `AssetDeposit` of the `ForeignAssets` pallet on Asset Hub.
50+
pub const CreateForeignAssetDeposit: u128 = UNITS / 10;
4851
}
4952

5053
/// Builds an (un)congestion XCM program with the `report_bridge_status` call for

bridges/chains/chain-asset-hub-westend/Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ sp-core = { workspace = true }
2323

2424
# Bridge Dependencies
2525
bp-xcm-bridge-hub-router = { workspace = true }
26+
testnet-parachains-constants = { features = ["westend"], workspace = true }
2627

2728
# Polkadot dependencies
2829
xcm = { workspace = true }
@@ -35,5 +36,6 @@ std = [
3536
"frame-support/std",
3637
"scale-info/std",
3738
"sp-core/std",
39+
"testnet-parachains-constants/std",
3840
"xcm/std",
3941
]

bridges/chains/chain-asset-hub-westend/src/lib.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ use codec::{Decode, Encode};
2424
use scale_info::TypeInfo;
2525

2626
pub use bp_xcm_bridge_hub_router::XcmBridgeHubRouterCall;
27+
use testnet_parachains_constants::westend::currency::UNITS;
2728
use xcm::latest::prelude::*;
2829

2930
/// `AssetHubWestend` Runtime `Call` enum.
@@ -45,6 +46,9 @@ pub enum Call {
4546
frame_support::parameter_types! {
4647
/// Some sane weight to execute `xcm::Transact(pallet-xcm-bridge-hub-router::Call::report_bridge_status)`.
4748
pub const XcmBridgeHubRouterTransactCallMaxWeight: frame_support::weights::Weight = frame_support::weights::Weight::from_parts(200_000_000, 6144);
49+
50+
/// Should match the `AssetDeposit` of the `ForeignAssets` pallet on Asset Hub.
51+
pub const CreateForeignAssetDeposit: u128 = UNITS / 10;
4852
}
4953

5054
/// Builds an (un)congestion XCM program with the `report_bridge_status` call for

bridges/snowbridge/pallets/ethereum-client/Cargo.toml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@ workspace = true
1414
[package.metadata.docs.rs]
1515
targets = ["x86_64-unknown-linux-gnu"]
1616

17+
[package.metadata.polkadot-sdk]
18+
exclude-from-umbrella = true
19+
1720
[dependencies]
1821
codec = { features = ["derive"], workspace = true }
1922
hex-literal = { optional = true, workspace = true, default-features = true }
@@ -34,6 +37,7 @@ pallet-timestamp = { optional = true, workspace = true }
3437
snowbridge-beacon-primitives = { workspace = true }
3538
snowbridge-core = { workspace = true }
3639
snowbridge-ethereum = { workspace = true }
40+
snowbridge-inbound-queue-primitives = { workspace = true }
3741
snowbridge-pallet-ethereum-client-fixtures = { optional = true, workspace = true }
3842
static_assertions = { workspace = true }
3943

@@ -60,6 +64,7 @@ std = [
6064
"snowbridge-beacon-primitives/std",
6165
"snowbridge-core/std",
6266
"snowbridge-ethereum/std",
67+
"snowbridge-inbound-queue-primitives/std",
6368
"snowbridge-pallet-ethereum-client-fixtures/std",
6469
"sp-core/std",
6570
"sp-io/std",
@@ -74,6 +79,7 @@ runtime-benchmarks = [
7479
"hex-literal",
7580
"pallet-timestamp?/runtime-benchmarks",
7681
"snowbridge-core/runtime-benchmarks",
82+
"snowbridge-inbound-queue-primitives/runtime-benchmarks",
7783
"snowbridge-pallet-ethereum-client-fixtures/runtime-benchmarks",
7884
"sp-runtime/runtime-benchmarks",
7985
]

bridges/snowbridge/pallets/ethereum-client/fixtures/Cargo.toml

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,14 @@ workspace = true
1414
[package.metadata.docs.rs]
1515
targets = ["x86_64-unknown-linux-gnu"]
1616

17+
[package.metadata.polkadot-sdk]
18+
exclude-from-umbrella = true
19+
1720
[dependencies]
1821
hex-literal = { workspace = true, default-features = true }
1922
snowbridge-beacon-primitives = { workspace = true }
2023
snowbridge-core = { workspace = true }
24+
snowbridge-inbound-queue-primitives = { workspace = true }
2125
sp-core = { workspace = true }
2226
sp-std = { workspace = true }
2327

@@ -26,7 +30,11 @@ default = ["std"]
2630
std = [
2731
"snowbridge-beacon-primitives/std",
2832
"snowbridge-core/std",
33+
"snowbridge-inbound-queue-primitives/std",
2934
"sp-core/std",
3035
"sp-std/std",
3136
]
32-
runtime-benchmarks = ["snowbridge-core/runtime-benchmarks"]
37+
runtime-benchmarks = [
38+
"snowbridge-core/runtime-benchmarks",
39+
"snowbridge-inbound-queue-primitives/runtime-benchmarks",
40+
]

bridges/snowbridge/pallets/ethereum-client/fixtures/src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use snowbridge_beacon_primitives::{
99
types::deneb, AncestryProof, BeaconHeader, ExecutionProof, NextSyncCommitteeUpdate,
1010
SyncAggregate, SyncCommittee, VersionedExecutionPayloadHeader,
1111
};
12-
use snowbridge_core::inbound::{InboundQueueFixture, Log, Message, Proof};
12+
use snowbridge_inbound_queue_primitives::{EventProof, InboundQueueFixture, Log, Proof};
1313
use sp_core::U256;
1414
use sp_std::{boxed::Box, vec};
1515

@@ -1227,7 +1227,7 @@ pub fn make_execution_proof() -> Box<ExecutionProof> {
12271227

12281228
pub fn make_inbound_fixture() -> InboundQueueFixture {
12291229
InboundQueueFixture {
1230-
message: Message {
1230+
event: EventProof {
12311231
event_log: Log {
12321232
address: hex!("eda338e4dc46038493b885327842fd3e301cab39").into(),
12331233
topics: vec![

bridges/snowbridge/pallets/ethereum-client/src/impls.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@ use frame_support::ensure;
55
use snowbridge_beacon_primitives::ExecutionProof;
66

77
use snowbridge_beacon_primitives::merkle_proof::{generalized_index_length, subtree_index};
8-
use snowbridge_core::inbound::{
8+
use snowbridge_ethereum::Receipt;
9+
use snowbridge_inbound_queue_primitives::{
910
VerificationError::{self, *},
1011
*,
1112
};
12-
use snowbridge_ethereum::Receipt;
1313

1414
impl<T: Config> Verifier for Pallet<T> {
1515
/// Verify a message by verifying the existence of the corresponding

0 commit comments

Comments
 (0)