From 77bff465e53e8cae9863ce6cd7da7974fa634fc2 Mon Sep 17 00:00:00 2001 From: Keith Yeung Date: Sat, 11 Sep 2021 15:15:30 -0700 Subject: [PATCH 1/4] Use DecodeLimit for decoding XCM messages --- Cargo.lock | 6 ++--- client/collator/Cargo.toml | 2 +- client/consensus/aura/Cargo.toml | 2 +- client/consensus/common/Cargo.toml | 2 +- client/consensus/relay-chain/Cargo.toml | 2 +- client/network/Cargo.toml | 2 +- client/pov-recovery/Cargo.toml | 2 +- client/service/Cargo.toml | 2 +- pallets/aura-ext/Cargo.toml | 2 +- pallets/collator-selection/Cargo.toml | 2 +- pallets/dmp-queue/Cargo.toml | 2 +- pallets/dmp-queue/src/lib.rs | 11 +++++---- pallets/parachain-system/Cargo.toml | 2 +- pallets/session-benchmarking/Cargo.toml | 2 +- pallets/xcm/Cargo.toml | 2 +- pallets/xcm/src/lib.rs | 21 +++++++++++----- pallets/xcmp-queue/Cargo.toml | 2 +- pallets/xcmp-queue/src/lib.rs | 24 ++++++++++++++----- polkadot-parachains/Cargo.toml | 2 +- .../pallets/parachain-info/Cargo.toml | 2 +- polkadot-parachains/pallets/ping/Cargo.toml | 2 +- .../parachains-common/Cargo.toml | 2 +- polkadot-parachains/rococo/Cargo.toml | 2 +- polkadot-parachains/shell/Cargo.toml | 2 +- polkadot-parachains/statemine/Cargo.toml | 2 +- polkadot-parachains/statemint/Cargo.toml | 2 +- polkadot-parachains/westmint/Cargo.toml | 2 +- primitives/core/Cargo.toml | 2 +- primitives/parachain-inherent/Cargo.toml | 2 +- primitives/timestamp/Cargo.toml | 2 +- primitives/utility/Cargo.toml | 2 +- test/client/Cargo.toml | 2 +- test/relay-sproof-builder/Cargo.toml | 2 +- test/runtime-upgrade/Cargo.toml | 2 +- test/runtime/Cargo.toml | 2 +- test/service/Cargo.toml | 2 +- 36 files changed, 75 insertions(+), 51 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index a04a1f39e9f..156b6ddd632 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -5985,9 +5985,9 @@ dependencies = [ [[package]] name = "parity-scale-codec" -version = "2.2.0" +version = "2.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8975095a2a03bbbdc70a74ab11a4f76a6d0b84680d87c68d722531b0ac28e8a9" +checksum = "e11263a97373b43da4b426edbb52ef99a7b51e2d9752ef56a7f8b356f48495a5" dependencies = [ "arrayvec 0.7.0", "bitvec 0.20.1", @@ -11576,7 +11576,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "04f8ab788026715fa63b31960869617cba39117e520eb415b0139543e325ab59" dependencies = [ "cfg-if 0.1.10", - "rand 0.3.23", + "rand 0.7.3", "static_assertions", ] diff --git a/client/collator/Cargo.toml b/client/collator/Cargo.toml index 68b579a1a5d..c47fcf6ea46 100644 --- a/client/collator/Cargo.toml +++ b/client/collator/Cargo.toml @@ -25,7 +25,7 @@ cumulus-client-consensus-common = { path = "../consensus/common" } cumulus-primitives-core = { path = "../../primitives/core" } # Other dependencies -codec = { package = "parity-scale-codec", version = "2.0.0", features = [ "derive" ] } +codec = { package = "parity-scale-codec", version = "2.3.0", features = [ "derive" ] } futures = { version = "0.3.1", features = ["compat"] } parking_lot = "0.10.2" tracing = "0.1.25" diff --git a/client/consensus/aura/Cargo.toml b/client/consensus/aura/Cargo.toml index c9a85165e86..5a4819f9cc4 100644 --- a/client/consensus/aura/Cargo.toml +++ b/client/consensus/aura/Cargo.toml @@ -33,7 +33,7 @@ cumulus-primitives-core = { path = "../../../primitives/core" } # Other deps futures = { version = "0.3.8", features = ["compat"] } -codec = { package = "parity-scale-codec", version = "2.0.0", features = [ "derive" ] } +codec = { package = "parity-scale-codec", version = "2.3.0", features = [ "derive" ] } tracing = "0.1.22" async-trait = "0.1.42" parking_lot = "0.10.2" diff --git a/client/consensus/common/Cargo.toml b/client/consensus/common/Cargo.toml index f7f4565ba64..14e3fc4b246 100644 --- a/client/consensus/common/Cargo.toml +++ b/client/consensus/common/Cargo.toml @@ -25,7 +25,7 @@ polkadot-runtime = { git = "https://github.com/paritytech/polkadot", branch = "m # Other deps futures = { version = "0.3.8", features = ["compat"] } -codec = { package = "parity-scale-codec", version = "2.0.0", features = [ "derive" ] } +codec = { package = "parity-scale-codec", version = "2.3.0", features = [ "derive" ] } tracing = "0.1.25" async-trait = "0.1.42" dyn-clone = "1.0.4" diff --git a/client/consensus/relay-chain/Cargo.toml b/client/consensus/relay-chain/Cargo.toml index 5486a3f0915..5e0450e035d 100644 --- a/client/consensus/relay-chain/Cargo.toml +++ b/client/consensus/relay-chain/Cargo.toml @@ -27,7 +27,7 @@ cumulus-primitives-core = { path = "../../../primitives/core" } # Other deps futures = { version = "0.3.8", features = ["compat"] } -codec = { package = "parity-scale-codec", version = "2.0.0", features = [ "derive" ] } +codec = { package = "parity-scale-codec", version = "2.3.0", features = [ "derive" ] } tracing = "0.1.22" async-trait = "0.1.42" parking_lot = "0.10.2" diff --git a/client/network/Cargo.toml b/client/network/Cargo.toml index d8d9bb2a6c8..9689659030a 100644 --- a/client/network/Cargo.toml +++ b/client/network/Cargo.toml @@ -22,7 +22,7 @@ polkadot-client = { git = "https://github.com/paritytech/polkadot", branch = "ma polkadot-parachain = { git = "https://github.com/paritytech/polkadot", branch = "master" } # other deps -codec = { package = "parity-scale-codec", version = "2.0.0", features = [ "derive" ] } +codec = { package = "parity-scale-codec", version = "2.3.0", features = [ "derive" ] } futures = { version = "0.3.1", features = ["compat"] } futures-timer = "3.0.2" tracing = "0.1.22" diff --git a/client/pov-recovery/Cargo.toml b/client/pov-recovery/Cargo.toml index bc4d506b5fa..08ba637303a 100644 --- a/client/pov-recovery/Cargo.toml +++ b/client/pov-recovery/Cargo.toml @@ -25,7 +25,7 @@ polkadot-node-subsystem = { git = "https://github.com/paritytech/polkadot", bran cumulus-primitives-core = { path = "../../primitives/core" } # other deps -codec = { package = "parity-scale-codec", version = "2.0.0", features = [ "derive" ] } +codec = { package = "parity-scale-codec", version = "2.3.0", features = [ "derive" ] } futures = { version = "0.3.1", features = ["compat"] } futures-timer = "3.0.2" tracing = "0.1.22" diff --git a/client/service/Cargo.toml b/client/service/Cargo.toml index 187e19c301d..051482ad34e 100644 --- a/client/service/Cargo.toml +++ b/client/service/Cargo.toml @@ -32,5 +32,5 @@ polkadot-overseer = { git = "https://github.com/paritytech/polkadot", branch = " # Other deps tracing = "0.1.22" -codec = { package = "parity-scale-codec", version = "2.0.0" } +codec = { package = "parity-scale-codec", version = "2.3.0" } parking_lot = "0.10.2" diff --git a/pallets/aura-ext/Cargo.toml b/pallets/aura-ext/Cargo.toml index 375977a8245..21bdc169fcc 100644 --- a/pallets/aura-ext/Cargo.toml +++ b/pallets/aura-ext/Cargo.toml @@ -17,7 +17,7 @@ sp-runtime = { git = "https://github.com/paritytech/substrate", default-features sp-application-crypto = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "master" } # Other Dependencies -codec = { package = "parity-scale-codec", version = "2.0.0", default-features = false, features = ["derive"]} +codec = { package = "parity-scale-codec", version = "2.3.0", default-features = false, features = ["derive"]} serde = { version = "1.0.101", optional = true, features = ["derive"] } [dev-dependencies] diff --git a/pallets/collator-selection/Cargo.toml b/pallets/collator-selection/Cargo.toml index 8849881345d..efe2e7fc67f 100644 --- a/pallets/collator-selection/Cargo.toml +++ b/pallets/collator-selection/Cargo.toml @@ -14,7 +14,7 @@ targets = ['x86_64-unknown-linux-gnu'] [dependencies] log = { version = "0.4.0", default-features = false } -codec = { default-features = false, features = ['derive'], package = 'parity-scale-codec', version = '2.0.0' } +codec = { default-features = false, features = ['derive'], package = 'parity-scale-codec', version = '2.3.0' } serde = { version = "1.0.119", default-features = false } sp-std = { default-features = false, git = 'https://github.com/paritytech/substrate', branch = "master" } sp-runtime = { default-features = false, git = 'https://github.com/paritytech/substrate', branch = "master" } diff --git a/pallets/dmp-queue/Cargo.toml b/pallets/dmp-queue/Cargo.toml index e1f4447730c..85123baaea2 100644 --- a/pallets/dmp-queue/Cargo.toml +++ b/pallets/dmp-queue/Cargo.toml @@ -6,7 +6,7 @@ edition = "2018" [dependencies] # Other dependencies -codec = { package = "parity-scale-codec", version = "2.0.0", features = [ "derive" ], default-features = false } +codec = { package = "parity-scale-codec", version = "2.3.0", features = [ "derive" ], default-features = false } log = { version = "0.4.14", default-features = false } rand = { version = "0.8.3", default-features = false } rand_chacha = { version = "0.3.0", default-features = false } diff --git a/pallets/dmp-queue/src/lib.rs b/pallets/dmp-queue/src/lib.rs index 81928bdb608..2fe2da90f14 100644 --- a/pallets/dmp-queue/src/lib.rs +++ b/pallets/dmp-queue/src/lib.rs @@ -24,9 +24,9 @@ use sp_std::{prelude::*, convert::TryFrom}; use cumulus_primitives_core::relay_chain::BlockNumber as RelayBlockNumber; use cumulus_primitives_core::DmpMessageHandler; -use codec::{Encode, Decode}; +use codec::{Decode, DecodeLimit, Encode}; use sp_runtime::RuntimeDebug; -use xcm::{VersionedXcm, latest::prelude::*}; +use xcm::{latest::prelude::*, MAX_XCM_DECODE_DEPTH, VersionedXcm}; use frame_support::{traits::EnsureOrigin, dispatch::Weight, weights::constants::WEIGHT_PER_MILLIS}; pub use pallet::*; @@ -233,8 +233,11 @@ pub mod pallet { data: &[u8], ) -> Result { let id = sp_io::hashing::blake2_256(&data[..]); - let maybe_msg = VersionedXcm::::decode(&mut &data[..]) - .map(Xcm::::try_from); + let maybe_msg = VersionedXcm::::decode_and_advance_with_depth_limit( + MAX_XCM_DECODE_DEPTH, + &mut &data[..], + ) + .map(Xcm::::try_from); match maybe_msg { Err(_) => { Self::deposit_event(Event::InvalidFormat(id)); diff --git a/pallets/parachain-system/Cargo.toml b/pallets/parachain-system/Cargo.toml index 3c16f9ad0b2..0a5c2440bcc 100644 --- a/pallets/parachain-system/Cargo.toml +++ b/pallets/parachain-system/Cargo.toml @@ -30,7 +30,7 @@ sp-trie = { git = "https://github.com/paritytech/substrate", default-features = sp-externalities = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "master" } # Other Dependencies -codec = { package = "parity-scale-codec", version = "2.0.0", default-features = false, features = ["derive"]} +codec = { package = "parity-scale-codec", version = "2.3.0", default-features = false, features = ["derive"]} serde = { version = "1.0.101", optional = true, features = ["derive"] } log = { version = "0.4.14", default-features = false } environmental = { version = "1.1.2", default-features = false } diff --git a/pallets/session-benchmarking/Cargo.toml b/pallets/session-benchmarking/Cargo.toml index 660cac2fe51..d44c21987ba 100644 --- a/pallets/session-benchmarking/Cargo.toml +++ b/pallets/session-benchmarking/Cargo.toml @@ -24,7 +24,7 @@ sp-io = { default-features = false, git = 'https://github.com/paritytech/substra [dev-dependencies] serde = { version = "1.0.119" } -codec = { package = "parity-scale-codec", version = "2.0.0", features = [ "derive" ] } +codec = { package = "parity-scale-codec", version = "2.3.0", features = [ "derive" ] } sp-core = { git = 'https://github.com/paritytech/substrate', branch = "master" } [features] diff --git a/pallets/xcm/Cargo.toml b/pallets/xcm/Cargo.toml index 2d3c0f8220f..8d72460643a 100644 --- a/pallets/xcm/Cargo.toml +++ b/pallets/xcm/Cargo.toml @@ -5,7 +5,7 @@ name = "cumulus-pallet-xcm" version = "0.1.0" [dependencies] -codec = { package = "parity-scale-codec", version = "2.0.0", default-features = false, features = ["derive"] } +codec = { package = "parity-scale-codec", version = "2.3.0", default-features = false, features = ["derive"] } serde = { version = "1.0.101", optional = true, features = ["derive"] } sp-std = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "master" } diff --git a/pallets/xcm/src/lib.rs b/pallets/xcm/src/lib.rs index 294a3583762..7aab7b19ea1 100644 --- a/pallets/xcm/src/lib.rs +++ b/pallets/xcm/src/lib.rs @@ -23,9 +23,12 @@ use sp_std::{prelude::*, convert::TryFrom}; use cumulus_primitives_core::{ParaId, DmpMessageHandler}; use cumulus_primitives_core::relay_chain::BlockNumber as RelayBlockNumber; -use codec::{Encode, Decode}; +use codec::{Decode, DecodeLimit, Encode}; use sp_runtime::traits::BadOrigin; -use xcm::{VersionedXcm, latest::{Xcm, Outcome, Parent, ExecuteXcm}}; +use xcm::{ + latest::{Xcm, Outcome, Parent, ExecuteXcm}, + MAX_XCM_DECODE_DEPTH, VersionedXcm, +}; use frame_support::dispatch::Weight; pub use pallet::*; @@ -112,8 +115,11 @@ impl DmpMessageHandler for UnlimitedDmpExecution { let mut used = 0; for (_sent_at, data) in iter { let id = sp_io::hashing::twox_64(&data[..]); - let msg = VersionedXcm::::decode(&mut &data[..]) - .map(Xcm::::try_from); + let msg = VersionedXcm::::decode_and_advance_with_depth_limit( + MAX_XCM_DECODE_DEPTH, + &mut &data[..], + ) + .map(Xcm::::try_from); match msg { Err(_) => Pallet::::deposit_event(Event::InvalidFormat(id)), Ok(Err(())) => Pallet::::deposit_event(Event::UnsupportedVersion(id)), @@ -142,8 +148,11 @@ impl DmpMessageHandler for LimitAndDropDmpExecution { let mut used = 0; for (_sent_at, data) in iter { let id = sp_io::hashing::twox_64(&data[..]); - let msg = VersionedXcm::::decode(&mut &data[..]) - .map(Xcm::::try_from); + let msg = VersionedXcm::::decode_and_advance_with_depth_limit( + MAX_XCM_DECODE_DEPTH, + &mut &data[..], + ) + .map(Xcm::::try_from); match msg { Err(_) => Pallet::::deposit_event(Event::InvalidFormat(id)), Ok(Err(())) => Pallet::::deposit_event(Event::UnsupportedVersion(id)), diff --git a/pallets/xcmp-queue/Cargo.toml b/pallets/xcmp-queue/Cargo.toml index 6325ceb271e..bfb645a6612 100644 --- a/pallets/xcmp-queue/Cargo.toml +++ b/pallets/xcmp-queue/Cargo.toml @@ -6,7 +6,7 @@ edition = "2018" [dependencies] # Other dependencies -codec = { package = "parity-scale-codec", version = "2.0.0", features = [ "derive" ], default-features = false } +codec = { package = "parity-scale-codec", version = "2.3.0", features = [ "derive" ], default-features = false } log = { version = "0.4.14", default-features = false } rand = { version = "0.8.3", default-features = false } rand_chacha = { version = "0.3.0", default-features = false } diff --git a/pallets/xcmp-queue/src/lib.rs b/pallets/xcmp-queue/src/lib.rs index 7f59e77e328..19ffce84001 100644 --- a/pallets/xcmp-queue/src/lib.rs +++ b/pallets/xcmp-queue/src/lib.rs @@ -31,7 +31,7 @@ mod mock; #[cfg(test)] mod tests; -use codec::{Decode, Encode}; +use codec::{Decode, DecodeLimit, Encode}; use cumulus_primitives_core::{ relay_chain::BlockNumber as RelayBlockNumber, ChannelStatus, GetChannelInfo, MessageSendError, ParaId, XcmpMessageHandler, XcmpMessageSource, XcmpMessageFormat, @@ -43,7 +43,7 @@ use rand_chacha::{ }; use sp_runtime::{traits::Hash, RuntimeDebug}; use sp_std::{prelude::*, convert::TryFrom}; -use xcm::{latest::prelude::*, WrapVersion, VersionedXcm}; +use xcm::{latest::prelude::*, MAX_XCM_DECODE_DEPTH, WrapVersion, VersionedXcm}; pub use pallet::*; @@ -256,7 +256,10 @@ impl Pallet { let have_active = s[index].4 > s[index].3; let appended = have_active && >::mutate(recipient, s[index].4 - 1, |s| { - if XcmpMessageFormat::decode(&mut &s[..]) != Ok(format) { + if XcmpMessageFormat::decode_and_advance_with_depth_limit( + MAX_XCM_DECODE_DEPTH, + &mut &s[..], + ) != Ok(format) { return false; } if s.len() + data.len() > max_message_size { @@ -382,7 +385,10 @@ impl Pallet { XcmpMessageFormat::ConcatenatedVersionedXcm => { while !remaining_fragments.is_empty() { last_remaining_fragments = remaining_fragments; - if let Ok(xcm) = VersionedXcm::::decode(&mut remaining_fragments) { + if let Ok(xcm) = VersionedXcm::::decode_and_advance_with_depth_limit( + MAX_XCM_DECODE_DEPTH, + &mut remaining_fragments, + ) { let weight = max_weight - weight_used; match Self::handle_xcm_message(sender, sent_at, xcm, weight) { Ok(used) => weight_used = weight_used.saturating_add(used), @@ -405,7 +411,10 @@ impl Pallet { XcmpMessageFormat::ConcatenatedEncodedBlob => { while !remaining_fragments.is_empty() { last_remaining_fragments = remaining_fragments; - if let Ok(blob) = >::decode(&mut remaining_fragments) { + if let Ok(blob) = >::decode_and_advance_with_depth_limit( + 32, // hardcoded constant since we don't process any blob XCMP msgs anyway + &mut remaining_fragments, + ) { let weight = max_weight - weight_used; match Self::handle_blob_message(sender, sent_at, blob, weight) { Ok(used) => weight_used = weight_used.saturating_add(used), @@ -615,7 +624,10 @@ impl XcmpMessageHandler for Pallet { for (sender, sent_at, data) in iter { // Figure out the message format. let mut data_ref = data; - let format = match XcmpMessageFormat::decode(&mut data_ref) { + let format = match XcmpMessageFormat::decode_and_advance_with_depth_limit( + MAX_XCM_DECODE_DEPTH, + &mut data_ref, + ) { Ok(f) => f, Err(_) => { debug_assert!( diff --git a/polkadot-parachains/Cargo.toml b/polkadot-parachains/Cargo.toml index 25667e89c1a..283d0236b0c 100644 --- a/polkadot-parachains/Cargo.toml +++ b/polkadot-parachains/Cargo.toml @@ -16,7 +16,7 @@ futures = { version = "0.3.1", features = ["compat"] } log = "0.4.8" parking_lot = "0.10.2" trie-root = "0.15.2" -codec = { package = "parity-scale-codec", version = "2.0.0" } +codec = { package = "parity-scale-codec", version = "2.3.0" } structopt = "0.3.3" serde = { version = "1.0.101", features = ["derive"] } hex-literal = "0.2.1" diff --git a/polkadot-parachains/pallets/parachain-info/Cargo.toml b/polkadot-parachains/pallets/parachain-info/Cargo.toml index 42bf4afceab..3c80bd08638 100644 --- a/polkadot-parachains/pallets/parachain-info/Cargo.toml +++ b/polkadot-parachains/pallets/parachain-info/Cargo.toml @@ -5,7 +5,7 @@ name = "parachain-info" version = "0.1.0" [dependencies] -codec = { package = "parity-scale-codec", version = "2.0.0", default-features = false, features = ["derive"] } +codec = { package = "parity-scale-codec", version = "2.3.0", default-features = false, features = ["derive"] } serde = { version = "1.0.101", optional = true, features = ["derive"] } frame-support = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "master" } diff --git a/polkadot-parachains/pallets/ping/Cargo.toml b/polkadot-parachains/pallets/ping/Cargo.toml index 3c3d3a72416..b4a03685c98 100644 --- a/polkadot-parachains/pallets/ping/Cargo.toml +++ b/polkadot-parachains/pallets/ping/Cargo.toml @@ -5,7 +5,7 @@ name = "cumulus-ping" version = "0.1.0" [dependencies] -codec = { package = "parity-scale-codec", version = "2.0.0", default-features = false, features = ["derive"] } +codec = { package = "parity-scale-codec", version = "2.3.0", default-features = false, features = ["derive"] } serde = { version = "1.0.101", optional = true, features = ["derive"] } sp-std = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "master" } diff --git a/polkadot-parachains/parachains-common/Cargo.toml b/polkadot-parachains/parachains-common/Cargo.toml index 9ab9d6c4abb..8bfeb8cbe16 100644 --- a/polkadot-parachains/parachains-common/Cargo.toml +++ b/polkadot-parachains/parachains-common/Cargo.toml @@ -10,7 +10,7 @@ targets = ['x86_64-unknown-linux-gnu'] [dependencies] # External dependencies -codec = { package = 'parity-scale-codec', version = '2.0.0', features = ['derive'], default-features = false } +codec = { package = 'parity-scale-codec', version = '2.3.0', features = ['derive'], default-features = false } # Substrate dependencies sp-consensus-aura = { git = 'https://github.com/paritytech/substrate', branch = "master", default-features = false } diff --git a/polkadot-parachains/rococo/Cargo.toml b/polkadot-parachains/rococo/Cargo.toml index e7312f2f2a3..0130a99f327 100644 --- a/polkadot-parachains/rococo/Cargo.toml +++ b/polkadot-parachains/rococo/Cargo.toml @@ -7,7 +7,7 @@ description = "Simple runtime used by the rococo parachain(s)" [dependencies] serde = { version = "1.0.101", optional = true, features = ["derive"] } -codec = { package = "parity-scale-codec", version = "2.0.0", default-features = false, features = ["derive"] } +codec = { package = "parity-scale-codec", version = "2.3.0", default-features = false, features = ["derive"] } log = { version = "0.4.14", default-features = false } parachain-info = { path = "../pallets/parachain-info", default-features = false } diff --git a/polkadot-parachains/shell/Cargo.toml b/polkadot-parachains/shell/Cargo.toml index d0f18618d15..552b918ff07 100644 --- a/polkadot-parachains/shell/Cargo.toml +++ b/polkadot-parachains/shell/Cargo.toml @@ -6,7 +6,7 @@ edition = '2018' [dependencies] serde = { version = "1.0.101", optional = true, features = ["derive"] } -codec = { package = "parity-scale-codec", version = "2.0.0", default-features = false, features = ["derive"] } +codec = { package = "parity-scale-codec", version = "2.3.0", default-features = false, features = ["derive"] } log = { version = "0.4.14", default-features = false } parachain-info = { path = "../pallets/parachain-info", default-features = false } diff --git a/polkadot-parachains/statemine/Cargo.toml b/polkadot-parachains/statemine/Cargo.toml index 36218a6c89d..ff2a0239bc0 100644 --- a/polkadot-parachains/statemine/Cargo.toml +++ b/polkadot-parachains/statemine/Cargo.toml @@ -7,7 +7,7 @@ description = "Kusama variant of Statemint parachain runtime" [dependencies] serde = { version = "1.0.101", optional = true, features = ["derive"] } -codec = { package = "parity-scale-codec", version = "2.0.0", default-features = false, features = ["derive", "max-encoded-len"] } +codec = { package = "parity-scale-codec", version = "2.3.0", default-features = false, features = ["derive", "max-encoded-len"] } log = { version = "0.4.14", default-features = false } parachain-info = { path = "../pallets/parachain-info", default-features = false } smallvec = "1.6.1" diff --git a/polkadot-parachains/statemint/Cargo.toml b/polkadot-parachains/statemint/Cargo.toml index 9027ad4ec28..334d5b05b5b 100644 --- a/polkadot-parachains/statemint/Cargo.toml +++ b/polkadot-parachains/statemint/Cargo.toml @@ -7,7 +7,7 @@ description = "Statemint parachain runtime" [dependencies] serde = { version = "1.0.101", optional = true, features = ["derive"] } -codec = { package = "parity-scale-codec", version = "2.0.0", default-features = false, features = ["derive", "max-encoded-len"] } +codec = { package = "parity-scale-codec", version = "2.3.0", default-features = false, features = ["derive", "max-encoded-len"] } log = { version = "0.4.14", default-features = false } parachain-info = { path = "../pallets/parachain-info", default-features = false } smallvec = "1.6.1" diff --git a/polkadot-parachains/westmint/Cargo.toml b/polkadot-parachains/westmint/Cargo.toml index 9cf94d12def..035abd30e02 100644 --- a/polkadot-parachains/westmint/Cargo.toml +++ b/polkadot-parachains/westmint/Cargo.toml @@ -7,7 +7,7 @@ description = "Westend variant of Statemint parachain runtime" [dependencies] serde = { version = "1.0.101", optional = true, features = ["derive"] } -codec = { package = "parity-scale-codec", version = "2.0.0", default-features = false, features = ["derive", "max-encoded-len"] } +codec = { package = "parity-scale-codec", version = "2.3.0", default-features = false, features = ["derive", "max-encoded-len"] } log = { version = "0.4.14", default-features = false } parachain-info = { path = "../pallets/parachain-info", default-features = false } smallvec = "1.6.1" diff --git a/primitives/core/Cargo.toml b/primitives/core/Cargo.toml index 20d78aea358..3db2d88d6c4 100644 --- a/primitives/core/Cargo.toml +++ b/primitives/core/Cargo.toml @@ -20,7 +20,7 @@ xcm = { git = "https://github.com/paritytech/polkadot", default-features = false # Other dependencies impl-trait-for-tuples = "0.2.1" -codec = { package = "parity-scale-codec", version = "2.0.0", default-features = false, features = [ "derive" ] } +codec = { package = "parity-scale-codec", version = "2.3.0", default-features = false, features = [ "derive" ] } [features] default = [ "std" ] diff --git a/primitives/parachain-inherent/Cargo.toml b/primitives/parachain-inherent/Cargo.toml index 041d7f974f2..03f9a980539 100644 --- a/primitives/parachain-inherent/Cargo.toml +++ b/primitives/parachain-inherent/Cargo.toml @@ -23,7 +23,7 @@ cumulus-primitives-core = { path = "../core", default-features = false } cumulus-test-relay-sproof-builder = { path = "../../test/relay-sproof-builder", optional = true } # Other dependencies -codec = { package = "parity-scale-codec", version = "2.0.0", default-features = false, features = [ "derive" ] } +codec = { package = "parity-scale-codec", version = "2.3.0", default-features = false, features = [ "derive" ] } tracing = { version = "0.1.22", optional = true } async-trait = { version = "0.1.42", optional = true } diff --git a/primitives/timestamp/Cargo.toml b/primitives/timestamp/Cargo.toml index 4cd8b262d8a..e3404261cbd 100644 --- a/primitives/timestamp/Cargo.toml +++ b/primitives/timestamp/Cargo.toml @@ -25,7 +25,7 @@ cumulus-test-client = { path = "../../test/client" } cumulus-test-relay-sproof-builder = { path = "../../test/relay-sproof-builder" } # Other deps -codec = { package = "parity-scale-codec", version = "2.0.0", default-features = false, features = [ "derive" ] } +codec = { package = "parity-scale-codec", version = "2.3.0", default-features = false, features = [ "derive" ] } futures = "0.3.5" [features] diff --git a/primitives/utility/Cargo.toml b/primitives/utility/Cargo.toml index d069f7394f1..1e2e394d0a1 100644 --- a/primitives/utility/Cargo.toml +++ b/primitives/utility/Cargo.toml @@ -21,7 +21,7 @@ cumulus-primitives-core = { path = "../core", default-features = false } # Other dependencies impl-trait-for-tuples = "0.2.1" -codec = { package = "parity-scale-codec", version = "2.0.0", default-features = false, features = [ "derive" ] } +codec = { package = "parity-scale-codec", version = "2.3.0", default-features = false, features = [ "derive" ] } [features] diff --git a/test/client/Cargo.toml b/test/client/Cargo.toml index a5c836e7cc9..5548fe9f3d4 100644 --- a/test/client/Cargo.toml +++ b/test/client/Cargo.toml @@ -37,4 +37,4 @@ polkadot-primitives = { git = "https://github.com/paritytech/polkadot", branch = polkadot-parachain = { git = "https://github.com/paritytech/polkadot", branch = "master" } # Other deps -codec = { package = "parity-scale-codec", version = "2.0.0", default-features = false, features = [ "derive" ] } +codec = { package = "parity-scale-codec", version = "2.3.0", default-features = false, features = [ "derive" ] } diff --git a/test/relay-sproof-builder/Cargo.toml b/test/relay-sproof-builder/Cargo.toml index 9342ff74721..a951fddf1cd 100644 --- a/test/relay-sproof-builder/Cargo.toml +++ b/test/relay-sproof-builder/Cargo.toml @@ -6,7 +6,7 @@ edition = '2018' [dependencies] # Other dependencies -codec = { package = "parity-scale-codec", version = "2.0.0", default-features = false, features = [ "derive" ] } +codec = { package = "parity-scale-codec", version = "2.3.0", default-features = false, features = [ "derive" ] } # Substrate dependencies sp-state-machine = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "master" } diff --git a/test/runtime-upgrade/Cargo.toml b/test/runtime-upgrade/Cargo.toml index e944d56a574..4b3b7a730e7 100644 --- a/test/runtime-upgrade/Cargo.toml +++ b/test/runtime-upgrade/Cargo.toml @@ -5,7 +5,7 @@ authors = ["Parity Technologies "] edition = "2018" [dependencies] -codec = { package = "parity-scale-codec", version = "2.0.0", default-features = false, features = ["derive"] } +codec = { package = "parity-scale-codec", version = "2.3.0", default-features = false, features = ["derive"] } serde = { version = "1.0.101", optional = true, features = ["derive"] } # Substrate dependencies diff --git a/test/runtime/Cargo.toml b/test/runtime/Cargo.toml index 1bbdc88cb40..5fd4fa02515 100644 --- a/test/runtime/Cargo.toml +++ b/test/runtime/Cargo.toml @@ -5,7 +5,7 @@ authors = ["Parity Technologies "] edition = "2018" [dependencies] -codec = { package = "parity-scale-codec", version = "2.0.0", default-features = false, features = ["derive"] } +codec = { package = "parity-scale-codec", version = "2.3.0", default-features = false, features = ["derive"] } serde = { version = "1.0.101", optional = true, features = ["derive"] } # Substrate dependencies diff --git a/test/service/Cargo.toml b/test/service/Cargo.toml index 1b14bce61d5..41cdf48da10 100644 --- a/test/service/Cargo.toml +++ b/test/service/Cargo.toml @@ -5,7 +5,7 @@ authors = ["Parity Technologies "] edition = "2018" [dependencies] -codec = { package = "parity-scale-codec", version = "2.0.0" } +codec = { package = "parity-scale-codec", version = "2.3.0" } rand = "0.7.3" serde = { version = "1.0.101", features = ["derive"] } async-trait = "0.1.42" From 5fb51c26c755dab09402c12a89ed9dbe1946691a Mon Sep 17 00:00:00 2001 From: Keith Yeung Date: Sat, 11 Sep 2021 17:40:51 -0700 Subject: [PATCH 2/4] Use decode_all_with_depth_limit in appropriate places --- pallets/dmp-queue/src/lib.rs | 2 +- pallets/xcm/src/lib.rs | 4 ++-- pallets/xcmp-queue/src/lib.rs | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/pallets/dmp-queue/src/lib.rs b/pallets/dmp-queue/src/lib.rs index 2fe2da90f14..fddd3e081a0 100644 --- a/pallets/dmp-queue/src/lib.rs +++ b/pallets/dmp-queue/src/lib.rs @@ -233,7 +233,7 @@ pub mod pallet { data: &[u8], ) -> Result { let id = sp_io::hashing::blake2_256(&data[..]); - let maybe_msg = VersionedXcm::::decode_and_advance_with_depth_limit( + let maybe_msg = VersionedXcm::::decode_all_with_depth_limit( MAX_XCM_DECODE_DEPTH, &mut &data[..], ) diff --git a/pallets/xcm/src/lib.rs b/pallets/xcm/src/lib.rs index 7aab7b19ea1..f16f1214126 100644 --- a/pallets/xcm/src/lib.rs +++ b/pallets/xcm/src/lib.rs @@ -115,7 +115,7 @@ impl DmpMessageHandler for UnlimitedDmpExecution { let mut used = 0; for (_sent_at, data) in iter { let id = sp_io::hashing::twox_64(&data[..]); - let msg = VersionedXcm::::decode_and_advance_with_depth_limit( + let msg = VersionedXcm::::decode_all_with_depth_limit( MAX_XCM_DECODE_DEPTH, &mut &data[..], ) @@ -148,7 +148,7 @@ impl DmpMessageHandler for LimitAndDropDmpExecution { let mut used = 0; for (_sent_at, data) in iter { let id = sp_io::hashing::twox_64(&data[..]); - let msg = VersionedXcm::::decode_and_advance_with_depth_limit( + let msg = VersionedXcm::::decode_all_with_depth_limit( MAX_XCM_DECODE_DEPTH, &mut &data[..], ) diff --git a/pallets/xcmp-queue/src/lib.rs b/pallets/xcmp-queue/src/lib.rs index 19ffce84001..170d224d95f 100644 --- a/pallets/xcmp-queue/src/lib.rs +++ b/pallets/xcmp-queue/src/lib.rs @@ -411,7 +411,7 @@ impl Pallet { XcmpMessageFormat::ConcatenatedEncodedBlob => { while !remaining_fragments.is_empty() { last_remaining_fragments = remaining_fragments; - if let Ok(blob) = >::decode_and_advance_with_depth_limit( + if let Ok(blob) = >::decode_all_with_depth_limit( 32, // hardcoded constant since we don't process any blob XCMP msgs anyway &mut remaining_fragments, ) { From bc5b78866cee934f4ce1e5c96d8d98e8baab51a1 Mon Sep 17 00:00:00 2001 From: Keith Yeung Date: Tue, 14 Sep 2021 14:07:51 -0700 Subject: [PATCH 3/4] Use decode_all while decoding byte vector --- pallets/xcmp-queue/src/lib.rs | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/pallets/xcmp-queue/src/lib.rs b/pallets/xcmp-queue/src/lib.rs index 170d224d95f..80ffd33cc2e 100644 --- a/pallets/xcmp-queue/src/lib.rs +++ b/pallets/xcmp-queue/src/lib.rs @@ -31,7 +31,7 @@ mod mock; #[cfg(test)] mod tests; -use codec::{Decode, DecodeLimit, Encode}; +use codec::{Decode, DecodeAll, DecodeLimit, Encode}; use cumulus_primitives_core::{ relay_chain::BlockNumber as RelayBlockNumber, ChannelStatus, GetChannelInfo, MessageSendError, ParaId, XcmpMessageHandler, XcmpMessageSource, XcmpMessageFormat, @@ -411,10 +411,7 @@ impl Pallet { XcmpMessageFormat::ConcatenatedEncodedBlob => { while !remaining_fragments.is_empty() { last_remaining_fragments = remaining_fragments; - if let Ok(blob) = >::decode_all_with_depth_limit( - 32, // hardcoded constant since we don't process any blob XCMP msgs anyway - &mut remaining_fragments, - ) { + if let Ok(blob) = >::decode_all(&mut remaining_fragments) { let weight = max_weight - weight_used; match Self::handle_blob_message(sender, sent_at, blob, weight) { Ok(used) => weight_used = weight_used.saturating_add(used), From d85bd8b437256bdeff5f20db647f4565827f0cd3 Mon Sep 17 00:00:00 2001 From: Keith Yeung Date: Sat, 18 Sep 2021 02:56:56 -0700 Subject: [PATCH 4/4] cargo fmt --- pallets/dmp-queue/src/lib.rs | 2 +- pallets/xcm/src/lib.rs | 2 +- pallets/xcmp-queue/src/lib.rs | 7 ++++--- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/pallets/dmp-queue/src/lib.rs b/pallets/dmp-queue/src/lib.rs index 9c7edbd2d7c..ebd2b597671 100644 --- a/pallets/dmp-queue/src/lib.rs +++ b/pallets/dmp-queue/src/lib.rs @@ -30,7 +30,7 @@ pub use pallet::*; use scale_info::TypeInfo; use sp_runtime::RuntimeDebug; use sp_std::{convert::TryFrom, prelude::*}; -use xcm::{latest::prelude::*, MAX_XCM_DECODE_DEPTH, VersionedXcm}; +use xcm::{latest::prelude::*, VersionedXcm, MAX_XCM_DECODE_DEPTH}; #[derive(Copy, Clone, Eq, PartialEq, Encode, Decode, RuntimeDebug, TypeInfo)] pub struct ConfigData { diff --git a/pallets/xcm/src/lib.rs b/pallets/xcm/src/lib.rs index 9dd822e87dd..ab61076ddf6 100644 --- a/pallets/xcm/src/lib.rs +++ b/pallets/xcm/src/lib.rs @@ -31,7 +31,7 @@ use sp_runtime::traits::BadOrigin; use sp_std::{convert::TryFrom, prelude::*}; use xcm::{ latest::{ExecuteXcm, Outcome, Parent, Xcm}, - MAX_XCM_DECODE_DEPTH, VersionedXcm, + VersionedXcm, MAX_XCM_DECODE_DEPTH, }; #[frame_support::pallet] diff --git a/pallets/xcmp-queue/src/lib.rs b/pallets/xcmp-queue/src/lib.rs index ba3265db637..9f3ecc8ffa4 100644 --- a/pallets/xcmp-queue/src/lib.rs +++ b/pallets/xcmp-queue/src/lib.rs @@ -44,7 +44,7 @@ use rand_chacha::{ use scale_info::TypeInfo; use sp_runtime::{traits::Hash, RuntimeDebug}; use sp_std::{convert::TryFrom, prelude::*}; -use xcm::{latest::prelude::*, MAX_XCM_DECODE_DEPTH, VersionedXcm, WrapVersion}; +use xcm::{latest::prelude::*, VersionedXcm, WrapVersion, MAX_XCM_DECODE_DEPTH}; pub use pallet::*; @@ -252,8 +252,9 @@ impl Pallet { if XcmpMessageFormat::decode_and_advance_with_depth_limit( MAX_XCM_DECODE_DEPTH, &mut &s[..], - ) != Ok(format) { - return false; + ) != Ok(format) + { + return false } if s.len() + data.len() > max_message_size { return false