Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 19 additions & 3 deletions substrate/frame/executive/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,9 @@ use ::{
#[allow(dead_code)]
const LOG_TARGET: &str = "runtime::executive";

/// Maximum nesting level for extrinsics.
pub const MAX_EXTRINSIC_DEPTH: u32 = 256;

pub type CheckedOf<E, C> = <E as Checkable<C>>::Checked;
pub type CallOf<E, C> = <CheckedOf<E, C> as Applyable>::Call;
pub type OriginOf<E, C> = <CallOf<E, C> as Dispatchable>::RuntimeOrigin;
Expand Down Expand Up @@ -627,6 +630,13 @@ where
let encoded_len = encoded.len();
sp_tracing::enter_span!(sp_tracing::info_span!("apply_extrinsic",
ext=?sp_core::hexdisplay::HexDisplay::from(&encoded)));

let uxt = <Block::Extrinsic as codec::DecodeLimit>::decode_all_with_depth_limit(
MAX_EXTRINSIC_DEPTH,
&mut &encoded[..],
)
.expect("Decoding the encoded transaction works; qed");

// Verify that the signature is good.
let xt = uxt.check(&Default::default())?;

Expand Down Expand Up @@ -703,10 +713,16 @@ where

enter_span! { sp_tracing::Level::TRACE, "validate_transaction" };

let encoded_len = within_span! { sp_tracing::Level::TRACE, "using_encoded";
uxt.using_encoded(|d| d.len())
let encoded = within_span! { sp_tracing::Level::TRACE, "using_encoded";
uxt.encode()
};

let uxt = <Block::Extrinsic as codec::DecodeLimit>::decode_all_with_depth_limit(
MAX_EXTRINSIC_DEPTH,
&mut &encoded[..],
)
.map_err(|_| InvalidTransaction::Call)?;

let xt = within_span! { sp_tracing::Level::TRACE, "check";
uxt.check(&Default::default())
}?;
Expand All @@ -721,7 +737,7 @@ where

within_span! {
sp_tracing::Level::TRACE, "validate";
xt.validate::<UnsignedValidator>(source, &dispatch_info, encoded_len)
xt.validate::<UnsignedValidator>(source, &dispatch_info, encoded.len())
}
}

Expand Down
3 changes: 1 addition & 2 deletions substrate/primitives/api/proc-macro/src/impl_runtime_apis.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,7 @@ fn generate_impl_call(

quote!(
#let_binding =
match #c::DecodeLimit::decode_all_with_depth_limit(
#c::MAX_EXTRINSIC_DEPTH,
match #c::Decode::decode(
&mut #input,
) {
Ok(res) => res,
Expand Down
Loading