Skip to content

Commit

Permalink
When deterministic feature will be enabled (turned-off by default) …
Browse files Browse the repository at this point in the history
…it'll guarantee deterministic

execution of wasm programs across different hardware/circumstances.
This is very useful for Blockchain projects having wasm smart-contracts

This is critical for Blockchain projects that require execution to be deterministic
in order to reach a consensus of the state transition of each smart-contract transaction.
  • Loading branch information
YaronWittenstein committed Oct 7, 2019
1 parent c8e9530 commit 6ca5812
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 6 deletions.
4 changes: 3 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ wabt = "0.9.1"
wasmer-clif-backend = { path = "lib/clif-backend" }
wasmer-singlepass-backend = { path = "lib/singlepass-backend", optional = true }
wasmer-middleware-common = { path = "lib/middleware-common" }
wasmer-runtime = { path = "lib/runtime" }
wasmer-runtime = { path = "lib/runtime", default-features = false }
wasmer-runtime-core = { path = "lib/runtime-core" }
wasmer-emscripten = { path = "lib/emscripten" }
wasmer-llvm-backend = { path = "lib/llvm-backend", optional = true }
Expand Down Expand Up @@ -101,6 +101,8 @@ backend-singlepass = [
wasi = ["wasmer-wasi"]
managed = ["backend-singlepass", "wasmer-runtime-core/managed"]

deterministic = ["wasmer-runtime/deterministic"]

[[example]]
name = "plugin"
crate-type = ["bin"]
Expand Down
1 change: 1 addition & 0 deletions lib/runtime-core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -58,3 +58,4 @@ trace = ["debug"]
"backend-singlepass" = []
"backend-llvm" = []
managed = []
deterministic = ["wasmparser/deterministic"]
3 changes: 3 additions & 0 deletions lib/runtime-core/src/codegen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,9 @@ pub fn validating_parser_config(features: &Features) -> wasmparser::ValidatingPa
enable_simd: features.simd,
enable_bulk_memory: false,
enable_multi_value: false,

#[cfg(feature = "deterministic")]
deterministic_only: true,
},
}
}
Expand Down
3 changes: 3 additions & 0 deletions lib/runtime-core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,9 @@ pub fn validate_and_report_errors_with_features(
enable_multi_value: false,
enable_reference_types: false,
enable_threads: features.threads,

#[cfg(feature = "deterministic")]
deterministic_only: true,
},
};
let mut parser = wasmparser::ValidatingParser::new(wasm, Some(config));
Expand Down
1 change: 1 addition & 0 deletions lib/runtime/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ singlepass = ["wasmer-singlepass-backend"]
default-backend-singlepass = ["singlepass"]
default-backend-llvm = ["llvm"]
default-backend-cranelift = ["cranelift"]
deterministic = ["wasmer-singlepass-backend/deterministic"]

[[bench]]
name = "nginx"
Expand Down
12 changes: 7 additions & 5 deletions lib/runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@
//! let value = add_one.call(42)?;
//!
//! assert_eq!(value, 43);
//!
//!
//! Ok(())
//! }
//! ```
Expand Down Expand Up @@ -199,13 +199,15 @@ pub fn default_compiler() -> impl Compiler {
feature = "default-backend-llvm",
any(
feature = "default-backend-cranelift",
feature = "default-backend-singlepass"
feature = "default-backend-singlepass",
feature = "deterministic"
)
),
all(
feature = "default-backend-cranelift",
feature = "default-backend-singlepass"
)
any(feature = "default-backend-singlepass", feature = "deterministic")
),
all(feature = "default-backend-singlepass", feature = "deterministic")
))]
compile_error!(
"The `default-backend-X` features are mutually exclusive. Please choose just one"
Expand All @@ -214,7 +216,7 @@ pub fn default_compiler() -> impl Compiler {
#[cfg(feature = "default-backend-llvm")]
use wasmer_llvm_backend::LLVMCompiler as DefaultCompiler;

#[cfg(feature = "default-backend-singlepass")]
#[cfg(any(feature = "default-backend-singlepass", feature = "deterministic"))]
use wasmer_singlepass_backend::SinglePassCompiler as DefaultCompiler;

#[cfg(feature = "default-backend-cranelift")]
Expand Down
4 changes: 4 additions & 0 deletions lib/singlepass-backend/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,7 @@ byteorder = "1.3"
nix = "0.15"
libc = "0.2.60"
smallvec = "0.6"

[features]
default = []
deterministic = ["wasmparser/deterministic", "wasmer-runtime-core/deterministic"]

0 comments on commit 6ca5812

Please sign in to comment.