seal: Change prefix and module name from "ext_" to "seal_" for contract callable functions (#6798)

* seal: Change prefix "ext_" to "seal_" for contract callable functions

The word Ext is a overloaded term in the context of substrate. It usually
is a trait which abstracts away access to external resources usually in order
to mock them away for the purpose of tests. The contract module has its own
`Ext` trait in addition the the substrate `Ext` which makes things even more
confusing.

In order to differentiate the contract callable functions more clearly from
this `Ext` concept we rename them to use the "seal_" prefix instead.

This should change no behaviour at all. This is a pure renaming commit.

* seal: Rename import module from "env" to "seal0"

* seal: Fixup integration test

* seal: Add more tests for new import module names
This commit is contained in:
Alexander Theißen
2020-08-10 15:14:34 +02:00
committed by GitHub
parent f9f8262303
commit 04b185e3d4
29 changed files with 355 additions and 303 deletions
+68 -68
View File
@@ -127,9 +127,9 @@ impl<'a, T: Trait> crate::exec::Vm<T> for WasmVm<'a> {
});
let mut imports = sp_sandbox::EnvironmentDefinitionBuilder::new();
imports.add_memory("env", "memory", memory.clone());
imports.add_memory(self::prepare::IMPORT_MODULE_MEMORY, "memory", memory.clone());
runtime::Env::impls(&mut |name, func_ptr| {
imports.add_host_func("env", name, func_ptr);
imports.add_host_func(self::prepare::IMPORT_MODULE_FN, name, func_ptr);
});
let mut runtime = Runtime::new(
@@ -477,17 +477,17 @@ mod tests {
const CODE_TRANSFER: &str = r#"
(module
;; ext_transfer(
;; seal_transfer(
;; account_ptr: u32,
;; account_len: u32,
;; value_ptr: u32,
;; value_len: u32,
;;) -> u32
(import "env" "ext_transfer" (func $ext_transfer (param i32 i32 i32 i32) (result i32)))
(import "seal0" "seal_transfer" (func $seal_transfer (param i32 i32 i32 i32) (result i32)))
(import "env" "memory" (memory 1 1))
(func (export "call")
(drop
(call $ext_transfer
(call $seal_transfer
(i32.const 4) ;; Pointer to "account" address.
(i32.const 8) ;; Length of "account" address.
(i32.const 12) ;; Pointer to the buffer with value to transfer
@@ -530,7 +530,7 @@ mod tests {
const CODE_CALL: &str = r#"
(module
;; ext_call(
;; seal_call(
;; callee_ptr: u32,
;; callee_len: u32,
;; gas: u64,
@@ -541,11 +541,11 @@ mod tests {
;; output_ptr: u32,
;; output_len_ptr: u32
;;) -> u32
(import "env" "ext_call" (func $ext_call (param i32 i32 i64 i32 i32 i32 i32 i32 i32) (result i32)))
(import "seal0" "seal_call" (func $seal_call (param i32 i32 i64 i32 i32 i32 i32 i32 i32) (result i32)))
(import "env" "memory" (memory 1 1))
(func (export "call")
(drop
(call $ext_call
(call $seal_call
(i32.const 4) ;; Pointer to "callee" address.
(i32.const 8) ;; Length of "callee" address.
(i64.const 0) ;; How much gas to devote for the execution. 0 = all.
@@ -594,7 +594,7 @@ mod tests {
const CODE_INSTANTIATE: &str = r#"
(module
;; ext_instantiate(
;; seal_instantiate(
;; code_ptr: u32,
;; code_len: u32,
;; gas: u64,
@@ -608,11 +608,11 @@ mod tests {
;; output_ptr: u32,
;; output_len_ptr: u32
;; ) -> u32
(import "env" "ext_instantiate" (func $ext_instantiate (param i32 i32 i64 i32 i32 i32 i32 i32 i32 i32 i32) (result i32)))
(import "seal0" "seal_instantiate" (func $seal_instantiate (param i32 i32 i64 i32 i32 i32 i32 i32 i32 i32 i32) (result i32)))
(import "env" "memory" (memory 1 1))
(func (export "call")
(drop
(call $ext_instantiate
(call $seal_instantiate
(i32.const 16) ;; Pointer to `code_hash`
(i32.const 32) ;; Length of `code_hash`
(i64.const 0) ;; How much gas to devote for the execution. 0 = all.
@@ -665,14 +665,14 @@ mod tests {
const CODE_TERMINATE: &str = r#"
(module
;; ext_terminate(
;; seal_terminate(
;; beneficiary_ptr: u32,
;; beneficiary_len: u32,
;; )
(import "env" "ext_terminate" (func $ext_terminate (param i32 i32)))
(import "seal0" "seal_terminate" (func $seal_terminate (param i32 i32)))
(import "env" "memory" (memory 1 1))
(func (export "call")
(call $ext_terminate
(call $seal_terminate
(i32.const 4) ;; Pointer to "beneficiary" address.
(i32.const 8) ;; Length of "beneficiary" address.
)
@@ -706,7 +706,7 @@ mod tests {
const CODE_TRANSFER_LIMITED_GAS: &str = r#"
(module
;; ext_call(
;; seal_call(
;; callee_ptr: u32,
;; callee_len: u32,
;; gas: u64,
@@ -717,11 +717,11 @@ mod tests {
;; output_ptr: u32,
;; output_len_ptr: u32
;;) -> u32
(import "env" "ext_call" (func $ext_call (param i32 i32 i64 i32 i32 i32 i32 i32 i32) (result i32)))
(import "seal0" "seal_call" (func $seal_call (param i32 i32 i64 i32 i32 i32 i32 i32 i32) (result i32)))
(import "env" "memory" (memory 1 1))
(func (export "call")
(drop
(call $ext_call
(call $seal_call
(i32.const 4) ;; Pointer to "callee" address.
(i32.const 8) ;; Length of "callee" address.
(i64.const 228) ;; How much gas to devote for the execution.
@@ -770,8 +770,8 @@ mod tests {
const CODE_GET_STORAGE: &str = r#"
(module
(import "env" "ext_get_storage" (func $ext_get_storage (param i32 i32 i32) (result i32)))
(import "env" "ext_return" (func $ext_return (param i32 i32 i32)))
(import "seal0" "seal_get_storage" (func $seal_get_storage (param i32 i32 i32) (result i32)))
(import "seal0" "seal_return" (func $seal_return (param i32 i32 i32)))
(import "env" "memory" (memory 1 1))
;; [0, 32) key for get storage
@@ -800,7 +800,7 @@ mod tests {
;; Load a storage value into contract memory.
(call $assert
(i32.eq
(call $ext_get_storage
(call $seal_get_storage
(i32.const 0) ;; The pointer to the storage key to fetch
(i32.const 36) ;; Pointer to the output buffer
(i32.const 32) ;; Pointer to the size of the buffer
@@ -818,13 +818,13 @@ mod tests {
)
;; Return the contents of the buffer
(call $ext_return
(call $seal_return
(i32.const 0)
(i32.const 36)
(get_local $buf_size)
)
;; env:ext_return doesn't return, so this is effectively unreachable.
;; env:seal_return doesn't return, so this is effectively unreachable.
(unreachable)
)
@@ -849,10 +849,10 @@ mod tests {
assert_eq!(output, ExecReturnValue { flags: ReturnFlags::empty(), data: [0x22; 32].to_vec() });
}
/// calls `ext_caller` and compares the result with the constant 42.
/// calls `seal_caller` and compares the result with the constant 42.
const CODE_CALLER: &str = r#"
(module
(import "env" "ext_caller" (func $ext_caller (param i32 i32)))
(import "seal0" "seal_caller" (func $seal_caller (param i32 i32)))
(import "env" "memory" (memory 1 1))
;; size of our buffer is 32 bytes
@@ -869,7 +869,7 @@ mod tests {
(func (export "call")
;; fill the buffer with the caller.
(call $ext_caller (i32.const 0) (i32.const 32))
(call $seal_caller (i32.const 0) (i32.const 32))
;; assert len == 8
(call $assert
@@ -902,10 +902,10 @@ mod tests {
).unwrap();
}
/// calls `ext_address` and compares the result with the constant 69.
/// calls `seal_address` and compares the result with the constant 69.
const CODE_ADDRESS: &str = r#"
(module
(import "env" "ext_address" (func $ext_address (param i32 i32)))
(import "seal0" "seal_address" (func $seal_address (param i32 i32)))
(import "env" "memory" (memory 1 1))
;; size of our buffer is 32 bytes
@@ -922,7 +922,7 @@ mod tests {
(func (export "call")
;; fill the buffer with the self address.
(call $ext_address (i32.const 0) (i32.const 32))
(call $seal_address (i32.const 0) (i32.const 32))
;; assert size == 8
(call $assert
@@ -957,7 +957,7 @@ mod tests {
const CODE_BALANCE: &str = r#"
(module
(import "env" "ext_balance" (func $ext_balance (param i32 i32)))
(import "seal0" "seal_balance" (func $seal_balance (param i32 i32)))
(import "env" "memory" (memory 1 1))
;; size of our buffer is 32 bytes
@@ -974,7 +974,7 @@ mod tests {
(func (export "call")
;; This stores the balance in the buffer
(call $ext_balance (i32.const 0) (i32.const 32))
(call $seal_balance (i32.const 0) (i32.const 32))
;; assert len == 8
(call $assert
@@ -1009,7 +1009,7 @@ mod tests {
const CODE_GAS_PRICE: &str = r#"
(module
(import "env" "ext_weight_to_fee" (func $ext_weight_to_fee (param i64 i32 i32)))
(import "seal0" "seal_weight_to_fee" (func $seal_weight_to_fee (param i64 i32 i32)))
(import "env" "memory" (memory 1 1))
;; size of our buffer is 32 bytes
@@ -1026,7 +1026,7 @@ mod tests {
(func (export "call")
;; This stores the gas price in the buffer
(call $ext_weight_to_fee (i64.const 2) (i32.const 0) (i32.const 32))
(call $seal_weight_to_fee (i64.const 2) (i32.const 0) (i32.const 32))
;; assert len == 8
(call $assert
@@ -1061,8 +1061,8 @@ mod tests {
const CODE_GAS_LEFT: &str = r#"
(module
(import "env" "ext_gas_left" (func $ext_gas_left (param i32 i32)))
(import "env" "ext_return" (func $ext_return (param i32 i32 i32)))
(import "seal0" "seal_gas_left" (func $seal_gas_left (param i32 i32)))
(import "seal0" "seal_return" (func $seal_return (param i32 i32 i32)))
(import "env" "memory" (memory 1 1))
;; size of our buffer is 32 bytes
@@ -1079,7 +1079,7 @@ mod tests {
(func (export "call")
;; This stores the gas left in the buffer
(call $ext_gas_left (i32.const 0) (i32.const 32))
(call $seal_gas_left (i32.const 0) (i32.const 32))
;; assert len == 8
(call $assert
@@ -1090,7 +1090,7 @@ mod tests {
)
;; return gas left
(call $ext_return (i32.const 0) (i32.const 0) (i32.const 8))
(call $seal_return (i32.const 0) (i32.const 0) (i32.const 8))
(unreachable)
)
@@ -1116,7 +1116,7 @@ mod tests {
const CODE_VALUE_TRANSFERRED: &str = r#"
(module
(import "env" "ext_value_transferred" (func $ext_value_transferred (param i32 i32)))
(import "seal0" "seal_value_transferred" (func $seal_value_transferred (param i32 i32)))
(import "env" "memory" (memory 1 1))
;; size of our buffer is 32 bytes
@@ -1133,7 +1133,7 @@ mod tests {
(func (export "call")
;; This stores the value transferred in the buffer
(call $ext_value_transferred (i32.const 0) (i32.const 32))
(call $seal_value_transferred (i32.const 0) (i32.const 32))
;; assert len == 8
(call $assert
@@ -1168,12 +1168,12 @@ mod tests {
const CODE_RETURN_FROM_START_FN: &str = r#"
(module
(import "env" "ext_return" (func $ext_return (param i32 i32 i32)))
(import "seal0" "seal_return" (func $seal_return (param i32 i32 i32)))
(import "env" "memory" (memory 1 1))
(start $start)
(func $start
(call $ext_return
(call $seal_return
(i32.const 0)
(i32.const 8)
(i32.const 4)
@@ -1204,7 +1204,7 @@ mod tests {
const CODE_TIMESTAMP_NOW: &str = r#"
(module
(import "env" "ext_now" (func $ext_now (param i32 i32)))
(import "seal0" "seal_now" (func $seal_now (param i32 i32)))
(import "env" "memory" (memory 1 1))
;; size of our buffer is 32 bytes
@@ -1221,7 +1221,7 @@ mod tests {
(func (export "call")
;; This stores the block timestamp in the buffer
(call $ext_now (i32.const 0) (i32.const 32))
(call $seal_now (i32.const 0) (i32.const 32))
;; assert len == 8
(call $assert
@@ -1256,7 +1256,7 @@ mod tests {
const CODE_MINIMUM_BALANCE: &str = r#"
(module
(import "env" "ext_minimum_balance" (func $ext_minimum_balance (param i32 i32)))
(import "seal0" "seal_minimum_balance" (func $seal_minimum_balance (param i32 i32)))
(import "env" "memory" (memory 1 1))
;; size of our buffer is 32 bytes
@@ -1272,7 +1272,7 @@ mod tests {
)
(func (export "call")
(call $ext_minimum_balance (i32.const 0) (i32.const 32))
(call $seal_minimum_balance (i32.const 0) (i32.const 32))
;; assert len == 8
(call $assert
@@ -1307,7 +1307,7 @@ mod tests {
const CODE_TOMBSTONE_DEPOSIT: &str = r#"
(module
(import "env" "ext_tombstone_deposit" (func $ext_tombstone_deposit (param i32 i32)))
(import "seal0" "seal_tombstone_deposit" (func $seal_tombstone_deposit (param i32 i32)))
(import "env" "memory" (memory 1 1))
;; size of our buffer is 32 bytes
@@ -1323,7 +1323,7 @@ mod tests {
)
(func (export "call")
(call $ext_tombstone_deposit (i32.const 0) (i32.const 32))
(call $seal_tombstone_deposit (i32.const 0) (i32.const 32))
;; assert len == 8
(call $assert
@@ -1358,8 +1358,8 @@ mod tests {
const CODE_RANDOM: &str = r#"
(module
(import "env" "ext_random" (func $ext_random (param i32 i32 i32 i32)))
(import "env" "ext_return" (func $ext_return (param i32 i32 i32)))
(import "seal0" "seal_random" (func $seal_random (param i32 i32 i32 i32)))
(import "seal0" "seal_return" (func $seal_return (param i32 i32 i32)))
(import "env" "memory" (memory 1 1))
;; [0,128) is reserved for the result of PRNG.
@@ -1384,7 +1384,7 @@ mod tests {
(func (export "call")
;; This stores the block random seed in the buffer
(call $ext_random
(call $seal_random
(i32.const 128) ;; Pointer in memory to the start of the subject buffer
(i32.const 32) ;; The subject buffer's length
(i32.const 0) ;; Pointer to the output buffer
@@ -1400,7 +1400,7 @@ mod tests {
)
;; return the random data
(call $ext_return
(call $seal_return
(i32.const 0)
(i32.const 0)
(i32.const 32)
@@ -1433,11 +1433,11 @@ mod tests {
const CODE_DEPOSIT_EVENT: &str = r#"
(module
(import "env" "ext_deposit_event" (func $ext_deposit_event (param i32 i32 i32 i32)))
(import "seal0" "seal_deposit_event" (func $seal_deposit_event (param i32 i32 i32 i32)))
(import "env" "memory" (memory 1 1))
(func (export "call")
(call $ext_deposit_event
(call $seal_deposit_event
(i32.const 32) ;; Pointer to the start of topics buffer
(i32.const 33) ;; The length of the topics buffer.
(i32.const 8) ;; Pointer to the start of the data buffer
@@ -1475,11 +1475,11 @@ mod tests {
const CODE_DEPOSIT_EVENT_MAX_TOPICS: &str = r#"
(module
(import "env" "ext_deposit_event" (func $ext_deposit_event (param i32 i32 i32 i32)))
(import "seal0" "seal_deposit_event" (func $seal_deposit_event (param i32 i32 i32 i32)))
(import "env" "memory" (memory 1 1))
(func (export "call")
(call $ext_deposit_event
(call $seal_deposit_event
(i32.const 32) ;; Pointer to the start of topics buffer
(i32.const 161) ;; The length of the topics buffer.
(i32.const 8) ;; Pointer to the start of the data buffer
@@ -1521,11 +1521,11 @@ mod tests {
const CODE_DEPOSIT_EVENT_DUPLICATES: &str = r#"
(module
(import "env" "ext_deposit_event" (func $ext_deposit_event (param i32 i32 i32 i32)))
(import "seal0" "seal_deposit_event" (func $seal_deposit_event (param i32 i32 i32 i32)))
(import "env" "memory" (memory 1 1))
(func (export "call")
(call $ext_deposit_event
(call $seal_deposit_event
(i32.const 32) ;; Pointer to the start of topics buffer
(i32.const 129) ;; The length of the topics buffer.
(i32.const 8) ;; Pointer to the start of the data buffer
@@ -1564,10 +1564,10 @@ mod tests {
);
}
/// calls `ext_block_number` compares the result with the constant 121.
/// calls `seal_block_number` compares the result with the constant 121.
const CODE_BLOCK_NUMBER: &str = r#"
(module
(import "env" "ext_block_number" (func $ext_block_number (param i32 i32)))
(import "seal0" "seal_block_number" (func $seal_block_number (param i32 i32)))
(import "env" "memory" (memory 1 1))
;; size of our buffer is 32 bytes
@@ -1584,7 +1584,7 @@ mod tests {
(func (export "call")
;; This stores the block height in the buffer
(call $ext_block_number (i32.const 0) (i32.const 32))
(call $seal_block_number (i32.const 0) (i32.const 32))
;; assert len == 8
(call $assert
@@ -1619,8 +1619,8 @@ mod tests {
const CODE_RETURN_WITH_DATA: &str = r#"
(module
(import "env" "ext_input" (func $ext_input (param i32 i32)))
(import "env" "ext_return" (func $ext_return (param i32 i32 i32)))
(import "seal0" "seal_input" (func $seal_input (param i32 i32)))
(import "seal0" "seal_return" (func $seal_return (param i32 i32 i32)))
(import "env" "memory" (memory 1 1))
(data (i32.const 32) "\20")
@@ -1633,13 +1633,13 @@ mod tests {
;; Call reads the first 4 bytes (LE) as the exit status and returns the rest as output data.
(func $call (export "call")
;; Copy input data this contract memory.
(call $ext_input
(call $seal_input
(i32.const 0) ;; Pointer where to store input
(i32.const 32) ;; Pointer to the length of the buffer
)
;; Copy all but the first 4 bytes of the input data as the output data.
(call $ext_return
(call $seal_return
(i32.load (i32.const 0))
(i32.const 4)
(i32.sub (i32.load (i32.const 32)) (i32.const 4))
@@ -1650,7 +1650,7 @@ mod tests {
"#;
#[test]
fn ext_return_with_success_status() {
fn seal_return_with_success_status() {
let output = execute(
CODE_RETURN_WITH_DATA,
hex!("00000000445566778899").to_vec(),
@@ -1677,13 +1677,13 @@ mod tests {
const CODE_OUT_OF_BOUNDS_ACCESS: &str = r#"
(module
(import "env" "ext_terminate" (func $ext_terminate (param i32 i32)))
(import "seal0" "seal_terminate" (func $seal_terminate (param i32 i32)))
(import "env" "memory" (memory 1 1))
(func (export "deploy"))
(func (export "call")
(call $ext_terminate
(call $seal_terminate
(i32.const 65536) ;; Pointer to "account" address (out of bound).
(i32.const 8) ;; Length of "account" address.
)
@@ -1712,13 +1712,13 @@ mod tests {
const CODE_DECODE_FAILURE: &str = r#"
(module
(import "env" "ext_terminate" (func $ext_terminate (param i32 i32)))
(import "seal0" "seal_terminate" (func $seal_terminate (param i32 i32)))
(import "env" "memory" (memory 1 1))
(func (export "deploy"))
(func (export "call")
(call $ext_terminate
(call $seal_terminate
(i32.const 0) ;; Pointer to "account" address.
(i32.const 4) ;; Length of "account" address (too small -> decode fail).
)