From c74d978b4582b016797d6ba3373ed652c1509427 Mon Sep 17 00:00:00 2001 From: Simon Warta Date: Wed, 9 Dec 2020 17:44:51 +0100 Subject: [PATCH 1/2] Add ref_to_u32 --- packages/vm/src/conversion.rs | 49 +++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) diff --git a/packages/vm/src/conversion.rs b/packages/vm/src/conversion.rs index c6fd82dc9c..e763021c1a 100644 --- a/packages/vm/src/conversion.rs +++ b/packages/vm/src/conversion.rs @@ -12,6 +12,14 @@ pub fn to_u32 + Display + Copy>(input: T) -> VmResult { }) } +/// Safely converts input of type &T to u32. +/// Errors with a cosmwasm_vm::errors::VmError::ConversionErr if conversion cannot be done. +pub fn ref_to_u32 + ToString + Clone>(input: &T) -> VmResult { + input.clone().try_into().map_err(|_| { + VmError::conversion_err(type_name::(), type_name::(), input.to_string()) + }) +} + /// Safely converts input of type T to i32. /// Errors with a cosmwasm_vm::errors::VmError::ConversionErr if conversion cannot be done. /// @@ -98,6 +106,47 @@ mod test { }; } + #[test] + fn ref_to_u32_works() { + // i32 + assert_eq!(ref_to_u32(&0i32).unwrap(), 0); + assert_eq!(ref_to_u32(&1i32).unwrap(), 1); + assert_eq!(ref_to_u32(&2147483647i32).unwrap(), 2147483647); + match ref_to_u32(&-1i32).unwrap_err() { + VmError::ConversionErr { + from_type, + to_type, + input, + .. + } => { + assert_eq!(from_type, "i32"); + assert_eq!(to_type, "u32"); + assert_eq!(input, "-1"); + } + err => panic!("Unexpected error: {:?}", err), + }; + + // usize + assert_eq!(ref_to_u32(&0usize).unwrap(), 0); + assert_eq!(ref_to_u32(&1usize).unwrap(), 1); + assert_eq!(ref_to_u32(&2147483647usize).unwrap(), 2147483647); + assert_eq!(ref_to_u32(&2147483648usize).unwrap(), 2147483648); + assert_eq!(ref_to_u32(&4294967295usize).unwrap(), 4294967295); + match ref_to_u32(&4294967296usize).unwrap_err() { + VmError::ConversionErr { + from_type, + to_type, + input, + .. + } => { + assert_eq!(from_type, "usize"); + assert_eq!(to_type, "u32"); + assert_eq!(input, "4294967296"); + } + err => panic!("Unexpected error: {:?}", err), + }; + } + #[test] fn to_i32_works_for_usize() { assert_eq!(to_i32(0usize).unwrap(), 0); From 57bbf42a50b1099eb504cb87b3c255f0fab657b8 Mon Sep 17 00:00:00 2001 From: Simon Warta Date: Wed, 9 Dec 2020 17:56:58 +0100 Subject: [PATCH 2/2] Use ref_to_u32 for Wasmer's Value --- Cargo.lock | 22 +++++++++++----------- contracts/burner/Cargo.lock | 22 +++++++++++----------- contracts/hackatom/Cargo.lock | 22 +++++++++++----------- contracts/queue/Cargo.lock | 22 +++++++++++----------- contracts/reflect/Cargo.lock | 22 +++++++++++----------- contracts/staking/Cargo.lock | 22 +++++++++++----------- packages/vm/Cargo.toml | 4 ++-- packages/vm/src/calls.rs | 3 ++- packages/vm/src/context.rs | 3 ++- packages/vm/src/imports.rs | 8 ++++---- packages/vm/src/instance.rs | 14 +++++++------- 11 files changed, 83 insertions(+), 81 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 2a599566f6..8708c90e10 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1357,7 +1357,7 @@ checksum = "7e7811dd7f9398f14cc76efd356f98f03aa30419dea46aa810d71e819fc97158" [[package]] name = "wasmer" version = "1.0.0-beta1" -source = "git+https://github.com/wasmerio/wasmer?rev=e1c92737#e1c92737820d9afbd2f1920ed22e958910cbad00" +source = "git+https://github.com/webmaster128/wasmer?rev=05f4882#05f48829c67f1b3ce21a245c4f352735989fab73" dependencies = [ "cfg-if 0.1.10", "indexmap", @@ -1379,7 +1379,7 @@ dependencies = [ [[package]] name = "wasmer-compiler" version = "1.0.0-beta1" -source = "git+https://github.com/wasmerio/wasmer?rev=e1c92737#e1c92737820d9afbd2f1920ed22e958910cbad00" +source = "git+https://github.com/webmaster128/wasmer?rev=05f4882#05f48829c67f1b3ce21a245c4f352735989fab73" dependencies = [ "enumset", "raw-cpuid", @@ -1396,7 +1396,7 @@ dependencies = [ [[package]] name = "wasmer-compiler-cranelift" version = "1.0.0-beta1" -source = "git+https://github.com/wasmerio/wasmer?rev=e1c92737#e1c92737820d9afbd2f1920ed22e958910cbad00" +source = "git+https://github.com/webmaster128/wasmer?rev=05f4882#05f48829c67f1b3ce21a245c4f352735989fab73" dependencies = [ "cranelift-codegen", "cranelift-frontend", @@ -1414,7 +1414,7 @@ dependencies = [ [[package]] name = "wasmer-compiler-singlepass" version = "1.0.0-beta1" -source = "git+https://github.com/wasmerio/wasmer?rev=e1c92737#e1c92737820d9afbd2f1920ed22e958910cbad00" +source = "git+https://github.com/webmaster128/wasmer?rev=05f4882#05f48829c67f1b3ce21a245c4f352735989fab73" dependencies = [ "byteorder", "dynasm", @@ -1432,7 +1432,7 @@ dependencies = [ [[package]] name = "wasmer-derive" version = "1.0.0-beta1" -source = "git+https://github.com/wasmerio/wasmer?rev=e1c92737#e1c92737820d9afbd2f1920ed22e958910cbad00" +source = "git+https://github.com/webmaster128/wasmer?rev=05f4882#05f48829c67f1b3ce21a245c4f352735989fab73" dependencies = [ "proc-macro-error", "proc-macro2", @@ -1443,7 +1443,7 @@ dependencies = [ [[package]] name = "wasmer-engine" version = "1.0.0-beta1" -source = "git+https://github.com/wasmerio/wasmer?rev=e1c92737#e1c92737820d9afbd2f1920ed22e958910cbad00" +source = "git+https://github.com/webmaster128/wasmer?rev=05f4882#05f48829c67f1b3ce21a245c4f352735989fab73" dependencies = [ "backtrace", "bincode", @@ -1462,7 +1462,7 @@ dependencies = [ [[package]] name = "wasmer-engine-jit" version = "1.0.0-beta1" -source = "git+https://github.com/wasmerio/wasmer?rev=e1c92737#e1c92737820d9afbd2f1920ed22e958910cbad00" +source = "git+https://github.com/webmaster128/wasmer?rev=05f4882#05f48829c67f1b3ce21a245c4f352735989fab73" dependencies = [ "bincode", "cfg-if 0.1.10", @@ -1479,7 +1479,7 @@ dependencies = [ [[package]] name = "wasmer-engine-native" version = "1.0.0-beta1" -source = "git+https://github.com/wasmerio/wasmer?rev=e1c92737#e1c92737820d9afbd2f1920ed22e958910cbad00" +source = "git+https://github.com/webmaster128/wasmer?rev=05f4882#05f48829c67f1b3ce21a245c4f352735989fab73" dependencies = [ "bincode", "cfg-if 0.1.10", @@ -1499,7 +1499,7 @@ dependencies = [ [[package]] name = "wasmer-object" version = "1.0.0-beta1" -source = "git+https://github.com/wasmerio/wasmer?rev=e1c92737#e1c92737820d9afbd2f1920ed22e958910cbad00" +source = "git+https://github.com/webmaster128/wasmer?rev=05f4882#05f48829c67f1b3ce21a245c4f352735989fab73" dependencies = [ "object 0.22.0", "thiserror", @@ -1510,7 +1510,7 @@ dependencies = [ [[package]] name = "wasmer-types" version = "1.0.0-beta1" -source = "git+https://github.com/wasmerio/wasmer?rev=e1c92737#e1c92737820d9afbd2f1920ed22e958910cbad00" +source = "git+https://github.com/webmaster128/wasmer?rev=05f4882#05f48829c67f1b3ce21a245c4f352735989fab73" dependencies = [ "cranelift-entity", "serde", @@ -1519,7 +1519,7 @@ dependencies = [ [[package]] name = "wasmer-vm" version = "1.0.0-beta1" -source = "git+https://github.com/wasmerio/wasmer?rev=e1c92737#e1c92737820d9afbd2f1920ed22e958910cbad00" +source = "git+https://github.com/webmaster128/wasmer?rev=05f4882#05f48829c67f1b3ce21a245c4f352735989fab73" dependencies = [ "backtrace", "cc", diff --git a/contracts/burner/Cargo.lock b/contracts/burner/Cargo.lock index 30f31a5f2d..2d8fcc589f 100644 --- a/contracts/burner/Cargo.lock +++ b/contracts/burner/Cargo.lock @@ -1032,7 +1032,7 @@ checksum = "cccddf32554fecc6acb585f82a32a72e28b48f8c4c1883ddfeeeaa96f7d8e519" [[package]] name = "wasmer" version = "1.0.0-beta1" -source = "git+https://github.com/wasmerio/wasmer?rev=e1c92737#e1c92737820d9afbd2f1920ed22e958910cbad00" +source = "git+https://github.com/webmaster128/wasmer?rev=05f4882#05f48829c67f1b3ce21a245c4f352735989fab73" dependencies = [ "cfg-if 0.1.10", "indexmap", @@ -1054,7 +1054,7 @@ dependencies = [ [[package]] name = "wasmer-compiler" version = "1.0.0-beta1" -source = "git+https://github.com/wasmerio/wasmer?rev=e1c92737#e1c92737820d9afbd2f1920ed22e958910cbad00" +source = "git+https://github.com/webmaster128/wasmer?rev=05f4882#05f48829c67f1b3ce21a245c4f352735989fab73" dependencies = [ "enumset", "raw-cpuid", @@ -1071,7 +1071,7 @@ dependencies = [ [[package]] name = "wasmer-compiler-cranelift" version = "1.0.0-beta1" -source = "git+https://github.com/wasmerio/wasmer?rev=e1c92737#e1c92737820d9afbd2f1920ed22e958910cbad00" +source = "git+https://github.com/webmaster128/wasmer?rev=05f4882#05f48829c67f1b3ce21a245c4f352735989fab73" dependencies = [ "cranelift-codegen", "cranelift-frontend", @@ -1089,7 +1089,7 @@ dependencies = [ [[package]] name = "wasmer-compiler-singlepass" version = "1.0.0-beta1" -source = "git+https://github.com/wasmerio/wasmer?rev=e1c92737#e1c92737820d9afbd2f1920ed22e958910cbad00" +source = "git+https://github.com/webmaster128/wasmer?rev=05f4882#05f48829c67f1b3ce21a245c4f352735989fab73" dependencies = [ "byteorder", "dynasm", @@ -1107,7 +1107,7 @@ dependencies = [ [[package]] name = "wasmer-derive" version = "1.0.0-beta1" -source = "git+https://github.com/wasmerio/wasmer?rev=e1c92737#e1c92737820d9afbd2f1920ed22e958910cbad00" +source = "git+https://github.com/webmaster128/wasmer?rev=05f4882#05f48829c67f1b3ce21a245c4f352735989fab73" dependencies = [ "proc-macro-error", "proc-macro2", @@ -1118,7 +1118,7 @@ dependencies = [ [[package]] name = "wasmer-engine" version = "1.0.0-beta1" -source = "git+https://github.com/wasmerio/wasmer?rev=e1c92737#e1c92737820d9afbd2f1920ed22e958910cbad00" +source = "git+https://github.com/webmaster128/wasmer?rev=05f4882#05f48829c67f1b3ce21a245c4f352735989fab73" dependencies = [ "backtrace", "bincode", @@ -1137,7 +1137,7 @@ dependencies = [ [[package]] name = "wasmer-engine-jit" version = "1.0.0-beta1" -source = "git+https://github.com/wasmerio/wasmer?rev=e1c92737#e1c92737820d9afbd2f1920ed22e958910cbad00" +source = "git+https://github.com/webmaster128/wasmer?rev=05f4882#05f48829c67f1b3ce21a245c4f352735989fab73" dependencies = [ "bincode", "cfg-if 0.1.10", @@ -1154,7 +1154,7 @@ dependencies = [ [[package]] name = "wasmer-engine-native" version = "1.0.0-beta1" -source = "git+https://github.com/wasmerio/wasmer?rev=e1c92737#e1c92737820d9afbd2f1920ed22e958910cbad00" +source = "git+https://github.com/webmaster128/wasmer?rev=05f4882#05f48829c67f1b3ce21a245c4f352735989fab73" dependencies = [ "bincode", "cfg-if 0.1.10", @@ -1174,7 +1174,7 @@ dependencies = [ [[package]] name = "wasmer-object" version = "1.0.0-beta1" -source = "git+https://github.com/wasmerio/wasmer?rev=e1c92737#e1c92737820d9afbd2f1920ed22e958910cbad00" +source = "git+https://github.com/webmaster128/wasmer?rev=05f4882#05f48829c67f1b3ce21a245c4f352735989fab73" dependencies = [ "object", "thiserror", @@ -1185,7 +1185,7 @@ dependencies = [ [[package]] name = "wasmer-types" version = "1.0.0-beta1" -source = "git+https://github.com/wasmerio/wasmer?rev=e1c92737#e1c92737820d9afbd2f1920ed22e958910cbad00" +source = "git+https://github.com/webmaster128/wasmer?rev=05f4882#05f48829c67f1b3ce21a245c4f352735989fab73" dependencies = [ "cranelift-entity", "serde", @@ -1194,7 +1194,7 @@ dependencies = [ [[package]] name = "wasmer-vm" version = "1.0.0-beta1" -source = "git+https://github.com/wasmerio/wasmer?rev=e1c92737#e1c92737820d9afbd2f1920ed22e958910cbad00" +source = "git+https://github.com/webmaster128/wasmer?rev=05f4882#05f48829c67f1b3ce21a245c4f352735989fab73" dependencies = [ "backtrace", "cc", diff --git a/contracts/hackatom/Cargo.lock b/contracts/hackatom/Cargo.lock index 64baf20efa..a9683e1c15 100644 --- a/contracts/hackatom/Cargo.lock +++ b/contracts/hackatom/Cargo.lock @@ -1043,7 +1043,7 @@ checksum = "cccddf32554fecc6acb585f82a32a72e28b48f8c4c1883ddfeeeaa96f7d8e519" [[package]] name = "wasmer" version = "1.0.0-beta1" -source = "git+https://github.com/wasmerio/wasmer?rev=e1c92737#e1c92737820d9afbd2f1920ed22e958910cbad00" +source = "git+https://github.com/webmaster128/wasmer?rev=05f4882#05f48829c67f1b3ce21a245c4f352735989fab73" dependencies = [ "cfg-if 0.1.10", "indexmap", @@ -1065,7 +1065,7 @@ dependencies = [ [[package]] name = "wasmer-compiler" version = "1.0.0-beta1" -source = "git+https://github.com/wasmerio/wasmer?rev=e1c92737#e1c92737820d9afbd2f1920ed22e958910cbad00" +source = "git+https://github.com/webmaster128/wasmer?rev=05f4882#05f48829c67f1b3ce21a245c4f352735989fab73" dependencies = [ "enumset", "raw-cpuid", @@ -1082,7 +1082,7 @@ dependencies = [ [[package]] name = "wasmer-compiler-cranelift" version = "1.0.0-beta1" -source = "git+https://github.com/wasmerio/wasmer?rev=e1c92737#e1c92737820d9afbd2f1920ed22e958910cbad00" +source = "git+https://github.com/webmaster128/wasmer?rev=05f4882#05f48829c67f1b3ce21a245c4f352735989fab73" dependencies = [ "cranelift-codegen", "cranelift-frontend", @@ -1100,7 +1100,7 @@ dependencies = [ [[package]] name = "wasmer-compiler-singlepass" version = "1.0.0-beta1" -source = "git+https://github.com/wasmerio/wasmer?rev=e1c92737#e1c92737820d9afbd2f1920ed22e958910cbad00" +source = "git+https://github.com/webmaster128/wasmer?rev=05f4882#05f48829c67f1b3ce21a245c4f352735989fab73" dependencies = [ "byteorder", "dynasm", @@ -1118,7 +1118,7 @@ dependencies = [ [[package]] name = "wasmer-derive" version = "1.0.0-beta1" -source = "git+https://github.com/wasmerio/wasmer?rev=e1c92737#e1c92737820d9afbd2f1920ed22e958910cbad00" +source = "git+https://github.com/webmaster128/wasmer?rev=05f4882#05f48829c67f1b3ce21a245c4f352735989fab73" dependencies = [ "proc-macro-error", "proc-macro2", @@ -1129,7 +1129,7 @@ dependencies = [ [[package]] name = "wasmer-engine" version = "1.0.0-beta1" -source = "git+https://github.com/wasmerio/wasmer?rev=e1c92737#e1c92737820d9afbd2f1920ed22e958910cbad00" +source = "git+https://github.com/webmaster128/wasmer?rev=05f4882#05f48829c67f1b3ce21a245c4f352735989fab73" dependencies = [ "backtrace", "bincode", @@ -1148,7 +1148,7 @@ dependencies = [ [[package]] name = "wasmer-engine-jit" version = "1.0.0-beta1" -source = "git+https://github.com/wasmerio/wasmer?rev=e1c92737#e1c92737820d9afbd2f1920ed22e958910cbad00" +source = "git+https://github.com/webmaster128/wasmer?rev=05f4882#05f48829c67f1b3ce21a245c4f352735989fab73" dependencies = [ "bincode", "cfg-if 0.1.10", @@ -1165,7 +1165,7 @@ dependencies = [ [[package]] name = "wasmer-engine-native" version = "1.0.0-beta1" -source = "git+https://github.com/wasmerio/wasmer?rev=e1c92737#e1c92737820d9afbd2f1920ed22e958910cbad00" +source = "git+https://github.com/webmaster128/wasmer?rev=05f4882#05f48829c67f1b3ce21a245c4f352735989fab73" dependencies = [ "bincode", "cfg-if 0.1.10", @@ -1185,7 +1185,7 @@ dependencies = [ [[package]] name = "wasmer-object" version = "1.0.0-beta1" -source = "git+https://github.com/wasmerio/wasmer?rev=e1c92737#e1c92737820d9afbd2f1920ed22e958910cbad00" +source = "git+https://github.com/webmaster128/wasmer?rev=05f4882#05f48829c67f1b3ce21a245c4f352735989fab73" dependencies = [ "object", "thiserror", @@ -1196,7 +1196,7 @@ dependencies = [ [[package]] name = "wasmer-types" version = "1.0.0-beta1" -source = "git+https://github.com/wasmerio/wasmer?rev=e1c92737#e1c92737820d9afbd2f1920ed22e958910cbad00" +source = "git+https://github.com/webmaster128/wasmer?rev=05f4882#05f48829c67f1b3ce21a245c4f352735989fab73" dependencies = [ "cranelift-entity", "serde", @@ -1205,7 +1205,7 @@ dependencies = [ [[package]] name = "wasmer-vm" version = "1.0.0-beta1" -source = "git+https://github.com/wasmerio/wasmer?rev=e1c92737#e1c92737820d9afbd2f1920ed22e958910cbad00" +source = "git+https://github.com/webmaster128/wasmer?rev=05f4882#05f48829c67f1b3ce21a245c4f352735989fab73" dependencies = [ "backtrace", "cc", diff --git a/contracts/queue/Cargo.lock b/contracts/queue/Cargo.lock index a740d7dda9..d26ddd5d13 100644 --- a/contracts/queue/Cargo.lock +++ b/contracts/queue/Cargo.lock @@ -1032,7 +1032,7 @@ checksum = "cccddf32554fecc6acb585f82a32a72e28b48f8c4c1883ddfeeeaa96f7d8e519" [[package]] name = "wasmer" version = "1.0.0-beta1" -source = "git+https://github.com/wasmerio/wasmer?rev=e1c92737#e1c92737820d9afbd2f1920ed22e958910cbad00" +source = "git+https://github.com/webmaster128/wasmer?rev=05f4882#05f48829c67f1b3ce21a245c4f352735989fab73" dependencies = [ "cfg-if 0.1.10", "indexmap", @@ -1054,7 +1054,7 @@ dependencies = [ [[package]] name = "wasmer-compiler" version = "1.0.0-beta1" -source = "git+https://github.com/wasmerio/wasmer?rev=e1c92737#e1c92737820d9afbd2f1920ed22e958910cbad00" +source = "git+https://github.com/webmaster128/wasmer?rev=05f4882#05f48829c67f1b3ce21a245c4f352735989fab73" dependencies = [ "enumset", "raw-cpuid", @@ -1071,7 +1071,7 @@ dependencies = [ [[package]] name = "wasmer-compiler-cranelift" version = "1.0.0-beta1" -source = "git+https://github.com/wasmerio/wasmer?rev=e1c92737#e1c92737820d9afbd2f1920ed22e958910cbad00" +source = "git+https://github.com/webmaster128/wasmer?rev=05f4882#05f48829c67f1b3ce21a245c4f352735989fab73" dependencies = [ "cranelift-codegen", "cranelift-frontend", @@ -1089,7 +1089,7 @@ dependencies = [ [[package]] name = "wasmer-compiler-singlepass" version = "1.0.0-beta1" -source = "git+https://github.com/wasmerio/wasmer?rev=e1c92737#e1c92737820d9afbd2f1920ed22e958910cbad00" +source = "git+https://github.com/webmaster128/wasmer?rev=05f4882#05f48829c67f1b3ce21a245c4f352735989fab73" dependencies = [ "byteorder", "dynasm", @@ -1107,7 +1107,7 @@ dependencies = [ [[package]] name = "wasmer-derive" version = "1.0.0-beta1" -source = "git+https://github.com/wasmerio/wasmer?rev=e1c92737#e1c92737820d9afbd2f1920ed22e958910cbad00" +source = "git+https://github.com/webmaster128/wasmer?rev=05f4882#05f48829c67f1b3ce21a245c4f352735989fab73" dependencies = [ "proc-macro-error", "proc-macro2", @@ -1118,7 +1118,7 @@ dependencies = [ [[package]] name = "wasmer-engine" version = "1.0.0-beta1" -source = "git+https://github.com/wasmerio/wasmer?rev=e1c92737#e1c92737820d9afbd2f1920ed22e958910cbad00" +source = "git+https://github.com/webmaster128/wasmer?rev=05f4882#05f48829c67f1b3ce21a245c4f352735989fab73" dependencies = [ "backtrace", "bincode", @@ -1137,7 +1137,7 @@ dependencies = [ [[package]] name = "wasmer-engine-jit" version = "1.0.0-beta1" -source = "git+https://github.com/wasmerio/wasmer?rev=e1c92737#e1c92737820d9afbd2f1920ed22e958910cbad00" +source = "git+https://github.com/webmaster128/wasmer?rev=05f4882#05f48829c67f1b3ce21a245c4f352735989fab73" dependencies = [ "bincode", "cfg-if 0.1.10", @@ -1154,7 +1154,7 @@ dependencies = [ [[package]] name = "wasmer-engine-native" version = "1.0.0-beta1" -source = "git+https://github.com/wasmerio/wasmer?rev=e1c92737#e1c92737820d9afbd2f1920ed22e958910cbad00" +source = "git+https://github.com/webmaster128/wasmer?rev=05f4882#05f48829c67f1b3ce21a245c4f352735989fab73" dependencies = [ "bincode", "cfg-if 0.1.10", @@ -1174,7 +1174,7 @@ dependencies = [ [[package]] name = "wasmer-object" version = "1.0.0-beta1" -source = "git+https://github.com/wasmerio/wasmer?rev=e1c92737#e1c92737820d9afbd2f1920ed22e958910cbad00" +source = "git+https://github.com/webmaster128/wasmer?rev=05f4882#05f48829c67f1b3ce21a245c4f352735989fab73" dependencies = [ "object", "thiserror", @@ -1185,7 +1185,7 @@ dependencies = [ [[package]] name = "wasmer-types" version = "1.0.0-beta1" -source = "git+https://github.com/wasmerio/wasmer?rev=e1c92737#e1c92737820d9afbd2f1920ed22e958910cbad00" +source = "git+https://github.com/webmaster128/wasmer?rev=05f4882#05f48829c67f1b3ce21a245c4f352735989fab73" dependencies = [ "cranelift-entity", "serde", @@ -1194,7 +1194,7 @@ dependencies = [ [[package]] name = "wasmer-vm" version = "1.0.0-beta1" -source = "git+https://github.com/wasmerio/wasmer?rev=e1c92737#e1c92737820d9afbd2f1920ed22e958910cbad00" +source = "git+https://github.com/webmaster128/wasmer?rev=05f4882#05f48829c67f1b3ce21a245c4f352735989fab73" dependencies = [ "backtrace", "cc", diff --git a/contracts/reflect/Cargo.lock b/contracts/reflect/Cargo.lock index db694303ea..47f277052f 100644 --- a/contracts/reflect/Cargo.lock +++ b/contracts/reflect/Cargo.lock @@ -1042,7 +1042,7 @@ checksum = "cccddf32554fecc6acb585f82a32a72e28b48f8c4c1883ddfeeeaa96f7d8e519" [[package]] name = "wasmer" version = "1.0.0-beta1" -source = "git+https://github.com/wasmerio/wasmer?rev=e1c92737#e1c92737820d9afbd2f1920ed22e958910cbad00" +source = "git+https://github.com/webmaster128/wasmer?rev=05f4882#05f48829c67f1b3ce21a245c4f352735989fab73" dependencies = [ "cfg-if 0.1.10", "indexmap", @@ -1064,7 +1064,7 @@ dependencies = [ [[package]] name = "wasmer-compiler" version = "1.0.0-beta1" -source = "git+https://github.com/wasmerio/wasmer?rev=e1c92737#e1c92737820d9afbd2f1920ed22e958910cbad00" +source = "git+https://github.com/webmaster128/wasmer?rev=05f4882#05f48829c67f1b3ce21a245c4f352735989fab73" dependencies = [ "enumset", "raw-cpuid", @@ -1081,7 +1081,7 @@ dependencies = [ [[package]] name = "wasmer-compiler-cranelift" version = "1.0.0-beta1" -source = "git+https://github.com/wasmerio/wasmer?rev=e1c92737#e1c92737820d9afbd2f1920ed22e958910cbad00" +source = "git+https://github.com/webmaster128/wasmer?rev=05f4882#05f48829c67f1b3ce21a245c4f352735989fab73" dependencies = [ "cranelift-codegen", "cranelift-frontend", @@ -1099,7 +1099,7 @@ dependencies = [ [[package]] name = "wasmer-compiler-singlepass" version = "1.0.0-beta1" -source = "git+https://github.com/wasmerio/wasmer?rev=e1c92737#e1c92737820d9afbd2f1920ed22e958910cbad00" +source = "git+https://github.com/webmaster128/wasmer?rev=05f4882#05f48829c67f1b3ce21a245c4f352735989fab73" dependencies = [ "byteorder", "dynasm", @@ -1117,7 +1117,7 @@ dependencies = [ [[package]] name = "wasmer-derive" version = "1.0.0-beta1" -source = "git+https://github.com/wasmerio/wasmer?rev=e1c92737#e1c92737820d9afbd2f1920ed22e958910cbad00" +source = "git+https://github.com/webmaster128/wasmer?rev=05f4882#05f48829c67f1b3ce21a245c4f352735989fab73" dependencies = [ "proc-macro-error", "proc-macro2", @@ -1128,7 +1128,7 @@ dependencies = [ [[package]] name = "wasmer-engine" version = "1.0.0-beta1" -source = "git+https://github.com/wasmerio/wasmer?rev=e1c92737#e1c92737820d9afbd2f1920ed22e958910cbad00" +source = "git+https://github.com/webmaster128/wasmer?rev=05f4882#05f48829c67f1b3ce21a245c4f352735989fab73" dependencies = [ "backtrace", "bincode", @@ -1147,7 +1147,7 @@ dependencies = [ [[package]] name = "wasmer-engine-jit" version = "1.0.0-beta1" -source = "git+https://github.com/wasmerio/wasmer?rev=e1c92737#e1c92737820d9afbd2f1920ed22e958910cbad00" +source = "git+https://github.com/webmaster128/wasmer?rev=05f4882#05f48829c67f1b3ce21a245c4f352735989fab73" dependencies = [ "bincode", "cfg-if 0.1.10", @@ -1164,7 +1164,7 @@ dependencies = [ [[package]] name = "wasmer-engine-native" version = "1.0.0-beta1" -source = "git+https://github.com/wasmerio/wasmer?rev=e1c92737#e1c92737820d9afbd2f1920ed22e958910cbad00" +source = "git+https://github.com/webmaster128/wasmer?rev=05f4882#05f48829c67f1b3ce21a245c4f352735989fab73" dependencies = [ "bincode", "cfg-if 0.1.10", @@ -1184,7 +1184,7 @@ dependencies = [ [[package]] name = "wasmer-object" version = "1.0.0-beta1" -source = "git+https://github.com/wasmerio/wasmer?rev=e1c92737#e1c92737820d9afbd2f1920ed22e958910cbad00" +source = "git+https://github.com/webmaster128/wasmer?rev=05f4882#05f48829c67f1b3ce21a245c4f352735989fab73" dependencies = [ "object", "thiserror", @@ -1195,7 +1195,7 @@ dependencies = [ [[package]] name = "wasmer-types" version = "1.0.0-beta1" -source = "git+https://github.com/wasmerio/wasmer?rev=e1c92737#e1c92737820d9afbd2f1920ed22e958910cbad00" +source = "git+https://github.com/webmaster128/wasmer?rev=05f4882#05f48829c67f1b3ce21a245c4f352735989fab73" dependencies = [ "cranelift-entity", "serde", @@ -1204,7 +1204,7 @@ dependencies = [ [[package]] name = "wasmer-vm" version = "1.0.0-beta1" -source = "git+https://github.com/wasmerio/wasmer?rev=e1c92737#e1c92737820d9afbd2f1920ed22e958910cbad00" +source = "git+https://github.com/webmaster128/wasmer?rev=05f4882#05f48829c67f1b3ce21a245c4f352735989fab73" dependencies = [ "backtrace", "cc", diff --git a/contracts/staking/Cargo.lock b/contracts/staking/Cargo.lock index d2dc5c6a77..b6ea87829b 100644 --- a/contracts/staking/Cargo.lock +++ b/contracts/staking/Cargo.lock @@ -1069,7 +1069,7 @@ checksum = "cccddf32554fecc6acb585f82a32a72e28b48f8c4c1883ddfeeeaa96f7d8e519" [[package]] name = "wasmer" version = "1.0.0-beta1" -source = "git+https://github.com/wasmerio/wasmer?rev=e1c92737#e1c92737820d9afbd2f1920ed22e958910cbad00" +source = "git+https://github.com/webmaster128/wasmer?rev=05f4882#05f48829c67f1b3ce21a245c4f352735989fab73" dependencies = [ "cfg-if 0.1.10", "indexmap", @@ -1091,7 +1091,7 @@ dependencies = [ [[package]] name = "wasmer-compiler" version = "1.0.0-beta1" -source = "git+https://github.com/wasmerio/wasmer?rev=e1c92737#e1c92737820d9afbd2f1920ed22e958910cbad00" +source = "git+https://github.com/webmaster128/wasmer?rev=05f4882#05f48829c67f1b3ce21a245c4f352735989fab73" dependencies = [ "enumset", "raw-cpuid", @@ -1108,7 +1108,7 @@ dependencies = [ [[package]] name = "wasmer-compiler-cranelift" version = "1.0.0-beta1" -source = "git+https://github.com/wasmerio/wasmer?rev=e1c92737#e1c92737820d9afbd2f1920ed22e958910cbad00" +source = "git+https://github.com/webmaster128/wasmer?rev=05f4882#05f48829c67f1b3ce21a245c4f352735989fab73" dependencies = [ "cranelift-codegen", "cranelift-frontend", @@ -1126,7 +1126,7 @@ dependencies = [ [[package]] name = "wasmer-compiler-singlepass" version = "1.0.0-beta1" -source = "git+https://github.com/wasmerio/wasmer?rev=e1c92737#e1c92737820d9afbd2f1920ed22e958910cbad00" +source = "git+https://github.com/webmaster128/wasmer?rev=05f4882#05f48829c67f1b3ce21a245c4f352735989fab73" dependencies = [ "byteorder", "dynasm", @@ -1144,7 +1144,7 @@ dependencies = [ [[package]] name = "wasmer-derive" version = "1.0.0-beta1" -source = "git+https://github.com/wasmerio/wasmer?rev=e1c92737#e1c92737820d9afbd2f1920ed22e958910cbad00" +source = "git+https://github.com/webmaster128/wasmer?rev=05f4882#05f48829c67f1b3ce21a245c4f352735989fab73" dependencies = [ "proc-macro-error", "proc-macro2", @@ -1155,7 +1155,7 @@ dependencies = [ [[package]] name = "wasmer-engine" version = "1.0.0-beta1" -source = "git+https://github.com/wasmerio/wasmer?rev=e1c92737#e1c92737820d9afbd2f1920ed22e958910cbad00" +source = "git+https://github.com/webmaster128/wasmer?rev=05f4882#05f48829c67f1b3ce21a245c4f352735989fab73" dependencies = [ "backtrace", "bincode", @@ -1174,7 +1174,7 @@ dependencies = [ [[package]] name = "wasmer-engine-jit" version = "1.0.0-beta1" -source = "git+https://github.com/wasmerio/wasmer?rev=e1c92737#e1c92737820d9afbd2f1920ed22e958910cbad00" +source = "git+https://github.com/webmaster128/wasmer?rev=05f4882#05f48829c67f1b3ce21a245c4f352735989fab73" dependencies = [ "bincode", "cfg-if 0.1.10", @@ -1191,7 +1191,7 @@ dependencies = [ [[package]] name = "wasmer-engine-native" version = "1.0.0-beta1" -source = "git+https://github.com/wasmerio/wasmer?rev=e1c92737#e1c92737820d9afbd2f1920ed22e958910cbad00" +source = "git+https://github.com/webmaster128/wasmer?rev=05f4882#05f48829c67f1b3ce21a245c4f352735989fab73" dependencies = [ "bincode", "cfg-if 0.1.10", @@ -1211,7 +1211,7 @@ dependencies = [ [[package]] name = "wasmer-object" version = "1.0.0-beta1" -source = "git+https://github.com/wasmerio/wasmer?rev=e1c92737#e1c92737820d9afbd2f1920ed22e958910cbad00" +source = "git+https://github.com/webmaster128/wasmer?rev=05f4882#05f48829c67f1b3ce21a245c4f352735989fab73" dependencies = [ "object", "thiserror", @@ -1222,7 +1222,7 @@ dependencies = [ [[package]] name = "wasmer-types" version = "1.0.0-beta1" -source = "git+https://github.com/wasmerio/wasmer?rev=e1c92737#e1c92737820d9afbd2f1920ed22e958910cbad00" +source = "git+https://github.com/webmaster128/wasmer?rev=05f4882#05f48829c67f1b3ce21a245c4f352735989fab73" dependencies = [ "cranelift-entity", "serde", @@ -1231,7 +1231,7 @@ dependencies = [ [[package]] name = "wasmer-vm" version = "1.0.0-beta1" -source = "git+https://github.com/wasmerio/wasmer?rev=e1c92737#e1c92737820d9afbd2f1920ed22e958910cbad00" +source = "git+https://github.com/webmaster128/wasmer?rev=05f4882#05f48829c67f1b3ce21a245c4f352735989fab73" dependencies = [ "backtrace", "cc", diff --git a/packages/vm/Cargo.toml b/packages/vm/Cargo.toml index 1800c4bae1..fdee38fb40 100644 --- a/packages/vm/Cargo.toml +++ b/packages/vm/Cargo.toml @@ -42,8 +42,8 @@ serde = { version = "1.0.103", default-features = false, features = ["derive", " serde_json = "1.0" sha2 = "0.9.1" thiserror = "1.0" -wasmer = { git = "https://github.com/wasmerio/wasmer", rev = "e1c92737", default-features = false, features = ["jit", "singlepass"] } -wasmer-engine = { git = "https://github.com/wasmerio/wasmer", rev = "e1c92737" } +wasmer = { git = "https://github.com/webmaster128/wasmer", rev = "05f4882", default-features = false, features = ["jit", "singlepass"] } +wasmer-engine = { git = "https://github.com/webmaster128/wasmer", rev = "05f4882" } # Wasmer local (used for quick local debugging or patching) # wasmer = { path = "../../../wasmer/lib/api", default-features = false, features = ["jit", "singlepass"] } diff --git a/packages/vm/src/calls.rs b/packages/vm/src/calls.rs index 3e7990fc85..9fd80a7011 100644 --- a/packages/vm/src/calls.rs +++ b/packages/vm/src/calls.rs @@ -8,6 +8,7 @@ use cosmwasm_std::{ }; use crate::backend::{Api, Querier, Storage}; +use crate::conversion::ref_to_u32; use crate::errors::{VmError, VmResult}; use crate::instance::Instance; use crate::serde::{from_slice, to_vec}; @@ -153,7 +154,7 @@ fn call_raw( arg_region_ptrs.push(region_ptr.into()); } let result = instance.call_function(name, &arg_region_ptrs)?; - let res_region_ptr = result[0].unwrap_i32() as u32; + let res_region_ptr = ref_to_u32(&result[0])?; let data = instance.read_memory(res_region_ptr, result_max_length)?; // free return value in wasm (arguments were freed in wasm code) instance.deallocate(res_region_ptr)?; diff --git a/packages/vm/src/context.rs b/packages/vm/src/context.rs index 3066a106e9..ba5aa5cb32 100644 --- a/packages/vm/src/context.rs +++ b/packages/vm/src/context.rs @@ -284,6 +284,7 @@ fn account_for_externally_used_gas_impl( mod test { use super::*; use crate::backend::Storage; + use crate::conversion::ref_to_u32; use crate::errors::VmError; use crate::size::Size; use crate::testing::{MockQuerier, MockStorage}; @@ -462,7 +463,7 @@ mod test { let ptr = env .with_func_from_context::<_, _>("allocate", |alloc_func| { let result = alloc_func.call(&[10u32.into()])?; - let ptr = result[0].unwrap_i32() as u32; + let ptr = ref_to_u32(&result[0])?; Ok(ptr) }) .unwrap(); diff --git a/packages/vm/src/imports.rs b/packages/vm/src/imports.rs index 5fd9b84ea2..d117d11b5f 100644 --- a/packages/vm/src/imports.rs +++ b/packages/vm/src/imports.rs @@ -9,7 +9,7 @@ use cosmwasm_std::{Binary, CanonicalAddr, HumanAddr}; use crate::backend::{Api, BackendError, Querier, Storage}; use crate::context::{process_gas_info, Env}; -use crate::conversion::to_u32; +use crate::conversion::{ref_to_u32, to_u32}; use crate::errors::{CommunicationError, VmError, VmResult}; #[cfg(feature = "iterator")] use crate::memory::maybe_read_region; @@ -201,7 +201,7 @@ fn write_to_contract(env: &Env, input: &[u8]) -> V let target_ptr = env.with_func_from_context::<_, u32>("allocate", |allocate| { let out_size = to_u32(input.len())?; let result = allocate.call(&[out_size.into()])?; - let ptr = result[0].unwrap_i32() as u32; + let ptr = ref_to_u32(&result[0])?; if ptr == 0 { return Err(CommunicationError::zero_address().into()); } @@ -350,7 +350,7 @@ mod test { let result = alloc_func .call(&[(data.len() as u32).into()]) .expect("error calling allocate"); - let ptr = result[0].unwrap_i32() as u32; + let ptr = ref_to_u32(&result[0])?; Ok(ptr) }) .unwrap(); @@ -366,7 +366,7 @@ mod test { let result = allocate .call(&[capacity.into()]) .expect("error calling allocate"); - let region_ptr = result[0].unwrap_i32() as u32; + let region_ptr = ref_to_u32(&result[0]).expect("error converting result"); region_ptr } diff --git a/packages/vm/src/instance.rs b/packages/vm/src/instance.rs index 66fce48f51..9bc3dfa76c 100644 --- a/packages/vm/src/instance.rs +++ b/packages/vm/src/instance.rs @@ -8,7 +8,7 @@ use wasmer::{ use crate::backend::{Api, Backend, Querier, Storage}; use crate::context::{move_into_context, move_out_of_context, Env}; -use crate::conversion::to_u32; +use crate::conversion::{ref_to_u32, to_u32}; use crate::errors::{CommunicationError, VmError, VmResult}; use crate::features::required_features_from_wasmer_instance; use crate::imports::{ @@ -123,8 +123,8 @@ where env_imports.insert( "canonicalize_address", Function::new_with_env(store, &i32i32_to_i32, env.clone(), move |env, args| { - let source_ptr = args[0].unwrap_i32() as u32; - let destination_ptr = args[1].unwrap_i32() as u32; + let source_ptr = ref_to_u32(&args[0])?; + let destination_ptr = ref_to_u32(&args[1])?; let ptr = do_canonicalize_address::(api, &env, source_ptr, destination_ptr)?; Ok(vec![ptr.into()]) @@ -138,8 +138,8 @@ where env_imports.insert( "humanize_address", Function::new_with_env(store, &i32i32_to_i32, env.clone(), move |env, args| { - let source_ptr = args[0].unwrap_i32() as u32; - let destination_ptr = args[1].unwrap_i32() as u32; + let source_ptr = ref_to_u32(&args[0])?; + let destination_ptr = ref_to_u32(&args[1])?; let ptr = do_humanize_address::(api, &env, source_ptr, destination_ptr)?; Ok(vec![ptr.into()]) }), @@ -152,7 +152,7 @@ where env_imports.insert( "debug", Function::new_with_env(store, &i32_to_void, env.clone(), move |env, args| { - let message_ptr = args[0].unwrap_i32() as u32; + let message_ptr = ref_to_u32(&args[0])?; if print_debug { print_debug_message(&env, message_ptr)?; } @@ -275,7 +275,7 @@ where /// in the Wasm address space to the created Region object. pub(crate) fn allocate(&mut self, size: usize) -> VmResult { let ret = self.call_function("allocate", &[to_u32(size)?.into()])?; - let ptr = ret.as_ref()[0].unwrap_i32() as u32; + let ptr = ref_to_u32(&ret.as_ref()[0])?; if ptr == 0 { return Err(CommunicationError::zero_address().into()); }