From 2cef4105736ab969470df2751e78fd3f0fc0a81d Mon Sep 17 00:00:00 2001 From: Maksym Zavershynskyi <35039879+nearmax@users.noreply.github.com> Date: Mon, 27 Apr 2020 19:30:17 -0700 Subject: [PATCH] fix(runtime): Rollback Wasmer to older version (#2533) Due to https://github.com/wasmerio/wasmer/issues/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: https://github.com/nearprotocol/nearcore/pull/2505 After the following PR lands https://github.com/wasmerio/wasmer/pull/1401 we would need to revisit error handling from Wasmer anyway. CC @fckt ### Testing Ran near-evm test. CI passes. --- Cargo.lock | 88 ++++++++++++++++------------ deny.toml | 5 +- runtime/near-vm-runner/Cargo.toml | 4 +- runtime/near-vm-runner/src/errors.rs | 67 ++++++++------------- 4 files changed, 78 insertions(+), 86 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index cea07d6d55f..61c0331dc18 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -477,20 +477,6 @@ dependencies = [ "constant_time_eq 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", ] -[[package]] -name = "blake3" -version = "0.1.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "arrayref 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", - "arrayvec 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)", - "cc 1.0.52 (registry+https://github.com/rust-lang/crates.io-index)", - "cfg-if 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)", - "constant_time_eq 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", - "crypto-mac 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", - "digest 0.8.1 (registry+https://github.com/rust-lang/crates.io-index)", -] - [[package]] name = "block-buffer" version = "0.7.3" @@ -1384,6 +1370,11 @@ dependencies = [ "libc 0.2.69 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "hex" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" + [[package]] name = "hex" version = "0.4.2" @@ -2241,8 +2232,8 @@ dependencies = [ "parity-wasm 0.41.0 (registry+https://github.com/rust-lang/crates.io-index)", "pwasm-utils 0.12.0 (registry+https://github.com/rust-lang/crates.io-index)", "wabt 0.9.2 (registry+https://github.com/rust-lang/crates.io-index)", - "wasmer-runtime 0.16.2 (registry+https://github.com/rust-lang/crates.io-index)", - "wasmer-runtime-core 0.16.2 (registry+https://github.com/rust-lang/crates.io-index)", + "wasmer-runtime 0.13.1 (registry+https://github.com/rust-lang/crates.io-index)", + "wasmer-runtime-core 0.13.1 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -2529,6 +2520,16 @@ name = "parity-wasm" version = "0.41.0" source = "registry+https://github.com/rust-lang/crates.io-index" +[[package]] +name = "parking_lot" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "lock_api 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)", + "parking_lot_core 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)", + "rustc_version 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "parking_lot" version = "0.10.2" @@ -2538,6 +2539,20 @@ dependencies = [ "parking_lot_core 0.7.2 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "parking_lot_core" +version = "0.6.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "cfg-if 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)", + "cloudabi 0.0.3 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.69 (registry+https://github.com/rust-lang/crates.io-index)", + "redox_syscall 0.1.56 (registry+https://github.com/rust-lang/crates.io-index)", + "rustc_version 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)", + "smallvec 0.6.13 (registry+https://github.com/rust-lang/crates.io-index)", + "winapi 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "parking_lot_core" version = "0.7.2" @@ -3356,11 +3371,6 @@ dependencies = [ "winapi 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", ] -[[package]] -name = "target-lexicon" -version = "0.9.0" -source = "registry+https://github.com/rust-lang/crates.io-index" - [[package]] name = "tempfile" version = "3.1.0" @@ -3897,48 +3907,47 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "wasmer-runtime" -version = "0.16.2" +version = "0.13.1" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)", "memmap 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", "serde 1.0.106 (registry+https://github.com/rust-lang/crates.io-index)", "serde_derive 1.0.106 (registry+https://github.com/rust-lang/crates.io-index)", - "wasmer-runtime-core 0.16.2 (registry+https://github.com/rust-lang/crates.io-index)", - "wasmer-singlepass-backend 0.16.2 (registry+https://github.com/rust-lang/crates.io-index)", + "wasmer-runtime-core 0.13.1 (registry+https://github.com/rust-lang/crates.io-index)", + "wasmer-singlepass-backend 0.13.1 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "wasmer-runtime-core" -version = "0.16.2" +version = "0.13.1" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "bincode 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)", - "blake3 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", + "blake2b_simd 0.5.10 (registry+https://github.com/rust-lang/crates.io-index)", "cc 1.0.52 (registry+https://github.com/rust-lang/crates.io-index)", "digest 0.8.1 (registry+https://github.com/rust-lang/crates.io-index)", "errno 0.2.5 (registry+https://github.com/rust-lang/crates.io-index)", - "hex 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", + "hex 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)", "indexmap 1.3.2 (registry+https://github.com/rust-lang/crates.io-index)", "lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)", "libc 0.2.69 (registry+https://github.com/rust-lang/crates.io-index)", "nix 0.15.0 (registry+https://github.com/rust-lang/crates.io-index)", "page_size 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", - "parking_lot 0.10.2 (registry+https://github.com/rust-lang/crates.io-index)", + "parking_lot 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)", "rustc_version 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)", "serde 1.0.106 (registry+https://github.com/rust-lang/crates.io-index)", "serde-bench 0.0.7 (registry+https://github.com/rust-lang/crates.io-index)", "serde_bytes 0.11.3 (registry+https://github.com/rust-lang/crates.io-index)", "serde_derive 1.0.106 (registry+https://github.com/rust-lang/crates.io-index)", "smallvec 0.6.13 (registry+https://github.com/rust-lang/crates.io-index)", - "target-lexicon 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)", - "wasmparser 0.51.4 (registry+https://github.com/rust-lang/crates.io-index)", + "wasmparser 0.45.2 (registry+https://github.com/rust-lang/crates.io-index)", "winapi 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "wasmer-singlepass-backend" -version = "0.16.2" +version = "0.13.1" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "bincode 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)", @@ -3951,12 +3960,12 @@ dependencies = [ "serde 1.0.106 (registry+https://github.com/rust-lang/crates.io-index)", "serde_derive 1.0.106 (registry+https://github.com/rust-lang/crates.io-index)", "smallvec 0.6.13 (registry+https://github.com/rust-lang/crates.io-index)", - "wasmer-runtime-core 0.16.2 (registry+https://github.com/rust-lang/crates.io-index)", + "wasmer-runtime-core 0.13.1 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "wasmparser" -version = "0.51.4" +version = "0.45.2" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] @@ -4096,7 +4105,6 @@ source = "registry+https://github.com/rust-lang/crates.io-index" "checksum bitflags 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "cf1de2fe8c75bc145a2f577add951f8134889b4795d47466a54a5c846d691693" "checksum blake2 0.8.1 (registry+https://github.com/rust-lang/crates.io-index)" = "94cb07b0da6a73955f8fb85d24c466778e70cda767a568229b104f0264089330" "checksum blake2b_simd 0.5.10 (registry+https://github.com/rust-lang/crates.io-index)" = "d8fb2d74254a3a0b5cac33ac9f8ed0e44aa50378d9dbb2e5d83bd21ed1dc2c8a" -"checksum blake3 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "46080006c1505f12f64dd2a09264b343381ed3190fa02c8005d5d662ac571c63" "checksum block-buffer 0.7.3 (registry+https://github.com/rust-lang/crates.io-index)" = "c0940dc441f31689269e10ac70eb1002a3a1d3ad1390e030043662eb7fe4688b" "checksum block-padding 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "fa79dedbb091f449f1f39e53edf88d5dbe95f895dae6135a8d7b881fb5af73f5" "checksum borsh 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)" = "e999aeba3dba8c2a2ac164fc3081a617dbeea104c1cc7fa877d4251f05178eb2" @@ -4196,6 +4204,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" "checksum heapsize 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)" = "1679e6ea370dee694f91f1dc469bf94cf8f52051d147aec3e1f9497c6fc22461" "checksum heck 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "20564e78d53d2bb135c343b3f47714a56af2061f1c928fdb541dc7b9fdd94205" "checksum hermit-abi 0.1.11 (registry+https://github.com/rust-lang/crates.io-index)" = "8a0d737e0f947a1864e93d33fdef4af8445a00d1ed8dc0c8ddb73139ea6abf15" +"checksum hex 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)" = "805026a5d0141ffc30abb3be3173848ad46a1b1664fe632428479619a3644d77" "checksum hex 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)" = "644f9158b2f133fd50f5fb3242878846d9eb792e445c893805ff0e3824006e35" "checksum hex-literal 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "961de220ec9a91af2e1e5bd80d02109155695e516771762381ef8581317066e0" "checksum hex-literal-impl 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "9d4c5c844e2fee0bf673d54c2c177f1713b3d2af2ff6e666b49cb7572e6cf42d" @@ -4268,6 +4277,8 @@ source = "registry+https://github.com/rust-lang/crates.io-index" "checksum parity-secp256k1 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "4fca4f82fccae37e8bbdaeb949a4a218a1bbc485d11598f193d2a908042e5fc1" "checksum parity-wasm 0.41.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ddfc878dac00da22f8f61e7af3157988424567ab01d9920b962ef7dcbd7cd865" "checksum parking_lot 0.10.2 (registry+https://github.com/rust-lang/crates.io-index)" = "d3a704eb390aafdc107b0e392f56a82b668e3a71366993b5340f5833fd62505e" +"checksum parking_lot 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)" = "f842b1982eb6c2fe34036a4fbfb06dd185a3f5c8edfaacdf7d1ea10b07de6252" +"checksum parking_lot_core 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)" = "b876b1b9e7ac6e1a74a6da34d25c42e17e8862aa409cbbbdcfc8d86c6f3bc62b" "checksum parking_lot_core 0.7.2 (registry+https://github.com/rust-lang/crates.io-index)" = "d58c7c768d4ba344e3e8d72518ac13e259d7c7ade24167003b8488e10b6740a3" "checksum peeking_take_while 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "19b17cddbe7ec3f8bc800887bab5e717348c95ea2ca0b1bf0837fb964dc67099" "checksum percent-encoding 2.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "d4fd5641d01c8f18a23da7b6fe29298ff4b55afcccdf78973b24cf3175fee32e" @@ -4357,7 +4368,6 @@ source = "registry+https://github.com/rust-lang/crates.io-index" "checksum syn 1.0.18 (registry+https://github.com/rust-lang/crates.io-index)" = "410a7488c0a728c7ceb4ad59b9567eb4053d02e8cc7f5c0e0eeeb39518369213" "checksum synstructure 0.12.3 (registry+https://github.com/rust-lang/crates.io-index)" = "67656ea1dc1b41b1451851562ea232ec2e5a80242139f7e679ceccfb5d61f545" "checksum sysinfo 0.14.1 (registry+https://github.com/rust-lang/crates.io-index)" = "d070254b7172eee9eb3990bea8f72aeabfe1226c40bf71a52e4fe75777812e9a" -"checksum target-lexicon 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)" = "6f4c118a7a38378f305a9e111fcb2f7f838c0be324bfb31a77ea04f7f6e684b4" "checksum tempfile 3.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "7a6e24d9338a0a5be79593e2fa15a648add6138caa803e2d5bc782c371732ca9" "checksum termcolor 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "bb6bfa289a4d7c5766392812c0a1f4c1ba45afa1ad47803c11e1f407d846d75f" "checksum termios 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)" = "6f0fcee7b24a25675de40d5bb4de6e41b0df07bc9856295e7e2b3a3600c400c2" @@ -4411,10 +4421,10 @@ source = "registry+https://github.com/rust-lang/crates.io-index" "checksum wasm-bindgen-macro 0.2.60 (registry+https://github.com/rust-lang/crates.io-index)" = "8bd151b63e1ea881bb742cd20e1d6127cef28399558f3b5d415289bc41eee3a4" "checksum wasm-bindgen-macro-support 0.2.60 (registry+https://github.com/rust-lang/crates.io-index)" = "d68a5b36eef1be7868f668632863292e37739656a80fc4b9acec7b0bd35a4931" "checksum wasm-bindgen-shared 0.2.60 (registry+https://github.com/rust-lang/crates.io-index)" = "daf76fe7d25ac79748a37538b7daeed1c7a6867c92d3245c12c6222e4a20d639" -"checksum wasmer-runtime 0.16.2 (registry+https://github.com/rust-lang/crates.io-index)" = "434a3454b98844e5d413ba21a2fa5931bb45bcdd8404bb6147b444d5cbf5a3d5" -"checksum wasmer-runtime-core 0.16.2 (registry+https://github.com/rust-lang/crates.io-index)" = "8e32bdb04d008eb136c88a12c0fdfb7e5d7ff30b208af4bef1d292d863eb1ba2" -"checksum wasmer-singlepass-backend 0.16.2 (registry+https://github.com/rust-lang/crates.io-index)" = "b4f850cf15c8d1d29e6010bd980206100cf58f0d4766216a7b24e6b590ab89c0" -"checksum wasmparser 0.51.4 (registry+https://github.com/rust-lang/crates.io-index)" = "aeb1956b19469d1c5e63e459d29e7b5aa0f558d9f16fcef09736f8a265e6c10a" +"checksum wasmer-runtime 0.13.1 (registry+https://github.com/rust-lang/crates.io-index)" = "05726a0bc546d57e06cde6a7754cf9afbf21a5869d080a3c654d35902cd6fab3" +"checksum wasmer-runtime-core 0.13.1 (registry+https://github.com/rust-lang/crates.io-index)" = "7b1131f1bb9a0610eeef2974275de019027fa8dcfac78a9976439ce5f4561ade" +"checksum wasmer-singlepass-backend 0.13.1 (registry+https://github.com/rust-lang/crates.io-index)" = "ae95c8c55b15261a4e99cc8a2eaebf8e63051c4400b2c85209964dac9a811820" +"checksum wasmparser 0.45.2 (registry+https://github.com/rust-lang/crates.io-index)" = "8b4eab1d9971d0803729cba3617b56eb04fcb4bd25361cb63880ed41a42f20d5" "checksum web-sys 0.3.37 (registry+https://github.com/rust-lang/crates.io-index)" = "2d6f51648d8c56c366144378a33290049eafdd784071077f6fe37dae64c1c4cb" "checksum webpki 0.21.2 (registry+https://github.com/rust-lang/crates.io-index)" = "f1f50e1972865d6b1adb54167d1c8ed48606004c2c9d0ea5f1eeb34d95e863ef" "checksum webpki-roots 0.18.0 (registry+https://github.com/rust-lang/crates.io-index)" = "91cd5736df7f12a964a5067a12c62fa38e1bd8080aff1f80bc29be7c80d19ab4" diff --git a/deny.toml b/deny.toml index dd2fa30f929..4047193d5b2 100644 --- a/deny.toml +++ b/deny.toml @@ -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" }, diff --git a/runtime/near-vm-runner/Cargo.toml b/runtime/near-vm-runner/Cargo.toml index b77e982ee90..944bb79a309 100644 --- a/runtime/near-vm-runner/Cargo.toml +++ b/runtime/near-vm-runner/Cargo.toml @@ -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" diff --git a/runtime/near-vm-runner/src/errors.rs b/runtime/near-vm-runner/src/errors.rs index 8b71e9666c7..85b3b594dcd 100644 --- a/runtime/near-vm-runner/src/errors.rs +++ b/runtime/near-vm-runner/src/errors.rs @@ -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 { @@ -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::() { - 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::() { - 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::() { + 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) } } }