Skip to content

Commit f6532de

Browse files
authored
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.
1 parent 30cfa81 commit f6532de

File tree

10 files changed

+28
-648
lines changed

10 files changed

+28
-648
lines changed

fixtures/dispatch_call.wat

Lines changed: 0 additions & 14 deletions
This file was deleted.

fixtures/dispatch_call_then_trap.wat

Lines changed: 0 additions & 15 deletions
This file was deleted.

fixtures/get_runtime_storage.wat

Lines changed: 0 additions & 74 deletions
This file was deleted.

fixtures/restoration.wat

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,8 @@
5151

5252
;; Code hash of SET_RENT
5353
(data (i32.const 264)
54-
"\c2\1c\41\10\a5\22\d8\59\1c\4c\77\35\dd\2d\bf\a1"
55-
"\13\0b\50\93\76\9b\92\31\97\b7\c5\74\26\aa\38\2a"
54+
"\ab\d6\58\65\1e\83\6e\4a\18\0d\f2\6d\bc\42\ba\e9"
55+
"\3d\64\76\e5\30\5b\33\46\bb\4d\43\99\38\21\ee\32"
5656
)
5757

5858
;; Rent allowance

fixtures/set_rent.wat

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
(module
2-
(import "env" "ext_dispatch_call" (func $ext_dispatch_call (param i32 i32)))
2+
(import "env" "ext_transfer" (func $ext_transfer (param i32 i32 i32 i32) (result i32)))
33
(import "env" "ext_set_storage" (func $ext_set_storage (param i32 i32 i32)))
44
(import "env" "ext_clear_storage" (func $ext_clear_storage (param i32)))
55
(import "env" "ext_set_rent_allowance" (func $ext_set_rent_allowance (param i32 i32)))
@@ -23,11 +23,13 @@
2323
)
2424
)
2525

26-
;; transfer 50 to ALICE
26+
;; transfer 50 to CHARLIE
2727
(func $call_2
28-
(call $ext_dispatch_call
29-
(i32.const 68)
30-
(i32.const 11)
28+
(call $assert
29+
(i32.eq
30+
(call $ext_transfer (i32.const 68) (i32.const 8) (i32.const 76) (i32.const 8))
31+
(i32.const 0)
32+
)
3133
)
3234
)
3335

@@ -96,6 +98,9 @@
9698
;; Encoding of 10 in balance
9799
(data (i32.const 0) "\28")
98100

99-
;; Encoding of call transfer 50 to CHARLIE
100-
(data (i32.const 68) "\00\00\03\00\00\00\00\00\00\00\C8")
101+
;; encoding of Charlies's account id
102+
(data (i32.const 68) "\03")
103+
104+
;; encoding of 50 balance
105+
(data (i32.const 76) "\32")
101106
)

src/exec.rs

Lines changed: 8 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ use frame_support::{
2929
};
3030

3131
pub type AccountIdOf<T> = <T as frame_system::Trait>::AccountId;
32-
pub type CallOf<T> = <T as Trait>::Call;
3332
pub type MomentOf<T> = <<T as Trait>::Time as Time>::Moment;
3433
pub type SeedOf<T> = <T as frame_system::Trait>::Hash;
3534
pub type BlockNumberOf<T> = <T as frame_system::Trait>::BlockNumber;
@@ -151,9 +150,6 @@ pub trait Ext {
151150
input_data: Vec<u8>,
152151
) -> ExecResult;
153152

154-
/// Notes a call dispatch.
155-
fn note_dispatch_call(&mut self, call: CallOf<Self::T>);
156-
157153
/// Restores the given destination contract sacrificing the current one.
158154
///
159155
/// Since this function removes the self contract eagerly, if succeeded, no further actions should
@@ -274,23 +270,11 @@ impl<T: Trait> Token<T> for ExecFeeToken {
274270
}
275271
}
276272

277-
#[cfg_attr(any(feature = "std", test), derive(PartialEq, Eq, Clone))]
278-
#[derive(sp_runtime::RuntimeDebug)]
279-
pub enum DeferredAction<T: Trait> {
280-
DispatchRuntimeCall {
281-
/// The account id of the contract who dispatched this call.
282-
origin: T::AccountId,
283-
/// The call to dispatch.
284-
call: <T as Trait>::Call,
285-
},
286-
}
287-
288273
pub struct ExecutionContext<'a, T: Trait + 'a, V, L> {
289274
pub caller: Option<&'a ExecutionContext<'a, T, V, L>>,
290275
pub self_account: T::AccountId,
291276
pub self_trie_id: Option<TrieId>,
292277
pub depth: usize,
293-
pub deferred: Vec<DeferredAction<T>>,
294278
pub config: &'a Config<T>,
295279
pub vm: &'a V,
296280
pub loader: &'a L,
@@ -314,7 +298,6 @@ where
314298
self_trie_id: None,
315299
self_account: origin,
316300
depth: 0,
317-
deferred: Vec::new(),
318301
config: &cfg,
319302
vm: &vm,
320303
loader: &loader,
@@ -331,7 +314,6 @@ where
331314
self_trie_id: trie_id,
332315
self_account: dest,
333316
depth: self.depth + 1,
334-
deferred: Vec::new(),
335317
config: self.config,
336318
vm: self.vm,
337319
loader: self.loader,
@@ -532,21 +514,14 @@ where
532514
where F: FnOnce(&mut ExecutionContext<T, V, L>) -> ExecResult
533515
{
534516
use frame_support::storage::TransactionOutcome::*;
535-
let (output, deferred) = {
536-
let mut nested = self.nested(dest, trie_id);
537-
let output = frame_support::storage::with_transaction(|| {
538-
let output = func(&mut nested);
539-
match output {
540-
Ok(ref rv) if rv.is_success() => Commit(output),
541-
_ => Rollback(output),
542-
}
543-
})?;
544-
(output, nested.deferred)
545-
};
546-
if output.is_success() {
547-
self.deferred.extend(deferred);
548-
}
549-
Ok(output)
517+
let mut nested = self.nested(dest, trie_id);
518+
frame_support::storage::with_transaction(|| {
519+
let output = func(&mut nested);
520+
match output {
521+
Ok(ref rv) if rv.is_success() => Commit(output),
522+
_ => Rollback(output),
523+
}
524+
})
550525
}
551526

552527
/// Returns whether a contract, identified by address, is currently live in the execution
@@ -767,13 +742,6 @@ where
767742
self.ctx.call(to.clone(), value, gas_meter, input_data)
768743
}
769744

770-
fn note_dispatch_call(&mut self, call: CallOf<Self::T>) {
771-
self.ctx.deferred.push(DeferredAction::DispatchRuntimeCall {
772-
origin: self.ctx.self_account.clone(),
773-
call,
774-
});
775-
}
776-
777745
fn restore_to(
778746
&mut self,
779747
dest: AccountIdOf<Self::T>,

src/lib.rs

Lines changed: 6 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -106,16 +106,13 @@ use sp_runtime::{
106106
},
107107
RuntimeDebug,
108108
};
109-
use frame_support::dispatch::{
110-
PostDispatchInfo, DispatchResult, Dispatchable, DispatchResultWithPostInfo
111-
};
112109
use frame_support::{
113-
Parameter, decl_module, decl_event, decl_storage, decl_error,
114-
parameter_types, IsSubType, storage::child::ChildInfo,
110+
decl_module, decl_event, decl_storage, decl_error,
111+
parameter_types, storage::child::ChildInfo,
112+
dispatch::{DispatchResult, DispatchResultWithPostInfo},
113+
traits::{OnUnbalanced, Currency, Get, Time, Randomness},
115114
};
116-
use frame_support::traits::{OnUnbalanced, Currency, Get, Time, Randomness};
117-
use frame_support::weights::GetDispatchInfo;
118-
use frame_system::{self as system, ensure_signed, RawOrigin, ensure_root};
115+
use frame_system::{self as system, ensure_signed, ensure_root};
119116
use pallet_contracts_primitives::{RentProjection, ContractAccessError};
120117
use frame_support::weights::Weight;
121118

@@ -321,12 +318,6 @@ pub trait Trait: frame_system::Trait {
321318
/// The currency in which fees are paid and contract balances are held.
322319
type Currency: Currency<Self::AccountId>;
323320

324-
/// The outer call dispatch type.
325-
type Call:
326-
Parameter +
327-
Dispatchable<PostInfo=PostDispatchInfo, Origin=<Self as frame_system::Trait>::Origin> +
328-
IsSubType<Module<Self>, Self> + GetDispatchInfo;
329-
330321
/// The overarching event type.
331322
type Event: From<Event<Self>> + Into<<Self as frame_system::Trait>::Event>;
332323

@@ -644,30 +635,7 @@ impl<T: Trait> Module<T> {
644635
let vm = WasmVm::new(&cfg.schedule);
645636
let loader = WasmLoader::new(&cfg.schedule);
646637
let mut ctx = ExecutionContext::top_level(origin.clone(), &cfg, &vm, &loader);
647-
648-
let result = func(&mut ctx, gas_meter);
649-
650-
// Execute deferred actions.
651-
ctx.deferred.into_iter().for_each(|deferred| {
652-
use self::exec::DeferredAction::*;
653-
match deferred {
654-
DispatchRuntimeCall {
655-
origin: who,
656-
call,
657-
} => {
658-
let info = call.get_dispatch_info();
659-
let result = call.dispatch(RawOrigin::Signed(who.clone()).into());
660-
let post_info = match result {
661-
Ok(post_info) => post_info,
662-
Err(err) => err.post_info,
663-
};
664-
gas_meter.refund(post_info.calc_unspent(&info));
665-
Self::deposit_event(RawEvent::Dispatched(who, result.is_ok()));
666-
}
667-
}
668-
});
669-
670-
result
638+
func(&mut ctx, gas_meter)
671639
}
672640
}
673641

0 commit comments

Comments
 (0)