Skip to content
This repository was archived by the owner on Nov 15, 2023. It is now read-only.
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
69 changes: 44 additions & 25 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion bin/node/cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,6 @@ pallet-balances = { version = "4.0.0-dev", path = "../../../frame/balances" }
[features]
default = ["cli"]
cli = [
"node-executor/wasmi-errno",
"node-inspect",
"sc-cli",
"frame-benchmarking-cli",
Expand Down
1 change: 0 additions & 1 deletion bin/node/executor/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ sp-runtime = { version = "6.0.0", path = "../../../primitives/runtime" }

[features]
wasmtime = ["sc-executor/wasmtime"]
wasmi-errno = ["sc-executor/wasmi-errno"]
stress-test = []

[[bench]]
Expand Down
3 changes: 1 addition & 2 deletions client/executor/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ lazy_static = "1.4.0"
lru = "0.7.5"
parking_lot = "0.12.1"
tracing = "0.1.29"
wasmi = "0.9.1"
wasmi = "0.13"

codec = { package = "parity-scale-codec", version = "3.0.0" }
sc-executor-common = { version = "0.10.0-dev", path = "common" }
Expand Down Expand Up @@ -63,5 +63,4 @@ default = ["std"]
std = []
wasm-extern-trace = []
wasmtime = ["sc-executor-wasmtime"]
wasmi-errno = ["wasmi/errno"]
wasmer-sandbox = ["sc-executor-common/wasmer-sandbox"]
4 changes: 2 additions & 2 deletions client/executor/common/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ targets = ["x86_64-unknown-linux-gnu"]
codec = { package = "parity-scale-codec", version = "3.0.0" }
environmental = "1.1.3"
thiserror = "1.0.30"
wasm-instrument = "0.1"
wasm-instrument = "0.2"
wasmer = { version = "2.2", features = ["singlepass"], optional = true }
wasmi = "0.9.1"
wasmi = "0.13"
sc-allocator = { version = "4.1.0-dev", path = "../../allocator" }
sp-maybe-compressed-blob = { version = "4.1.0-dev", path = "../../../primitives/maybe-compressed-blob" }
sp-sandbox = { version = "0.10.0-dev", path = "../../../primitives/sandbox" }
Expand Down
17 changes: 14 additions & 3 deletions client/executor/common/src/sandbox/wasmi_backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,14 @@

//! Wasmi specific impls for sandbox

use std::rc::Rc;
use std::{fmt, rc::Rc};

use codec::{Decode, Encode};
use sp_sandbox::HostError;
use sp_wasm_interface::{FunctionContext, Pointer, ReturnValue, Value, WordSize};
use wasmi::{
memory_units::Pages, ImportResolver, MemoryInstance, Module, ModuleInstance, RuntimeArgs,
RuntimeValue, Trap, TrapKind,
RuntimeValue, Trap,
};

use crate::{
Expand All @@ -39,9 +39,20 @@ use crate::{

environmental::environmental!(SandboxContextStore: trait SandboxContext);

#[derive(Debug)]
struct CustomHostError(String);

impl fmt::Display for CustomHostError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "HostError: {}", self.0)
}
}

impl wasmi::HostError for CustomHostError {}

/// Construct trap error from specified message
fn trap(msg: &'static str) -> Trap {
TrapKind::Host(Box::new(Error::Other(msg.into()))).into()
Trap::host(CustomHostError(msg.into()))
}

impl ImportResolver for Imports {
Expand Down
6 changes: 3 additions & 3 deletions client/executor/src/integration_tests/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ fn call_not_existing_function(wasm_method: WasmExecutionMethod) {
match call_in_wasm("test_calling_missing_external", &[], wasm_method, &mut ext).unwrap_err() {
Error::AbortedDueToTrap(error) => {
let expected = match wasm_method {
WasmExecutionMethod::Interpreted => "Trap: Host(Other(\"Function `missing_external` is only a stub. Calling a stub is not allowed.\"))",
WasmExecutionMethod::Interpreted => "Other: Function `missing_external` is only a stub. Calling a stub is not allowed.",
#[cfg(feature = "wasmtime")]
WasmExecutionMethod::Compiled { .. } => "call to a missing function env:missing_external"
};
Expand All @@ -273,7 +273,7 @@ fn call_yet_another_not_existing_function(wasm_method: WasmExecutionMethod) {
{
Error::AbortedDueToTrap(error) => {
let expected = match wasm_method {
WasmExecutionMethod::Interpreted => "Trap: Host(Other(\"Function `yet_another_missing_external` is only a stub. Calling a stub is not allowed.\"))",
WasmExecutionMethod::Interpreted => "Other: Function `yet_another_missing_external` is only a stub. Calling a stub is not allowed.",
#[cfg(feature = "wasmtime")]
WasmExecutionMethod::Compiled { .. } => "call to a missing function env:yet_another_missing_external"
};
Expand Down Expand Up @@ -909,7 +909,7 @@ fn unreachable_intrinsic(wasm_method: WasmExecutionMethod) {
match call_in_wasm("test_unreachable_intrinsic", &[], wasm_method, &mut ext).unwrap_err() {
Error::AbortedDueToTrap(error) => {
let expected = match wasm_method {
WasmExecutionMethod::Interpreted => "Trap: Unreachable",
WasmExecutionMethod::Interpreted => "unreachable",
#[cfg(feature = "wasmtime")]
WasmExecutionMethod::Compiled { .. } => "wasm trap: wasm `unreachable` instruction executed",
};
Expand Down
2 changes: 1 addition & 1 deletion client/executor/wasmi/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ targets = ["x86_64-unknown-linux-gnu"]
[dependencies]
codec = { package = "parity-scale-codec", version = "3.0.0" }
log = "0.4.17"
wasmi = "0.9.1"
wasmi = "0.13"
sc-allocator = { version = "4.1.0-dev", path = "../../allocator" }
sc-executor-common = { version = "0.10.0-dev", path = "../common" }
sp-runtime-interface = { version = "6.0.0", path = "../../../primitives/runtime-interface" }
Expand Down
2 changes: 2 additions & 0 deletions client/executor/wasmi/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,7 @@ impl Sandbox for FunctionExecutor {

let len = val_len as usize;

#[allow(deprecated)]
let buffer = match self.memory.get(val_ptr.into(), len) {
Err(_) => return Ok(sandbox_env::ERR_OUT_OF_BOUNDS),
Ok(buffer) => buffer,
Expand Down Expand Up @@ -568,6 +569,7 @@ fn call_in_wasm_module(
match result {
Ok(Some(I64(r))) => {
let (ptr, length) = unpack_ptr_and_len(r as u64);
#[allow(deprecated)]
memory.get(ptr, length as usize).map_err(|_| Error::Runtime)
},
Err(e) => {
Expand Down
2 changes: 1 addition & 1 deletion client/executor/wasmtime/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ cfg-if = "1.0"
codec = { package = "parity-scale-codec", version = "3.0.0" }
libc = "0.2.121"
log = "0.4.17"
parity-wasm = "0.42.0"
parity-wasm = "0.45"

# When bumping wasmtime do not forget to also bump rustix
# to exactly the same version as used by wasmtime!
Expand Down
4 changes: 2 additions & 2 deletions frame/contracts/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@ codec = { package = "parity-scale-codec", version = "3.0.0", default-features =
] }
scale-info = { version = "2.1.1", default-features = false, features = ["derive"] }
log = { version = "0.4", default-features = false }
wasm-instrument = { version = "0.1", default-features = false }
wasm-instrument = { version = "0.2", default-features = false }
serde = { version = "1", optional = true, features = ["derive"] }
smallvec = { version = "1", default-features = false, features = [
"const_generics",
] }
wasmi-validation = { version = "0.4", default-features = false }
wasmi-validation = { version = "0.5", default-features = false }
impl-trait-for-tuples = "0.2"

# Only used in benchmarking to generate random contract code
Expand Down
10 changes: 5 additions & 5 deletions frame/contracts/src/benchmarking/code.rs
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ where
for func in def.imported_functions {
let sig = builder::signature()
.with_params(func.params)
.with_results(func.return_type.into_iter().collect())
.with_results(func.return_type)
.build_sig();
let sig = contract.push_signature(sig);
contract = contract
Expand Down Expand Up @@ -254,9 +254,9 @@ where
code = inject_stack_metering::<T>(code);
}

let code = code.to_bytes().unwrap();
let code = code.into_bytes().unwrap();
let hash = T::Hashing::hash(&code);
Self { code, hash, memory: def.memory }
Self { code: code.into(), hash, memory: def.memory }
}
}

Expand Down Expand Up @@ -285,11 +285,11 @@ where
.find_map(|e| if let External::Memory(mem) = e.external() { Some(mem) } else { None })
.unwrap()
.limits();
let code = module.to_bytes().unwrap();
let code = module.into_bytes().unwrap();
let hash = T::Hashing::hash(&code);
let memory =
ImportedMemory { min_pages: limits.initial(), max_pages: limits.maximum().unwrap() };
Self { code, hash, memory: Some(memory) }
Self { code: code.into(), hash, memory: Some(memory) }
}

/// Creates a wasm module with an empty `call` and `deploy` function and nothing else.
Expand Down
2 changes: 1 addition & 1 deletion frame/contracts/src/wasm/prepare.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ impl<'a, T: Config> ContractModule<'a, T> {
elements::deserialize_buffer(original_code).map_err(|_| "Can't decode wasm code")?;

// Make sure that the module is valid.
validate_module::<PlainValidator>(&module).map_err(|_| "Module is not valid")?;
validate_module::<PlainValidator>(&module, ()).map_err(|_| "Module is not valid")?;

// Return a `ContractModule` instance with
// __valid__ module.
Expand Down
Loading