Skip to content

Commit ce32c51

Browse files
committed
update pwasm_utils to wasm_instrument
1 parent e8a77f5 commit ce32c51

File tree

2 files changed

+34
-14
lines changed

2 files changed

+34
-14
lines changed

packages/vm/Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,9 @@ readme = "README.md"
1111
[dependencies]
1212
assert_matches = "1.3.0"
1313
hex = "0.4"
14-
parity-wasm = "0.41"
14+
# parity-wasm = "0.45"
1515
pwasm-utils = "0.12"
16+
wasm-instrument = "0.2.0"
1617
wasmer = { version = "2.3.0", default-features = false, features = ["singlepass", "compiler", "universal"] }
1718
wasmer-middlewares = "2.3.0"
1819
# owasm-crypto = { path = "../crypto", version = "0.1.13" }

packages/vm/src/lib.rs

Lines changed: 32 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,15 @@ use cache::Cache;
66
use vm::Environment;
77

88
pub use error::Error;
9-
use parity_wasm::builder;
10-
use parity_wasm::elements::{self, External, MemoryType, Module};
119
pub use std::ptr::NonNull;
1210
use std::sync::Arc;
11+
use wasm_instrument::parity_wasm::builder;
12+
use wasm_instrument::parity_wasm::elements::{self, External, MemoryType, Module};
1313
use wasmer::Universal;
1414
use wasmer_middlewares::metering::{get_remaining_points, MeteringPoints};
1515

16-
use pwasm_utils::{self};
16+
// use pwasm_utils::{self};
17+
use wasm_instrument::{self};
1718

1819
use wasmer::Singlepass;
1920

@@ -75,7 +76,9 @@ fn inject_memory(module: Module) -> Result<Module, Error> {
7576
}
7677

7778
fn inject_stack_height(module: Module) -> Result<Module, Error> {
78-
pwasm_utils::stack_height::inject_limiter(module, MAX_STACK_HEIGHT)
79+
// pwasm_utils::stack_height::inject_limiter(module, MAX_STACK_HEIGHT)
80+
// .map_err(|_| Error::StackHeightInjectionError)
81+
wasm_instrument::inject_stack_limiter(module, MAX_STACK_HEIGHT)
7982
.map_err(|_| Error::StackHeightInjectionError)
8083
}
8184

@@ -327,10 +330,10 @@ mod test {
327330

328331
use super::*;
329332
use assert_matches::assert_matches;
330-
use parity_wasm::elements;
331333
use std::io::{Read, Write};
332334
use std::process::Command;
333335
use tempfile::NamedTempFile;
336+
use wasm_instrument::parity_wasm::elements;
334337

335338
pub struct MockEnv {}
336339

@@ -405,7 +408,7 @@ mod test {
405408
fn test_compile() {
406409
let wasm = wat2wasm(
407410
r#"(module
408-
(type (func (param i64 i64 i32 i64) (result i64)))
411+
(type (func (param i64 i64 i64 i64) (result i64)))
409412
(import "env" "ask_external_data" (func (type 0)))
410413
(func
411414
(local $idx i32)
@@ -428,7 +431,7 @@ mod test {
428431
let code = compile(&wasm).unwrap();
429432
let expected = wat2wasm(
430433
r#"(module
431-
(type (;0;) (func (param i64 i64 i32 i64) (result i64)))
434+
(type (;0;) (func (param i64 i64 i64 i64) (result i64)))
432435
(type (;1;) (func))
433436
(import "env" "ask_external_data" (func (;0;) (type 0)))
434437
(func (;1;) (type 1)
@@ -450,7 +453,7 @@ mod test {
450453
(func (;2;) (type 1))
451454
(func (;3;) (type 1)
452455
global.get 0
453-
i32.const 3
456+
i32.const 5
454457
i32.add
455458
global.set 0
456459
global.get 0
@@ -461,7 +464,7 @@ mod test {
461464
end
462465
call 1
463466
global.get 0
464-
i32.const 3
467+
i32.const 5
465468
i32.sub
466469
global.set 0)
467470
(memory (;0;) 17 512)
@@ -489,7 +492,7 @@ mod test {
489492
)
490493
)
491494
(func (;"execute": Resolves with result "beeb";)
492-
)
495+
)
493496
(memory 17)
494497
(data (i32.const 1048576) "beeb") (;str = "beeb";)
495498
(export "prepare" (func 0))
@@ -628,7 +631,7 @@ mod test {
628631
(func (;1;) (type 0))
629632
(func (;2;) (type 0)
630633
global.get 0
631-
i32.const 3
634+
i32.const 5
632635
i32.add
633636
global.set 0
634637
global.get 0
@@ -639,13 +642,29 @@ mod test {
639642
end
640643
call 0
641644
global.get 0
642-
i32.const 3
645+
i32.const 5
646+
i32.sub
647+
global.set 0)
648+
(func (;3;) (type 0)
649+
global.get 0
650+
i32.const 2
651+
i32.add
652+
global.set 0
653+
global.get 0
654+
i32.const 16384
655+
i32.gt_u
656+
if ;; label = @1
657+
unreachable
658+
end
659+
call 1
660+
global.get 0
661+
i32.const 2
643662
i32.sub
644663
global.set 0)
645664
(memory (;0;) 17)
646665
(global (;0;) (mut i32) (i32.const 0))
647666
(export "prepare" (func 2))
648-
(export "execute" (func 1))
667+
(export "execute" (func 3))
649668
(data (;0;) (i32.const 1048576) "beeb"))"#,
650669
);
651670
assert_eq!(wasm, expected);

0 commit comments

Comments
 (0)