From bc52d555c36d2470a3237eab173bdd49c7d68aa2 Mon Sep 17 00:00:00 2001 From: Vincent Geddes Date: Sun, 30 Jul 2023 14:37:13 +0100 Subject: [PATCH] Proxy contracts (#55) * Fix cumulus builds * Update cumulus (#46) * Create Agent (#47) * add hashed description * use existing account * add call filter * Create Agent (#48) * initial * update cargo lock * handle local accounts and pallets * Add set_gateway to safe call filter (#49) * Fix cumulus bridgehub runtime for proxy contracts. (#50) Co-authored-by: claravanstaden * Update inbound queue benchmarks. (#51) * Update inbound queue benchmarks. * Update inbound queue benchmarks. --------- Co-authored-by: claravanstaden * Asset transfer (#52) * update registry to gateway * added agent config * ws * increase message size --------- Co-authored-by: David Dunn <26876072+doubledup@users.noreply.github.com> Co-authored-by: Ron Co-authored-by: Alistair Singh Co-authored-by: Clara van Staden --- Cargo.lock | 3 ++ .../assets/asset-hub-kusama/src/lib.rs | 2 +- .../assets/asset-hub-kusama/src/xcm_config.rs | 10 ++--- .../bridge-hubs/bridge-hub-rococo/Cargo.toml | 1 + .../bridge-hubs/bridge-hub-rococo/src/lib.rs | 26 ++++++++----- .../src/weights/snowbridge_inbound_queue.rs | 20 +++++----- .../bridge-hub-rococo/src/xcm_config.rs | 38 +++++++++++-------- .../src/chain_spec/bridge_hubs.rs | 3 +- 8 files changed, 61 insertions(+), 42 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 91c994fd6f3..71d6eab4a6e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -13350,12 +13350,15 @@ dependencies = [ "sp-runtime", "sp-std", "xcm", + "xcm-builder", + "xcm-executor", ] [[package]] name = "snowbridge-core" version = "0.1.1" dependencies = [ + "ethabi-decode", "frame-support", "frame-system", "parity-scale-codec", diff --git a/parachains/runtimes/assets/asset-hub-kusama/src/lib.rs b/parachains/runtimes/assets/asset-hub-kusama/src/lib.rs index f33b38aa2a7..8858e1baebf 100644 --- a/parachains/runtimes/assets/asset-hub-kusama/src/lib.rs +++ b/parachains/runtimes/assets/asset-hub-kusama/src/lib.rs @@ -304,7 +304,7 @@ impl pallet_assets::Config for Runtime { ( FromSiblingParachain>, snowbridge_router_primitives::inbound::FromEthereumGlobalConsensus< - crate::bridging::EthereumRegistryLocation, + crate::bridging::EthereumGatewayLocation, >, ), ForeignCreatorsSovereignAccountOf, diff --git a/parachains/runtimes/assets/asset-hub-kusama/src/xcm_config.rs b/parachains/runtimes/assets/asset-hub-kusama/src/xcm_config.rs index d6eda78ca10..12ad726a544 100644 --- a/parachains/runtimes/assets/asset-hub-kusama/src/xcm_config.rs +++ b/parachains/runtimes/assets/asset-hub-kusama/src/xcm_config.rs @@ -540,11 +540,11 @@ pub mod bridging { pub EthereumLocation: MultiLocation = MultiLocation::new(2, X1(GlobalConsensus(EthereumNetwork::get()))); // The Registry contract for the bridge which is also the origin for reserves and the prefix of all assets. - pub EthereumRegistryLocation: MultiLocation = EthereumLocation::get() + pub EthereumGatewayLocation: MultiLocation = EthereumLocation::get() .pushed_with_interior( AccountKey20 { network: None, - key: hex_literal::hex!("D184c103F7acc340847eEE82a0B909E3358bc28d"), + key: hex_literal::hex!("EDa338E4dC46038493b885327842fD3E301CaB39"), } ).unwrap(); @@ -604,14 +604,14 @@ pub mod bridging { EthereumLocation::get(), AssetFilter::ByMultiLocation( MultiLocationFilter::default() - .add_starts_with(EthereumRegistryLocation::get()) + .add_starts_with(EthereumGatewayLocation::get()) ) ), ( - EthereumRegistryLocation::get(), + EthereumGatewayLocation::get(), AssetFilter::ByMultiLocation( MultiLocationFilter::default() - .add_starts_with(EthereumRegistryLocation::get()) + .add_starts_with(EthereumGatewayLocation::get()) ) ), ]; diff --git a/parachains/runtimes/bridge-hubs/bridge-hub-rococo/Cargo.toml b/parachains/runtimes/bridge-hubs/bridge-hub-rococo/Cargo.toml index 6b4becc57f2..d77f5ab3990 100644 --- a/parachains/runtimes/bridge-hubs/bridge-hub-rococo/Cargo.toml +++ b/parachains/runtimes/bridge-hubs/bridge-hub-rococo/Cargo.toml @@ -208,6 +208,7 @@ runtime-benchmarks = [ "cumulus-pallet-session-benchmarking/runtime-benchmarks", "cumulus-pallet-xcmp-queue/runtime-benchmarks", "pallet-xcm-benchmarks/runtime-benchmarks", + "snowbridge-control/runtime-benchmarks", "snowbridge-core/runtime-benchmarks", "snowbridge-inbound-queue/runtime-benchmarks", "snowbridge-outbound-queue/runtime-benchmarks", diff --git a/parachains/runtimes/bridge-hubs/bridge-hub-rococo/src/lib.rs b/parachains/runtimes/bridge-hubs/bridge-hub-rococo/src/lib.rs index b0e717eaca0..64021565c81 100644 --- a/parachains/runtimes/bridge-hubs/bridge-hub-rococo/src/lib.rs +++ b/parachains/runtimes/bridge-hubs/bridge-hub-rococo/src/lib.rs @@ -31,6 +31,7 @@ pub mod xcm_config; use constants::currency::*; use cumulus_pallet_parachain_system::RelayNumberStrictlyIncreases; use snowbridge_beacon_primitives::{Fork, ForkVersions}; +use snowbridge_router_primitives::outbound::AgentHashedDescription; use sp_api::impl_runtime_apis; use sp_core::{crypto::KeyTypeId, OpaqueMetadata}; use sp_runtime::{ @@ -67,9 +68,13 @@ use frame_system::{ limits::{BlockLength, BlockWeights}, EnsureRoot, }; + +use pallet_xcm::EnsureXcm; + pub use sp_consensus_aura::sr25519::AuthorityId as AuraId; pub use sp_runtime::{MultiAddress, Perbill, Permill}; -use xcm_config::{XcmConfig, XcmOriginToTransactDispatchOrigin}; +use xcm::v3::NetworkId::{self, Rococo}; +use xcm_config::{RelayLocation, UniversalLocation, XcmConfig, XcmOriginToTransactDispatchOrigin}; use bp_parachains::SingleParaStoredHeaderDataBuilder; use bp_runtime::HeaderId; @@ -77,8 +82,6 @@ use bp_runtime::HeaderId; #[cfg(any(feature = "std", test))] pub use sp_runtime::BuildStorage; -pub use snowbridge_core::MessageId; - use polkadot_runtime_common::{BlockHashCount, SlowAdjustingFeeUpdate}; use weights::{BlockExecutionWeight, ExtrinsicBaseWeight, RocksDbWeight}; @@ -589,18 +592,17 @@ impl BenchmarkHelper for Runtim impl snowbridge_inbound_queue::Config for Runtime { type RuntimeEvent = RuntimeEvent; + type Verifier = snowbridge_ethereum_beacon_client::Pallet; type Token = Balances; type Reward = Reward; - type Verifier = snowbridge_ethereum_beacon_client::Pallet; type XcmSender = XcmRouter; type WeightInfo = weights::snowbridge_inbound_queue::WeightInfo; - type AllowListLength = ConstU32<8>; #[cfg(feature = "runtime-benchmarks")] type Helper = Runtime; } parameter_types! { - pub const MaxMessagePayloadSize: u32 = 256; + pub const MaxMessagePayloadSize: u32 = 512; pub const MaxMessagesPerBlock: u32 = 32; } @@ -667,16 +669,22 @@ impl snowbridge_ethereum_beacon_client::Config for Runtime { } parameter_types! { - pub const GovernanceProxyContract: snowbridge_core::ContractId = snowbridge_core::ContractId::new(hex_literal::hex!("44bef07c29162ad04096f5cbe78ca2df62dffe97cea85825f08d13319e13f34a")); + // TODO: placeholder value - choose a real one + pub const MaxUpgradeDataSize: u32 = 1024; + pub const RelayNetwork: NetworkId = Rococo; } impl snowbridge_control::Config for Runtime { type RuntimeEvent = RuntimeEvent; type OwnParaId = ParachainInfo; type OutboundQueue = EthereumOutboundQueue; - type GovernanceProxyContract = GovernanceProxyContract; type MessageHasher = BlakeTwo256; type WeightInfo = (); + type MaxUpgradeDataSize = MaxUpgradeDataSize; + type CreateAgentOrigin = EnsureXcm; + type AgentHashedDescription = AgentHashedDescription; + type UniversalLocation = UniversalLocation; + type RelayLocation = RelayLocation; } // Create the runtime by composing the FRAME pallets that were previously configured. @@ -732,7 +740,7 @@ construct_runtime!( BridgeRelayers: pallet_bridge_relayers::{Pallet, Call, Storage, Event} = 47, // Ethereum Bridge - EthereumInboundQueue: snowbridge_inbound_queue::{Pallet, Call, Config, Storage, Event} = 48, + EthereumInboundQueue: snowbridge_inbound_queue::{Pallet, Call, Config, Storage, Event} = 48, EthereumOutboundQueue: snowbridge_outbound_queue::{Pallet, Call, Storage, Event} = 49, EthereumBeaconClient: snowbridge_ethereum_beacon_client::{Pallet, Call, Storage, Event} = 50, EthereumControl: snowbridge_control::{Pallet, Call, Storage, Event} = 51, diff --git a/parachains/runtimes/bridge-hubs/bridge-hub-rococo/src/weights/snowbridge_inbound_queue.rs b/parachains/runtimes/bridge-hubs/bridge-hub-rococo/src/weights/snowbridge_inbound_queue.rs index 9da9c0ef16e..830b978ea7f 100644 --- a/parachains/runtimes/bridge-hubs/bridge-hub-rococo/src/weights/snowbridge_inbound_queue.rs +++ b/parachains/runtimes/bridge-hubs/bridge-hub-rococo/src/weights/snowbridge_inbound_queue.rs @@ -2,7 +2,7 @@ //! Autogenerated weights for `snowbridge_inbound_queue` //! //! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev -//! DATE: 2023-07-14, STEPS: `50`, REPEAT: `20`, LOW RANGE: `[]`, HIGH RANGE: `[]` +//! DATE: 2023-07-25, STEPS: `50`, REPEAT: `20`, LOW RANGE: `[]`, HIGH RANGE: `[]` //! WORST CASE MAP SIZE: `1000000` //! HOSTNAME: `Claras-MacBook-Pro-2.local`, CPU: `` //! EXECUTION: Some(Wasm), WASM-EXECUTION: Compiled, CHAIN: Some("bridge-hub-rococo-dev"), DB CACHE: 1024 @@ -34,10 +34,12 @@ use core::marker::PhantomData; /// Weight functions for `snowbridge_inbound_queue`. pub struct WeightInfo(PhantomData); impl snowbridge_inbound_queue::WeightInfo for WeightInfo { + /// Storage: EthereumInboundQueue PalletOperatingMode (r:1 w:0) + /// Proof: EthereumInboundQueue PalletOperatingMode (max_values: Some(1), max_size: Some(1), added: 496, mode: MaxEncodedLen) /// Storage: EthereumBeaconClient ExecutionHeaders (r:1 w:0) /// Proof: EthereumBeaconClient ExecutionHeaders (max_values: None, max_size: Some(136), added: 2611, mode: MaxEncodedLen) - /// Storage: EthereumInboundQueue AllowList (r:1 w:0) - /// Proof: EthereumInboundQueue AllowList (max_values: Some(1), max_size: Some(161), added: 656, mode: MaxEncodedLen) + /// Storage: EthereumInboundQueue Gateway (r:1 w:0) + /// Proof: EthereumInboundQueue Gateway (max_values: Some(1), max_size: Some(20), added: 515, mode: MaxEncodedLen) /// Storage: EthereumInboundQueue Nonce (r:1 w:1) /// Proof: EthereumInboundQueue Nonce (max_values: None, max_size: Some(20), added: 2495, mode: MaxEncodedLen) /// Storage: System Account (r:1 w:1) @@ -54,12 +56,12 @@ impl snowbridge_inbound_queue::WeightInfo for WeightInf /// Proof Skipped: ParachainSystem RelevantMessagingState (max_values: Some(1), max_size: None, mode: Measured) fn submit() -> Weight { // Proof Size summary in bytes: - // Measured: `577` - // Estimated: `4042` - // Minimum execution time: 118_000_000 picoseconds. - Weight::from_parts(125_000_000, 0) - .saturating_add(Weight::from_parts(0, 4042)) - .saturating_add(T::DbWeight::get().reads(9)) + // Measured: `575` + // Estimated: `4040` + // Minimum execution time: 98_000_000 picoseconds. + Weight::from_parts(107_000_000, 0) + .saturating_add(Weight::from_parts(0, 4040)) + .saturating_add(T::DbWeight::get().reads(10)) .saturating_add(T::DbWeight::get().writes(4)) } } diff --git a/parachains/runtimes/bridge-hubs/bridge-hub-rococo/src/xcm_config.rs b/parachains/runtimes/bridge-hubs/bridge-hub-rococo/src/xcm_config.rs index 44cae66fe46..f99cafa9da7 100644 --- a/parachains/runtimes/bridge-hubs/bridge-hub-rococo/src/xcm_config.rs +++ b/parachains/runtimes/bridge-hubs/bridge-hub-rococo/src/xcm_config.rs @@ -33,14 +33,14 @@ use pallet_xcm::XcmPassthrough; use parachains_common::{impls::ToStakingPot, xcm_config::ConcreteNativeAssetFrom}; use polkadot_parachain::primitives::Sibling; use snowbridge_outbound_queue; -use snowbridge_router_primitives::outbound::EthereumBlobExporter; +use snowbridge_router_primitives::outbound::{AgentHashedDescription, EthereumBlobExporter}; use sp_core::Get; use xcm::latest::prelude::*; use xcm_builder::{ AccountId32Aliases, AllowExplicitUnpaidExecutionFrom, AllowKnownQueryResponses, AllowSubscriptionsFrom, AllowTopLevelPaidExecutionFrom, AllowUnpaidExecutionFrom, - CurrencyAdapter, DenyReserveTransferToRelayChain, DenyThenTry, EnsureXcmOrigin, IsConcrete, - ParentAsSuperuser, ParentIsPreset, RelayChainAsNative, SiblingParachainAsNative, + CurrencyAdapter, DenyReserveTransferToRelayChain, DenyThenTry, EnsureXcmOrigin, + IsConcrete, ParentAsSuperuser, ParentIsPreset, RelayChainAsNative, SiblingParachainAsNative, SiblingParachainConvertsVia, SignedAccountId32AsNative, SignedToAccountId32, SovereignSignedViaLocation, TakeWeightCredit, TrailingSetTopicAsId, UsingComponents, WeightInfoBounds, WithComputedOrigin, WithUniqueTopic, @@ -57,17 +57,17 @@ parameter_types! { X2(GlobalConsensus(RelayNetwork::get()), Parachain(ParachainInfo::parachain_id().into())); pub const MaxInstructions: u32 = 100; pub const MaxAssetsIntoHolding: u32 = 64; - + // Network and location for the local Ethereum testnet. pub const EthereumNetwork: NetworkId = NetworkId::Ethereum { chain_id: 15 }; pub EthereumLocation: MultiLocation = MultiLocation::new(2, X1(GlobalConsensus(EthereumNetwork::get()))); // The Registry contract for the bridge which is also the origin for reserves and the prefix of all assets. - pub EthereumRegistryLocation: MultiLocation = EthereumLocation::get() + pub EthereumGatewayLocation: MultiLocation = EthereumLocation::get() .pushed_with_interior( - AccountKey20 { - network: None, - key: hex_literal::hex!("D184c103F7acc340847eEE82a0B909E3358bc28d"), + AccountKey20 { + network: None, + key: hex_literal::hex!("EDa338E4dC46038493b885327842fD3E301CaB39"), } ).unwrap(); } @@ -213,14 +213,16 @@ impl Contains for SafeCallFilter { | snowbridge_ethereum_beacon_client::Call::set_owner { .. } | snowbridge_ethereum_beacon_client::Call::set_operating_mode { .. }, ) | RuntimeCall::EthereumInboundQueue( - snowbridge_inbound_queue::Call::add_allow_list { .. } - | snowbridge_inbound_queue::Call::remove_allow_list { .. } - | snowbridge_inbound_queue::Call::set_owner { .. } + snowbridge_inbound_queue::Call::set_owner { .. } + | snowbridge_inbound_queue::Call::set_gateway { .. } | snowbridge_inbound_queue::Call::set_operating_mode { .. }, ) | RuntimeCall::EthereumOutboundQueue( snowbridge_outbound_queue::Call::set_owner { .. } | snowbridge_outbound_queue::Call::set_operating_mode { .. }, - ) | RuntimeCall::EthereumControl(snowbridge_control::Call::upgrade { .. },) + ) | RuntimeCall::EthereumControl( + snowbridge_control::Call::upgrade { .. } + | snowbridge_control::Call::create_agent { .. }, + ) ) } } @@ -345,8 +347,12 @@ impl cumulus_pallet_xcm::Config for Runtime { type XcmExecutor = XcmExecutor; } -pub type SnowbridgeExporter = - EthereumBlobExporter>; +pub type SnowbridgeExporter = EthereumBlobExporter< + UniversalLocation, + EthereumGatewayLocation, + snowbridge_outbound_queue::Pallet, + AgentHashedDescription +>; /// Hacky switch implementation, because we have just one runtime for Rococo and Wococo BridgeHub, so it means we have just one XcmConfig pub struct BridgeHubRococoOrBridgeHubWococoSwitchExporter; @@ -386,7 +392,7 @@ impl ExportXcm for BridgeHubRococoOrBridgeHubWococoSwitchExporter { destination, message, ) - .map(|result| ((EthereumNetwork::get(), result.0), result.1)) + .map(|result| ((EthereumNetwork::get(), (result.0, XcmHash::default())), result.1)) }, _ => unimplemented!("Unsupported network: {:?}", network), } @@ -399,7 +405,7 @@ impl ExportXcm for BridgeHubRococoOrBridgeHubWococoSwitchExporter { Rococo => ToBridgeHubRococoHaulBlobExporter::deliver(ticket), Wococo => ToBridgeHubWococoHaulBlobExporter::deliver(ticket), location if location == EthereumNetwork::get() && relay == NetworkId::Rococo => { - SnowbridgeExporter::deliver(ticket) + SnowbridgeExporter::deliver(ticket.0) }, _ => unimplemented!("Unsupported network: {:?}", network), } diff --git a/polkadot-parachain/src/chain_spec/bridge_hubs.rs b/polkadot-parachain/src/chain_spec/bridge_hubs.rs index 2bbd661c8a4..cd43858da8a 100644 --- a/polkadot-parachain/src/chain_spec/bridge_hubs.rs +++ b/polkadot-parachain/src/chain_spec/bridge_hubs.rs @@ -341,8 +341,7 @@ pub mod rococo { }, // Ethereum Bridge ethereum_inbound_queue: bridge_hub_rococo_runtime::EthereumInboundQueueConfig { - allowlist: Default::default(), - owner: bridges_pallet_owner, + gateway: Default::default(), ..Default::default() }, }