From 3c4bec4d9f9c2e29e29021ca36557e6c30b314e6 Mon Sep 17 00:00:00 2001 From: Alistair Singh Date: Thu, 27 Jul 2023 14:47:42 +0200 Subject: [PATCH] Revert "Use hashed description (#884)" (#906) This reverts commit d26678debcac6048c2c7dd2db54c06687575661e. --- cumulus | 2 +- parachain/Cargo.lock | 60 ++++--------------- parachain/primitives/router/Cargo.toml | 3 - .../primitives/router/src/inbound/mod.rs | 58 +++++++++--------- smoketest/tests/create_token.rs | 4 +- smoketest/tests/lock_tokens.rs | 6 +- 6 files changed, 45 insertions(+), 88 deletions(-) diff --git a/cumulus b/cumulus index 9b83c7325df5e..825df854624bd 160000 --- a/cumulus +++ b/cumulus @@ -1 +1 @@ -Subproject commit 9b83c7325df5ec50fec2571f8ff304d40a7e88fe +Subproject commit 825df854624bdca89ae7cd47c0d77892a502f96b diff --git a/parachain/Cargo.lock b/parachain/Cargo.lock index a446032731625..0bb6b50fcf310 100644 --- a/parachain/Cargo.lock +++ b/parachain/Cargo.lock @@ -274,9 +274,9 @@ dependencies = [ [[package]] name = "bounded-collections" -version = "0.1.8" +version = "0.1.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "eb5b05133427c07c4776906f673ccf36c21b102c9829c641a5b56bd151d44fd6" +checksum = "07fbd1d11282a1eb134d3c3b7cf8ce213b5161c6e5f73fb1b98618482c606b64" dependencies = [ "log", "parity-scale-codec", @@ -1889,22 +1889,6 @@ dependencies = [ "sp-timestamp", ] -[[package]] -name = "pallet-transaction-payment" -version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=master#e976964644d951a1eefaaa85f1d7c7d58211ddf7" -dependencies = [ - "frame-support", - "frame-system", - "parity-scale-codec", - "scale-info", - "serde", - "sp-core", - "sp-io", - "sp-runtime", - "sp-std", -] - [[package]] name = "parity-bytes" version = "0.1.2" @@ -1913,9 +1897,9 @@ checksum = "16b56e3a2420138bdb970f84dfb9c774aea80fa0e7371549eedec0d80c209c67" [[package]] name = "parity-scale-codec" -version = "3.6.3" +version = "3.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "756d439303e94fae44f288ba881ad29670c65b0c4b0e05674ca81061bb65f2c5" +checksum = "637935964ff85a605d114591d4d2c13c5d1ba2806dae97cea6bf180238a749ac" dependencies = [ "arrayvec 0.7.2", "bitvec", @@ -1928,9 +1912,9 @@ dependencies = [ [[package]] name = "parity-scale-codec-derive" -version = "3.6.3" +version = "3.1.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9d884d78fcf214d70b1e239fcd1c6e5e95aa3be1881918da2e488cc946c7a476" +checksum = "86b26a931f824dd4eca30b3e43bb4f31cd5f0d3a403c5f5ff27106b805bfde7b" dependencies = [ "proc-macro-crate", "proc-macro2", @@ -2091,9 +2075,9 @@ dependencies = [ [[package]] name = "proc-macro2" -version = "1.0.66" +version = "1.0.59" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "18fb31db3f9bddb2ea821cde30a9f70117e3f119938b5ee630b7403aa6e2ead9" +checksum = "6aeca18b86b413c660b781aa319e4e2648a3e6f9eadc9b47e9038e6fe9f3451b" dependencies = [ "unicode-ident", ] @@ -2109,9 +2093,9 @@ dependencies = [ [[package]] name = "quote" -version = "1.0.31" +version = "1.0.28" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5fe8a65d69dd0808184ebb5f836ab526bb259db23c657efa38711b1072ee47f0" +checksum = "1b9ab9c7eadfd8df19006f1cf1a4aed13540ed5cbc047010ece5826e10825488" dependencies = [ "proc-macro2", ] @@ -2817,7 +2801,6 @@ dependencies = [ "sp-runtime", "sp-std", "xcm", - "xcm-builder", "xcm-executor", ] @@ -4136,35 +4119,12 @@ dependencies = [ "xcm-procedural", ] -[[package]] -name = "xcm-builder" -version = "0.9.43" -source = "git+https://github.com/paritytech/polkadot?branch=master#b6b74fdf546c14bf9ac93c03916abda9ee33a52f" -dependencies = [ - "frame-support", - "frame-system", - "impl-trait-for-tuples", - "log", - "pallet-transaction-payment", - "parity-scale-codec", - "polkadot-parachain", - "scale-info", - "sp-arithmetic", - "sp-io", - "sp-runtime", - "sp-std", - "sp-weights", - "xcm", - "xcm-executor", -] - [[package]] name = "xcm-executor" version = "0.9.43" source = "git+https://github.com/paritytech/polkadot?branch=master#b6b74fdf546c14bf9ac93c03916abda9ee33a52f" dependencies = [ "environmental", - "frame-benchmarking", "frame-support", "impl-trait-for-tuples", "log", diff --git a/parachain/primitives/router/Cargo.toml b/parachain/primitives/router/Cargo.toml index 33b0b99e18bcc..6d54a747dfc51 100644 --- a/parachain/primitives/router/Cargo.toml +++ b/parachain/primitives/router/Cargo.toml @@ -18,7 +18,6 @@ sp-std = { git = "https://github.com/paritytech/substrate.git", branch = "master xcm = { git = "https://github.com/paritytech/polkadot.git", branch = "master", default-features = false } xcm-executor = { git = "https://github.com/paritytech/polkadot.git", branch = "master", default-features = false } -xcm-builder = { git = "https://github.com/paritytech/polkadot.git", branch = "master", default-features = false } snowbridge-core = { path = "../../primitives/core", default-features = false } @@ -43,11 +42,9 @@ std = [ "sp-std/std", "xcm/std", "xcm-executor/std", - "xcm-builder/std", "snowbridge-core/std", "ethabi/std", ] runtime-benchmarks = [ "snowbridge-core/runtime-benchmarks", - "xcm-builder/runtime-benchmarks", ] diff --git a/parachain/primitives/router/src/inbound/mod.rs b/parachain/primitives/router/src/inbound/mod.rs index 17bac1969478b..c653859488c89 100644 --- a/parachain/primitives/router/src/inbound/mod.rs +++ b/parachain/primitives/router/src/inbound/mod.rs @@ -4,10 +4,10 @@ use codec::{Decode, Encode}; use core::marker::PhantomData; use frame_support::{traits::ContainsPair, weights::Weight}; use sp_core::{Get, RuntimeDebug, H160}; +use sp_io::hashing::blake2_256; use sp_runtime::MultiAddress; use sp_std::prelude::*; use xcm::v3::{prelude::*, Junction::AccountKey20}; -use xcm_builder::{DescribeLocation, HashedDescription}; use xcm_executor::traits::ConvertLocation; const MINIMUM_DEPOSIT: u128 = 1; @@ -62,8 +62,6 @@ pub enum NativeTokensMessage { pub enum ConvertError { /// Message is in the wrong format BadFormat, - // Origin conversion failed. - BadOrigin, } impl TryInto> for MessageV1 { @@ -103,17 +101,10 @@ impl NativeTokensMessage { create_call_index, set_metadata_call_index, } => { - let owner = - GlobalConsensusEthereumAccountConvertsFor::<[u8; 32]>::convert_location( - &MultiLocation::new( - 2, - ( - GlobalConsensus(network), - AccountKey20 { network: None, key: *origin.as_fixed_bytes() }, - ), - ), - ) - .ok_or(ConvertError::BadOrigin)?; + let owner = GlobalConsensusEthereumAccountConvertsFor::<[u8; 32]>::from_params( + &chain_id, + origin.as_fixed_bytes(), + ); let origin_location = Junction::AccountKey20 { network: None, key: origin.into() }; @@ -233,21 +224,6 @@ impl NativeTokensMessage { } } -pub struct DescribeEthereumAccountKey20Terminal; -impl DescribeLocation for DescribeEthereumAccountKey20Terminal { - fn describe_location(l: &MultiLocation) -> Option> { - match (l.parents, &l.interior) { - (_, X2(GlobalConsensus(Ethereum { chain_id }), AccountKey20 { key, .. })) => { - Some((b"ethereum", chain_id, key).encode()) - }, - _ => return None, - } - } -} - -pub type GlobalConsensusEthereumAccountConvertsFor = - HashedDescription; - pub struct FromEthereumGlobalConsensus(PhantomData); impl ContainsPair for FromEthereumGlobalConsensus @@ -259,6 +235,30 @@ where } } +pub struct GlobalConsensusEthereumAccountConvertsFor(PhantomData); +impl ConvertLocation for GlobalConsensusEthereumAccountConvertsFor +where + AccountId: From<[u8; 32]> + Clone, +{ + fn convert_location(location: &MultiLocation) -> Option { + if let MultiLocation { + interior: X2(GlobalConsensus(Ethereum { chain_id }), AccountKey20 { key, .. }), + .. + } = location + { + Some(Self::from_params(chain_id, key).into()) + } else { + None + } + } +} + +impl GlobalConsensusEthereumAccountConvertsFor { + fn from_params(chain_id: &u64, key: &[u8; 20]) -> [u8; 32] { + (b"ethereum", chain_id, key).using_encoded(blake2_256) + } +} + #[cfg(test)] mod tests { use super::{FromEthereumGlobalConsensus, GlobalConsensusEthereumAccountConvertsFor}; diff --git a/smoketest/tests/create_token.rs b/smoketest/tests/create_token.rs index a22e37abf84e2..0873ac77e0ce1 100644 --- a/smoketest/tests/create_token.rs +++ b/smoketest/tests/create_token.rs @@ -13,8 +13,8 @@ use ethers::{ // contracts are deployed in DeployScript.sol. const ETHEREUM_API: &str = "http://localhost:8545"; const ETHEREUM_KEY: &str = "0x5e002a1af63fd31f1c25258f3082dc889762664cb8f218d86da85dff8b07b342"; -const NATIVE_TOKENS_CONTRACT: &str = "0xB8EA8cB425d85536b158d661da1ef0895Bb92F1D"; -const WETH_CONTRACT: &str = "0x3f0839385DB9cBEa8E73AdA6fa0CFe07E321F61d"; +const NATIVE_TOKENS_CONTRACT: &str = "0x8cF6147918A5CBb672703F879f385036f8793a24"; +const WETH_CONTRACT: &str = "0x440eDFFA1352B13227e8eE646f3Ea37456deC701"; #[tokio::test] async fn create_tokens() { diff --git a/smoketest/tests/lock_tokens.rs b/smoketest/tests/lock_tokens.rs index cb5908a076bd7..9c27df05820df 100644 --- a/smoketest/tests/lock_tokens.rs +++ b/smoketest/tests/lock_tokens.rs @@ -18,9 +18,9 @@ use xcm::v3::{MultiLocation, Junction, Junctions::X1}; // contracts are deployed in DeployScript.sol. const ETHEREUM_API: &str = "http://localhost:8545"; const ETHEREUM_KEY: &str = "0x5e002a1af63fd31f1c25258f3082dc889762664cb8f218d86da85dff8b07b342"; -const TOKEN_VAULT_CONTRACT: &str = "0xB1185EDE04202fE62D38F5db72F71e38Ff3E8305"; -const NATIVE_TOKENS_CONTRACT: &str = "0xB8EA8cB425d85536b158d661da1ef0895Bb92F1D"; -const WETH_CONTRACT: &str = "0x3f0839385DB9cBEa8E73AdA6fa0CFe07E321F61d"; +const TOKEN_VAULT_CONTRACT: &str = "0xB8EA8cB425d85536b158d661da1ef0895Bb92F1D"; +const NATIVE_TOKENS_CONTRACT: &str = "0x8cF6147918A5CBb672703F879f385036f8793a24"; +const WETH_CONTRACT: &str = "0x440eDFFA1352B13227e8eE646f3Ea37456deC701"; // SS58: DE14BzQ1bDXWPKeLoAqdLAm1GpyAWaWF1knF74cEZeomTBM const FERDIE: [u8; 32] = hex!("1cbd2d43530a44705ad088af313e18f80b53ef16b36177cd4b77b846f2a5f07c");