Skip to content

Commit

Permalink
fix(runtime): Rollback Wasmer to older version (#2533)
Browse files Browse the repository at this point in the history
Due to wasmerio/wasmer#1409 we need to rollback Wasmer to older version. I am replacing some of Wasmer generated error with Unknown to avoid undoing too much code from this PR: #2505

After the following PR lands wasmerio/wasmer#1401 we would need to revisit error handling from Wasmer anyway. CC @fckt  

### Testing

Ran near-evm test. CI passes.
  • Loading branch information
MaksymZavershynskyi authored Apr 28, 2020
1 parent 7c75fe5 commit 2cef410
Show file tree
Hide file tree
Showing 4 changed files with 78 additions and 86 deletions.
88 changes: 49 additions & 39 deletions Cargo.lock

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

5 changes: 4 additions & 1 deletion deny.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,11 @@ skip = [
# crypto-mac 0.7.0 still uses it: https://github.com/RustCrypto/traits/issues/43
{ name = "subtle", version = "=1.0.0" },

# wasmer-runtime-core v0.16.2 still uses it
# wasmer-runtime-core v0.13.1 still uses it
{ name = "smallvec", version = "=0.6.13" },
{ name = "parking_lot", version = "=0.9.0" },
{ name = "parking_lot_core", version = "=0.6.2" },
{ name = "hex", version = "=0.3.2" },

# wabt 0.9.0 (dev dependency) still uses it
{ name = "glob", version = "=0.2.11" },
Expand Down
4 changes: 2 additions & 2 deletions runtime/near-vm-runner/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ This crate implements the specification of the interface that Near blockchain ex

[dependencies]
cached = "0.12"
wasmer-runtime = { version = "0.16.2", features = ["default-backend-singlepass"], default-features = false }
wasmer-runtime-core = { version = "0.16.2" }
wasmer-runtime = { version = "0.13.1", features = ["default-backend-singlepass"], default-features = false }
wasmer-runtime-core = { version = "0.13.1" }
pwasm-utils = "0.12"
parity-wasm = "0.41"

Expand Down
67 changes: 23 additions & 44 deletions runtime/near-vm-runner/src/errors.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use near_vm_errors::{CompilationError, FunctionCallError, MethodResolveError, VMError, WasmTrap};
use near_vm_errors::FunctionCallError::WasmUnknownError;
use near_vm_errors::{CompilationError, FunctionCallError, MethodResolveError, VMError};
use near_vm_logic::VMLogicError;

pub trait IntoVMError {
Expand Down Expand Up @@ -64,51 +65,29 @@ impl IntoVMError for wasmer_runtime::error::ResolveError {

impl IntoVMError for wasmer_runtime::error::RuntimeError {
fn into_vm_error(self) -> VMError {
use wasmer_runtime::ExceptionCode;
let data = &*self.0;

if let Some(err) = data.downcast_ref::<VMLogicError>() {
match err {
VMLogicError::HostError(h) => {
VMError::FunctionCallError(FunctionCallError::HostError(h.clone()))
}
VMLogicError::ExternalError(s) => VMError::ExternalError(s.clone()),
VMLogicError::InconsistentStateError(e) => {
VMError::InconsistentStateError(e.clone())
}
}
} else if let Some(err) = data.downcast_ref::<ExceptionCode>() {
use wasmer_runtime::ExceptionCode::*;
match err {
Unreachable => {
VMError::FunctionCallError(FunctionCallError::WasmTrap(WasmTrap::Unreachable))
use wasmer_runtime::error::RuntimeError;
match &self {
RuntimeError::Trap { msg: _ } => VMError::FunctionCallError(WasmUnknownError),
RuntimeError::Error { data } => {
if let Some(err) = data.downcast_ref::<VMLogicError>() {
match err {
VMLogicError::HostError(h) => {
VMError::FunctionCallError(FunctionCallError::HostError(h.clone()))
}
VMLogicError::ExternalError(s) => VMError::ExternalError(s.clone()),
VMLogicError::InconsistentStateError(e) => {
VMError::InconsistentStateError(e.clone())
}
}
} else {
eprintln!(
"Bad error case! Output is non-deterministic {:?} {:?}",
data.type_id(),
self.to_string()
);
VMError::FunctionCallError(WasmUnknownError)
}
IncorrectCallIndirectSignature => VMError::FunctionCallError(
FunctionCallError::WasmTrap(WasmTrap::IncorrectCallIndirectSignature),
),
MemoryOutOfBounds => VMError::FunctionCallError(FunctionCallError::WasmTrap(
WasmTrap::MemoryOutOfBounds,
)),
CallIndirectOOB => VMError::FunctionCallError(FunctionCallError::WasmTrap(
WasmTrap::CallIndirectOOB,
)),
IllegalArithmetic => VMError::FunctionCallError(FunctionCallError::WasmTrap(
WasmTrap::IllegalArithmetic,
)),
MisalignedAtomicAccess => VMError::FunctionCallError(FunctionCallError::WasmTrap(
WasmTrap::MisalignedAtomicAccess,
)),
}
} else {
// TODO: Wasmer provides no way to distingush runtime Internal Wasmer errors or host panics
// (at least for a single-pass backend)
// https://github.com/wasmerio/wasmer/issues/1338
eprintln!(
"Bad error case! Output might be non-deterministic {:?} {:?}",
data.type_id(),
self.to_string()
);
VMError::FunctionCallError(FunctionCallError::WasmUnknownError)
}
}
}

0 comments on commit 2cef410

Please sign in to comment.