From e8cd0f58c71898d2e3429d953ef972ed3fe3a39d Mon Sep 17 00:00:00 2001 From: Alexander Gryaznov Date: Fri, 5 May 2023 16:43:46 +0300 Subject: [PATCH] add error logging to call_runtime --- frame/contracts/src/wasm/runtime.rs | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/frame/contracts/src/wasm/runtime.rs b/frame/contracts/src/wasm/runtime.rs index 330bf19d65232..ae02e5badbf39 100644 --- a/frame/contracts/src/wasm/runtime.rs +++ b/frame/contracts/src/wasm/runtime.rs @@ -1235,6 +1235,10 @@ pub mod env { out_len_ptr: u32, ) -> Result { let charged = ctx.charge_gas(RuntimeCosts::TakeStorage(ctx.ext.max_value_size()))?; + ensure!( + key_len <= <::T as Config>::MaxStorageKeyLen::get(), + Error::::DecodingFailed + ); let key = ctx.read_sandbox_memory(memory, key_ptr, key_len)?; if let crate::storage::WriteOutcome::Taken(value) = ctx.ext.set_storage( &Key::::try_from_var(key).map_err(|_| Error::::DecodingFailed)?, @@ -2608,7 +2612,13 @@ pub mod env { ctx.adjust_gas(charged, RuntimeCosts::CallRuntime(actual_weight)); match result { Ok(_) => Ok(ReturnCode::Success), - Err(_) => Ok(ReturnCode::CallRuntimeFailed), + Err(e) => { + if ctx.ext.append_debug_buffer("") { + ctx.ext.append_debug_buffer("seal0::call_runtime failed with: "); + ctx.ext.append_debug_buffer(e.into()); + }; + Ok(ReturnCode::CallRuntimeFailed) + }, } }