Skip to content

Commit

Permalink
runtime: test that signext and saturating ops are disabled (#8921)
Browse files Browse the repository at this point in the history
These are not currently supported and any decision to enable them should
be a intentional decision, not an accidental one.

Overall these changes are no-op since the deserialization will fail
earlier when trying to deserialize with pwasm deserializer, but if and
when we eventually get rid of it, it would be nice if these extensions
didn't accidentally get enabled.

This puts to rest the question raised in #8886 (comment).
  • Loading branch information
nagisa authored and nikurt committed Apr 25, 2023
1 parent a12a5d0 commit 171d00e
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 9 deletions.
6 changes: 4 additions & 2 deletions runtime/near-vm-runner/src/near_vm_runner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,10 @@ const VM_FEATURES: Features = Features {
memory64: WASM_FEATURES.memory64,
exceptions: WASM_FEATURES.exceptions,
mutable_global: true,
saturating_float_to_int: true,
sign_extension: true,
// These are blocked at prepare by pwasm parser, but once that is gone these are going to be
// the only check we have.
saturating_float_to_int: false,
sign_extension: false,
};

#[derive(Clone)]
Expand Down
14 changes: 14 additions & 0 deletions runtime/near-vm-runner/src/prepare.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,20 @@ pub(crate) const WASM_FEATURES: wasmparser::WasmFeatures = wasmparser::WasmFeatu
multi_memory: false,
exceptions: false,
memory64: false,
//
// /!\ /!\ /!\ /!\ /!\ /!\ /!\ /!\ /!\ /!\ /!\ /!\ /!\ /!\ /!\ /!\ /!\ /!\ /!\ /!\ /!\ /!\
//
// FIXME: there are features that this version of wasmparser enables by default, but pwasm
// currently does not and the compilers' support for these features is therefore largely
// untested if it exists at all. Non exhaustive list of examples:
//
// * saturating_float_to_int
// * sign_extension
//
// This should be accounted for when pwasm code is removed!
//
// /!\ /!\ /!\ /!\ /!\ /!\ /!\ /!\ /!\ /!\ /!\ /!\ /!\ /!\ /!\ /!\ /!\ /!\ /!\ /!\ /!\ /!\
//
};

/// Loads the given module given in `original_code`, performs some checks on it and
Expand Down
14 changes: 7 additions & 7 deletions runtime/near-vm-runner/src/tests/cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -197,13 +197,13 @@ fn test_near_vm_artifact_output_stability() {
];
let mut got_prepared_hashes = Vec::with_capacity(seeds.len());
let compiled_hashes = [
244044469030513689,
5237896941728381456,
8878249955373865409,
14070580588423897597,
16220196077572326609,
11663797245987968376,
17572197684302294358,
10351663297260604629,
13937571770370186345,
9438649787181538636,
17513376043726020657,
8030854424152836681,
8449792361847063954,
2655860096455618118,
];
let mut got_compiled_hashes = Vec::with_capacity(seeds.len());
for seed in seeds {
Expand Down
43 changes: 43 additions & 0 deletions runtime/near-vm-runner/src/tests/compile_errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -390,3 +390,46 @@ fn test_sandbox_only_function() {
Err: ...
"#]]);
}

#[test]
fn extension_saturating_float_to_int() {
let tb = test_builder().wat(
r#"
(module
(func $test_trunc (param $x f64) (result i32) (i32.trunc_sat_f64_s (local.get $x)))
)
"#,
);

#[cfg(feature = "nightly")]
tb.expect(expect![[r#"
VMOutcome: balance 4 storage_usage 12 return data None burnt gas 48450963 used gas 48450963
Err: PrepareError: Error happened while deserializing the module.
"#]]);
#[cfg(not(feature = "nightly"))]
tb.expect(expect![[r#"
VMOutcome: balance 4 storage_usage 12 return data None burnt gas 0 used gas 0
Err: PrepareError: Error happened while deserializing the module.
"#]]);
}

#[test]
fn extension_signext() {
let tb = test_builder().wat(
r#"
(module
(func $extend8_s (param $x i32) (result i32) (i32.extend8_s (local.get $x)))
)
"#,
);
#[cfg(feature = "nightly")]
tb.expect(expect![[r#"
VMOutcome: balance 4 storage_usage 12 return data None burnt gas 48017463 used gas 48017463
Err: PrepareError: Error happened while deserializing the module.
"#]]);
#[cfg(not(feature = "nightly"))]
tb.expect(expect![[r#"
VMOutcome: balance 4 storage_usage 12 return data None burnt gas 0 used gas 0
Err: PrepareError: Error happened while deserializing the module.
"#]]);
}

0 comments on commit 171d00e

Please sign in to comment.