seal: Remove ext_dispatch_call and ext_get_runtime_storage (#6464)

Those are way too hard to audit and make only sense with specific
chains. They shouldn't be in the core API.
This commit is contained in:
Alexander Theißen
2020-06-24 13:53:40 +02:00
committed by GitHub
parent a3a42f599a
commit b14b472edf
11 changed files with 28 additions and 649 deletions
@@ -32,7 +32,6 @@ use sp_io::hashing::{
blake2_128,
sha2_256,
};
use frame_support::weights::GetDispatchInfo;
/// The value returned from ext_call and ext_instantiate contract external functions if the call or
/// instantiation traps. This value is chosen as if the execution does not trap, the return value
@@ -162,8 +161,6 @@ pub enum RuntimeToken {
/// The given number of bytes is read from the sandbox memory and
/// is returned as the return data buffer of the call.
ReturnData(u32),
/// Dispatched a call with the given weight.
DispatchWithWeight(Gas),
/// (topic_count, data_bytes): A buffer of the given size is posted as an event indexed with the
/// given number of topics.
DepositEvent(u32, u32),
@@ -204,7 +201,6 @@ impl<T: Trait> Token<T> for RuntimeToken {
data_and_topics_cost.checked_add(metadata.event_base_cost)
)
},
DispatchWithWeight(gas) => gas.checked_add(metadata.dispatch_base_cost),
};
value.unwrap_or_else(|| Bounded::max_value())
@@ -785,30 +781,6 @@ define_env!(Env, <E: Ext>,
Ok(())
},
// Decodes the given buffer as a `T::Call` and adds it to the list
// of to-be-dispatched calls.
//
// All calls made it to the top-level context will be dispatched before
// finishing the execution of the calling extrinsic.
ext_dispatch_call(ctx, call_ptr: u32, call_len: u32) => {
let call: <<E as Ext>::T as Trait>::Call =
read_sandbox_memory_as(ctx, call_ptr, call_len)?;
// We already deducted the len costs when reading from the sandbox.
// Bill on the actual weight of the dispatched call.
let info = call.get_dispatch_info();
charge_gas(
&mut ctx.gas_meter,
ctx.schedule,
&mut ctx.special_trap,
RuntimeToken::DispatchWithWeight(info.weight)
)?;
ctx.ext.note_dispatch_call(call);
Ok(())
},
// Try to restore the given destination contract sacrificing the caller.
//
// This function will compute a tombstone hash from the caller's storage and the given code hash
@@ -1005,32 +977,6 @@ define_env!(Env, <E: Ext>,
Ok(())
},
// Retrieve the value under the given key from the **runtime** storage and return 0.
// If there is no entry under the given key then this function will return 1 and
// clear the scratch buffer.
//
// - key_ptr: the pointer into the linear memory where the requested value is placed.
// - key_len: the length of the key in bytes.
ext_get_runtime_storage(ctx, key_ptr: u32, key_len: u32) -> u32 => {
// Steal the scratch buffer so that we hopefully save an allocation for the `key_buf`.
read_sandbox_memory_into_scratch(ctx, key_ptr, key_len)?;
let key_buf = mem::replace(&mut ctx.scratch_buf, Vec::new());
match ctx.ext.get_runtime_storage(&key_buf) {
Some(value_buf) => {
// The given value exists.
ctx.scratch_buf = value_buf;
Ok(0)
}
None => {
// Put back the `key_buf` and allow its allocation to be reused.
ctx.scratch_buf = key_buf;
ctx.scratch_buf.clear();
Ok(1)
}
}
},
// Computes the SHA2 256-bit hash on the given input buffer.
//
// Returns the result directly into the given output buffer.