Validate encoding of extrinsics passed to runtime (#6442)

* Validate encoding of extrinsics passed to runtime

* Bump codec version explicitly
This commit is contained in:
Arkadiy Paronyan
2020-06-19 21:27:16 +02:00
committed by GitHub
parent 9ee2427289
commit 7b34438178
131 changed files with 141 additions and 134 deletions
+1 -1
View File
@@ -12,7 +12,7 @@ description = "Substrate runtime api primitives"
targets = ["x86_64-unknown-linux-gnu"]
[dependencies]
codec = { package = "parity-scale-codec", version = "1.3.0", default-features = false }
codec = { package = "parity-scale-codec", version = "1.3.1", default-features = false }
sp-api-proc-macro = { version = "2.0.0-rc3", path = "proc-macro" }
sp-core = { version = "2.0.0-rc3", default-features = false, path = "../core" }
sp-std = { version = "2.0.0-rc3", default-features = false, path = "../std" }
@@ -191,7 +191,8 @@ fn generate_native_call_generators(decl: &ItemTrait) -> Result<TokenStream> {
input: &I, error_desc: &'static str,
) -> std::result::Result<R, String>
{
<R as #crate_::Decode>::decode(
<R as #crate_::DecodeLimit>::decode_with_depth_limit(
#crate_::MAX_EXTRINSIC_DEPTH,
&mut &#crate_::Encode::encode(input)[..],
).map_err(|e| format!("{} {}", error_desc, e.what()))
}
@@ -83,7 +83,10 @@ fn generate_impl_call(
Ok(
quote!(
#(
let #pnames : #ptypes = match #c_iter::Decode::decode(&mut #input) {
let #pnames : #ptypes = match #c_iter::DecodeLimit::decode_all_with_depth_limit(
#c_iter::MAX_EXTRINSIC_DEPTH,
&mut #input
) {
Ok(input) => input,
Err(e) => panic!("Bad input data provided to {}: {}", #fn_name_str, e.what()),
};
+4 -1
View File
@@ -69,11 +69,14 @@ pub use sp_std::{slice, mem};
#[cfg(feature = "std")]
use sp_std::result;
#[doc(hidden)]
pub use codec::{Encode, Decode};
pub use codec::{Encode, Decode, DecodeLimit};
use sp_core::OpaqueMetadata;
#[cfg(feature = "std")]
use std::{panic::UnwindSafe, cell::RefCell};
/// Maximum nesting level for extrinsics.
pub const MAX_EXTRINSIC_DEPTH: u32 = 256;
/// Declares given traits as runtime apis.
///
/// The macro will create two declarations, one for using on the client side and one for using
+1 -1
View File
@@ -19,7 +19,7 @@ sp-runtime = { version = "2.0.0-rc3", path = "../../runtime" }
sp-blockchain = { version = "2.0.0-rc3", path = "../../blockchain" }
sp-consensus = { version = "0.8.0-rc3", path = "../../../primitives/consensus/common" }
sc-block-builder = { version = "0.8.0-rc3", path = "../../../client/block-builder" }
codec = { package = "parity-scale-codec", version = "1.3.0" }
codec = { package = "parity-scale-codec", version = "1.3.1" }
sp-state-machine = { version = "0.8.0-rc3", path = "../../../primitives/state-machine" }
trybuild = "1.0.17"
rustversion = "1.0.0"
@@ -16,9 +16,9 @@ error[E0277]: the trait bound `u32: std::convert::From<std::string::String>` is
27 | | }
| |_^ the trait `std::convert::From<std::string::String>` is not implemented for `u32`
|
::: $WORKSPACE/primitives/api/src/lib.rs:347:35
::: $WORKSPACE/primitives/api/src/lib.rs:350:35
|
347 | type Error: std::fmt::Debug + From<String>;
350 | type Error: std::fmt::Debug + From<String>;
| ------------ required by this bound in `sp_api_hidden_includes_DECL_RUNTIME_APIS::sp_api::ApiErrorExt`
|
= help: the following implementations were found: