SSVM is a high performance, hardware optimal Wasm Virtual Machine for AI and Blockchain applications.
$ git clone [email protected]:second-state/SSVM.git
$ cd SSVM
$ git checkout 0.2.0
Our docker image use ubuntu 18.04
as base.
$ docker pull hydai/ssvm-dev:0.2.0
$ sudo apt install -y \
cmake \
g++ \
libboost-all-dev
SSVM provides various tools to enabling different runtime environment for optimal performance. After the build is finished, you can find there are two ssvm binaries:
ssvm
is for general wasm runtime.ssvm-evm
is for Ewasm runtime.ssvm-qitc
is for AI application, supporting ONNC runtime for AI model in ONNX format.
# After pulling our ssvm-dev docker image
$ docker run -it --rm \
-v <path/to/your/ssvm/source/folder>:/root/ssvm \
hydai/ssvm-dev:0.2.0
(docker)$ cd /root/ssvm
(docker)$ mkdir -p build && cd build
(docker)$ cmake -DCMAKE_BUILD_TYPE=Release -DBUILD_TESTS=ON .. && make
The following built-in tests are only avaliable 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>
$ cd test/regression
$ ./ssvmRegressionTests
$ cd ../loader
$ ./ssvmLoaderEthereumTests
$ ./ssvmLoaderFileMgrTests
$ ./ssvmLoaderWagonTests
$ cd ../ast/load
$ ./ssvmASTLoadTests
$ cd ../../evm
$ ./ssvmEVMTests
To run SSVM with Ewasm bytecode, you will need to provide a valid Ewasm bytecode and the calldata. Currently, SSVM doesn’t support ABI encoding for Ethereum, so users need to compose the calldata by theirselves.
SSVM-EVM will take 3 parameters:
- Ewasm bytecode file (
/path/to/your/ewasm/file
) - Call data in hex string format (
4e6ec2..000054
) - Gas limit (
100000
)
In this example, we create an ERC20 token contract and compile it into Ewasm bytecode by SecondState SOLL compiler.
You can find this Ewasm file(ethereum/erc20.wasm
) in the same folder of ssvm-evm.
# cd <path/to/ssvm/build_folder>
$ cd tools/ssvm-evm
# Usage: ./ssvm-evm wasm_file.wasm call_data_in_string_format gas_limit
$ ./ssvm-evm ethereum/erc20.wasm 4e6ec24700000000000000000000000012345678901234567890123456789012345678900000000000000000000000000000000000000000000000000000000000000064 100000
# Expect output:
Info: Start running...
Info: Worker execution succeeded.
================= Statistics =================
Total execution time: 243 us
Wasm instructions execution time: 190 us
Host functions execution time: 53 us
Executed wasm instructions count: 1041
Gas costs: 71308
Instructions per second: 5478947
--- result storage:
0000000000000000000000000000000000000000000000000000000000000000 0000000000000000000000000000000000000000000000000000000000000064
f5b24dcea0e9381721a8c72784d30cfe64c11b4591226269f839d095b3e9cf10 0000000000000000000000000000000000000000000000000000000000000064
--- return data:
# cd <path/to/ssvm/build_folder>
$ cd tools/ssvm-evm
# Usage: ./ssvm-evm wasm_file.wasm call_data_in_string_format gas_limit
$ ./ssvm-evm ethereum/erc20.wasm 4e6ec24700000000000000000000000012345678901234567890123456789012345678900000000000000000000000000000000000000000000000000000000000000064 10000
# Expect output:
Info: Start running...
Error: Reverted.
================= Statistics =================
Total execution time: 152 us
Wasm instructions execution time: 152 us
Host functions execution time: 0 us
Executed wasm instructions count: 188
Gas costs: 9900
Instructions per second: 1236842
--- result storage:
--- return data:
To run SSVM with general wasm runtime, users will need to provide the following parameters:
- Wasm file(
/path/to/wasm/file
) - (Optional) Entry function name, default value is
main
- (Optional) Argument List, can be one or more arguments.
# cd <path/to/ssvm/build_folder>
$ cd tools/ssvm
# ./ssvm wasm_file.wasm [exported_func_name] [args...]
$ ./ssvm examples/fibonacci.wasm fib 10
Info: Start running...
Info: Worker execution succeeded.
================= Statistics =================
Total execution time: 60 us
Wasm instructions execution time: 60 us
Host functions execution time: 0 us
Executed wasm instructions count: 1766
Gas costs: 1855
Instructions per second: 29433333
Return value: 89
# ./ssvm wasm_file.wasm [exported_func_name] [args...]
$ ./ssvm examples/factorial.wasm fac 5
Info: Start running...
Info: Worker execution succeeded.
================= Statistics =================
Total execution time: 33 us
Wasm instructions execution time: 33 us
Host functions execution time: 0 us
Executed wasm instructions count: 55
Gas costs: 61
Instructions per second: 1666666
Return value: 120