Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Initial vendor of risc0's rust adapter for RISC-V #454

Merged
merged 5 commits into from
Oct 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/target/
**/target/

# Remove Cargo.lock from gitignore if creating an executable, leave it for libraries
# More information here https://doc.rust-lang.org/cargo/guide/cargo-toml-vs-cargo-lock.html
Expand Down
154 changes: 150 additions & 4 deletions Cargo.lock

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

7 changes: 7 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,17 @@ members = [
"sdk",
"vm",
"vm/bin",
"riscv/zkvm/lib",
"riscv/zkvm/platform",
]
resolver = "2"

[workspace.package]
version = "0.1.0"
authors = ["Intrinsic Technologies"]
edition = "2021"
homepage = "https://axiom.xyz"
repository = "https://github.com/axiom-crypto/"

# Fastest runtime configuration
[profile.release]
Expand Down Expand Up @@ -61,6 +65,9 @@ incremental = true
lto = "thin"

[workspace.dependencies]
axvm-platform = { path = "riscv/zkvm/platform" }
axvm = { path = "riscv/zkvm/lib" }

p3-air = { git = "https://github.com/Plonky3/Plonky3.git", rev = "95e56fa" }
p3-field = { git = "https://github.com/Plonky3/Plonky3.git", rev = "95e56fa" }
p3-commit = { git = "https://github.com/Plonky3/Plonky3.git", rev = "95e56fa" }
Expand Down
3 changes: 3 additions & 0 deletions riscv/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Contains crates for compiling Rust to RISC-V ELF which targets the Modular VM architecture.

Currently vendored from RISC0.
37 changes: 37 additions & 0 deletions riscv/examples/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
To see list of all available built-in targets:

```bash
rustc --print target-list
```

We will currently use the risc0 target until we fork Rust to provide our own RISC-V target.

WARNING: to prevent from building for your host machine, make sure you do not have `rustflags = ["-Ctarget-cpu=native"]` in your `~/.cargo/config.toml`.

Build example with full command:

```bash
cd fibonacci/program
cargo +nightly build -Z build-std=alloc,core,proc_macro,panic_abort --target riscv32im-risc0-zkvm-elf
```

Also works with just `cargo +nightly build` because we have a `.cargo/config.toml` that specifies the target and unstable build features.

After this the ELF will be found via

```bash
file target/riscv32im-risc0-zkvm-elf/debug/axvm-fibonacci-program
target/riscv32im-risc0-zkvm-elf/debug/axvm-fibonacci-program: ELF 32-bit LSB executable, UCB RISC-V, soft-float ABI, version 1 (SYSV), statically linked, with debug_info, not stripped
```

To disassemble the ELF to read the instructions, [install cargo-binutils](https://github.com/rust-embedded/cargo-binutils) and run

```bash
rust-objdump -d target/riscv32im-risc0-zkvm-elf/debug/axvm-fibonacci-program
```

where `-d` is short for `--disassemble`.

A version of the ELF compiled with `--release` is provided in `fibonacci/program/elf` for reference.

Additional reference for learning: https://github.com/axiom-crypto/riscv-playground
5 changes: 5 additions & 0 deletions riscv/examples/fibonacci/program/.cargo/config.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[build]
target = "riscv32im-risc0-zkvm-elf"

[unstable]
build-std = ["core", "alloc", "proc_macro", "panic_abort"]
8 changes: 8 additions & 0 deletions riscv/examples/fibonacci/program/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[workspace]
[package]
version = "0.1.0"
name = "axvm-fibonacci-program"
edition = "2021"

[dependencies]
axvm = { path = "../../../zkvm/lib" }
Binary file not shown.
15 changes: 15 additions & 0 deletions riscv/examples/fibonacci/program/src/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#![no_main]
#![no_std]

axvm::entry!(main);

pub fn main() {
let n = 16;
let mut a: u32 = 0;
let mut b: u32 = 1;
for _ in 1..n {
let sum = a + b;
a = b;
b = sum;
}
}
Loading
Loading