Skip to content

Commit

Permalink
Added running WASM within the zkvm example (risc0#539)
Browse files Browse the repository at this point in the history
* Added a example that runs the supplied WASM bytecode within the zkvm and
commits the results. Using a simple fib() WAT module as an example
function
  • Loading branch information
mothran authored Apr 27, 2023
1 parent 8a6eb8e commit 4341c84
Show file tree
Hide file tree
Showing 12 changed files with 794 additions and 2 deletions.
105 changes: 103 additions & 2 deletions examples/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions examples/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ members = [
"sha",
"waldo",
"waldo/core",
"wasm",
"wordle",
"wordle/core",
]
Expand Down
15 changes: 15 additions & 0 deletions examples/wasm/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
[package]
name = "wasm"
version = "0.1.0"
edition = "2021"

[dependencies]
risc0-zkvm = { path = "../../risc0/zkvm" }
serde = "1.0"
wasm-methods = { path = "methods" }
wat = "1.0"

[features]
cuda = ["risc0-zkvm/cuda"]
default = []
metal = ["risc0-zkvm/metal"]
9 changes: 9 additions & 0 deletions examples/wasm/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# WASM

Example of running WASM code within the ZKVM using the [wasmi](https://crates.io/crates/wasmi) crate. In this example we define a fibonacci function in WAT format, compile it to WASM bytecode then run it within the ZKVM guest code. Returning the result of the fib() function back to the host. This sample can be extended to run arbitrary WAT/WASM modules or run a specific WASM bytecode if you compile the WASM code into the guest image.

## Running

```bash
cargo run --release
```
10 changes: 10 additions & 0 deletions examples/wasm/methods/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
[package]
name = "wasm-methods"
version = "0.1.0"
edition = "2021"

[build-dependencies]
risc0-build = { path = "../../../risc0/build" }

[package.metadata.risc0]
methods = ["guest"]
17 changes: 17 additions & 0 deletions examples/wasm/methods/build.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// Copyright 2023 RISC Zero, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

fn main() {
risc0_build::embed_methods();
}
Loading

0 comments on commit 4341c84

Please sign in to comment.