SSVM is a high performance and enterprise-ready WebAssembly (WASM) Virtual Machine for cloud, AI, and Blockchain applications. Its use cases include the following.
- A high performance and secure runtime for Rust functions in Node.js applications. Getting started | VSCode Codespaces | Tensorflow | Privacy computing @ Mozilla Open Labs
- A hardware-optimized runtime for ONNX AI models. ONNC compiler for AI
- Smart contract runtime engine for leading blockchain platforms. Polkadot/Substrate | CyberMiles
$ git clone git@github.com:second-state/SSVM.git
$ cd SSVM
$ git checkout 0.6.7
Our docker image use ubuntu 20.04
as the base.
$ docker pull secondstate/ssvm
# Tools and libraries
$ sudo apt install -y \
software-properties-common \
cmake \
libboost-all-dev
# And you will need to install llvm for ssvm-aot tools
$ sudo apt install -y \
llvm-dev \
liblld-10-dev
# SSVM supports both clang++ and g++ compilers
# You can choose one of them for building this project
$ sudo apt install -y gcc g++
$ sudo apt install -y clang
SSVM provides various tools for enabling different runtime environments for optimal performance. After the build is finished, you can find there are several ssvm related tools:
ssvm
is for general wasm runtime. Interpreter mode.ssvm-qitc
is for AI application, supporting ONNC runtime for AI model in ONNX format.- If you want to try
ssvm-qitc
, please refer to ONNC-Wasm project to set up the working environment and run several examples. - And here is our tutorial for ONNC-Wasm project(YouTube Video).
- If you want to try
ssvm-aot
is for general wasm runtime. AOT compilation mode.ssvmc
compiles a general wasm runtime to so file.ssvmr
execute a general wasm runtime or so file in WASI environment.- To disable building the ahead of time compilation runtime, you can set the CMake option
SSVM_DISABLE_AOT_RUNTIME
toOFF
.
# After pulling our ssvm docker image
$ docker run -it --rm \
-v <path/to/your/ssvm/source/folder>:/root/ssvm \
secondstate/ssvm:latest
(docker)$ cd /root/ssvm
(docker)$ mkdir -p build && cd build
(docker)$ cmake -DCMAKE_BUILD_TYPE=Release -DBUILD_TESTS=ON .. && make -j
SSVM requires libLLVM-10
and GLIBCXX_3.4.26
or after.
If users want to build and run ssvm
interpreter tool without these dependencies, they can set the CMake option SSVM_DISABLE_AOT_RUNTIME
and STATIC_BUILD
to ON
.
$ cmake -DCMAKE_BUILD_TYPE=Release -DSSVM_DISABLE_AOT_RUNTIME=ON -DSTATIC_BUILD=ON ..
The following built-in tests are only available when the build flag BUILD_TESTS
sets to ON
.
Users can use these tests to verify the correctness of SSVM binaries.
$ cd <path/to/ssvm/build_folder>
$ ctest
To run SSVM with general wasm runtime, users will need to provide the following parameters:
- (Optional) Reactor mode: use
--reactor
to enable reactor mode.- SSVM will execute the function which name should be given in ARG[0].
- If there's exported function which names
_initialize
, the function will be executed with the empty parameter at first.
- (Optional) Binding directories into WASI virtual filesystem.
- Each directory can be specified as
--dir host_path:guest_path
.
- Each directory can be specified as
- (Optional) Environ variables.
- Each variable can be specified as
--env NAME=VALUE
.
- Each variable can be specified as
- Wasm file(
/path/to/wasm/file
). - (Optional) Arguments.
- In reactor mode, the first argument will be the function name, and the arguments after ARG[0] will be parameters of wasm function ARG[0].
- In command mode, the arguments will be parameters of function
_start
.
# cd <path/to/ssvm/build_folder>
$ cd tools/ssvm
# ./ssvm [--reactor] [--dir PREOPEN_DIRS ...] [--env ENVS ...] [--] WASM_FILE [ARG ...]
$ ./ssvm --reactor examples/fibonacci.wasm fib 10
89
When wrong number of parameter given, the following error message is printed.
$ ./ssvm --reactor examples/fibonacci.wasm fib 10 10
2020-08-21 06:30:37,304 ERROR [default] execution failed: function signature mismatch, Code: 0x83
2020-08-21 06:30:37,304 ERROR [default] Mismatched function type. Expected: params{i32} returns{i32} , Got: params{i32 , i32} returns{i32}
2020-08-21 06:30:37,304 ERROR [default] When executing function name: "fib"
When calling unknown exported function, the following error message is printed.
$ ./ssvm --reactor examples/fibonacci.wasm fib2 10
2020-08-21 06:30:56,981 ERROR [default] ssvm runtime failed: wasm function not found, Code: 0x04
2020-08-21 06:30:56,981 ERROR [default] When executing function name: "fib2"
# ./ssvm [--reactor] [--dir PREOPEN_DIRS ...] [--env ENVS ...] [--] WASM_FILE [ARG ...]
$ ./ssvm --reactor examples/factorial.wasm fac 5
120
SSVM-EVMC provides support for Ewasm runtime which is compatible with EVMC.
This project provides a shared library that can initialize and execute by the EVMC interface.
SSVM-napi provides support for accessing SSVM as a Node.js addon.
It allows Node.js applications to call WebAssembly functions written in Rust or other high-performance languages.
Why do you want to run WebAssembly on the server-side?
The SSVM addon could interact with the wasm files generated by the ssvmup compiler tool.
The Second State DevChain features a powerful and easy-to-use virtual machine that can quickly get you started with the smart contract and DApp development.
SSVM-evmc is integrated into our DevChain. Click here to learn how to run an ewasm smart contract on a real blockchain.
Design document shows how to register customized host functions into SSVM and execute with wasm files.