https://github.com/nervosnetwork/wasm-secp256k1-test
A demo showcasing running WASM programs on CKB VM
https://github.com/nervosnetwork/wasm-secp256k1-test
Last synced: 4 months ago
JSON representation
A demo showcasing running WASM programs on CKB VM
- Host: GitHub
- URL: https://github.com/nervosnetwork/wasm-secp256k1-test
- Owner: nervosnetwork
- Created: 2019-10-08T10:54:52.000Z (almost 7 years ago)
- Default Branch: master
- Last Pushed: 2023-07-22T18:11:48.000Z (about 3 years ago)
- Last Synced: 2025-08-03T17:54:33.941Z (about 1 year ago)
- Language: Rust
- Homepage:
- Size: 12.7 KB
- Stars: 4
- Watchers: 6
- Forks: 1
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# wasm-secp256k1-test
This is test showing that we can compile WASM code to RISC-V directly, and run the resulting binary directly on CKB VM.
# How to use this:
```bash
$ git clone --recursive https://github.com/WebAssembly/wabt
$ cd wabt
$ export WABT_PATH=`pwd`
$ mkdir build
$ cd build
$ cmake ..
$ cmake --build .
$ cd ../..
$ git clone https://github.com/nervosnetwork/wasm-secp256k1-test
$ cd wasm-secp256k1-test
$ cargo build --release --target=wasm32-unknown-unknown
$ $WABT_PATH/bin/wasm2c target/wasm32-unknown-unknown/release/wasm-secp256k1-test.wasm -o secp.c
$ cd ..
$ sudo docker run --rm -it -v `pwd`:/code nervos/ckb-riscv-gnu-toolchain:xenial bash
(docker) $ cd /code/wasm-secp256k1-test
(docker) $ riscv64-unknown-elf-gcc -o secp_riscv64 -O3 -g main.c secp.c /code/wabt/wasm2c/wasm-rt-impl.c -I /code/wabt/wasm2c
(docker) $ exit
```
Now you will have a secp_riscv64 binary to play with in CKB VM. One way to run it, is to take advantage of CKB VM binaries used in CKB VM test suite:
```bash
$ git clone https://github.com/nervosnetwork/ckb-vm-test-suite
$ git submodule update --init --recursive
$ cd ckb-vm-test-suite
$ git clone https://github.com/nervosnetwork/ckb-vm
$ cd binary
$ cargo build --release
$ ./target/release/asm64 ../../wasm-secp256k1-test/secp_riscv64 1
```