-
Notifications
You must be signed in to change notification settings - Fork 13.2k
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
feat: add succinct-zkvm
os and target
#138463
Open
nhtyy
wants to merge
7
commits into
rust-lang:master
Choose a base branch
from
succinctlabs:n/succinct-target-only
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 3 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
ea4c160
feat: succinct-zkvm target
nhtyy 9007968
fix(ci): trailing comma fmt
nhtyy 7e69cf7
fix: include platform-summary
nhtyy 92244b3
fix: pr suggestions, risc32im-succinct-zkvm-elf -> riscv32im-succinct…
nhtyy c0f6dfc
fix: tidy ci
nhtyy 24e8fee
fix: ui tests
nhtyy 53916e1
fix: add platform support top level docs
nhtyy File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 42 additions & 0 deletions
42
compiler/rustc_target/src/spec/targets/riscv32im_succinct_zkvm_elf.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
use crate::spec::{ | ||
Cc, LinkerFlavor, Lld, PanicStrategy, RelocModel, Target, TargetMetadata, TargetOptions, | ||
}; | ||
|
||
pub(crate) fn target() -> Target { | ||
Target { | ||
data_layout: "e-m:e-p:32:32-i64:64-n32-S128".into(), | ||
llvm_target: "riscv32".into(), | ||
metadata: TargetMetadata { | ||
description: Some("Succinct's zero-knowledge Virtual Machine (RV32IM ISA)".into()), | ||
tier: Some(3), | ||
host_tools: Some(false), | ||
std: None, | ||
}, | ||
pointer_width: 32, | ||
arch: "riscv32".into(), | ||
|
||
options: TargetOptions { | ||
os: "succinct-zkvm".into(), | ||
vendor: "succinct".into(), | ||
linker_flavor: LinkerFlavor::Gnu(Cc::No, Lld::Yes), | ||
linker: Some("rust-lld".into()), | ||
cpu: "generic-rv32".into(), | ||
|
||
// The zkvm is singlethreaded and all operations are atomic. | ||
// The std-lib is compiled with lowered atomicsa and the default Succinct build tools | ||
// enforce this on programs. | ||
max_atomic_width: Some(64), | ||
atomic_cas: true, | ||
|
||
features: "+m".into(), | ||
llvm_abiname: "ilp32".into(), | ||
executables: true, | ||
panic_strategy: PanicStrategy::Abort, | ||
relocation_model: RelocModel::Static, | ||
emit_debug_gdb_scripts: false, | ||
eh_frame_header: false, | ||
singlethread: true, | ||
..Default::default() | ||
}, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
83 changes: 83 additions & 0 deletions
83
src/doc/rustc/src/platform-support/riscv32im-succinct-zkvm-elf.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
# `riscv32im-risc0-zkvm-elf` | ||
|
||
**Tier: 3** | ||
|
||
Succinct's ISA for the SP1 zkVM (Zero Knowledge Virtual Machine). | ||
|
||
## Target maintainers | ||
|
||
- John Guibas, `john@succinct.xyz`, https://github.com/jtguibas | ||
- Nathan Bustamante, `nathan@succinct.xyz`, https://github.com/nhtyy | ||
|
||
## Background | ||
|
||
This target is an execution environment to produce a proof of execution of | ||
a RISC-V ELF binary and any output that the developer of the binary wishes to | ||
display publicly. In order to do this, the target will execute the ELF and | ||
create a cryptographic proof of the "trace" of the programs runtime. | ||
|
||
We have a cargo extension called [cargo-prove] that allow users to generate | ||
project templates, install tools for improved user experience and build binaries. | ||
|
||
## Requirements | ||
|
||
The target only supports cross compilation and no host tools. The target | ||
supports `alloc` with a default allocator and will have support for std soon. | ||
|
||
The target's execution environment is single threaded, non-preemptive, and does | ||
not support any privileged instructions, nor unaligned accesses. At the time of | ||
writing the VM has 192 MB of memory and text/data, heap, and stack need to be | ||
with in the address range `0x400` - `0x0C000000`. The binaries themselves expect | ||
no operating system and can be thought of as running on bare-metal. The target | ||
does not use `#[target_feature(...)]` or `-C target-feature=` values. | ||
|
||
Calling `extern "C"` on the target uses the C calling convention outlined in the | ||
[RISC-V specification]. | ||
|
||
## Building for the zkVM | ||
|
||
Programs for the zkVM could be built by adding it to the `target` list in | ||
`config.toml`. However, we recommend building programs in our starter template | ||
generated by the [cargo-prove] utility and the [sp1-build] crate. This | ||
crate calls `rustc` with `-C "link-arg=-Ttext=` so that it maps the text in the | ||
appropriate location as well as generating variables that represent the ELF and | ||
a unique ID associated with the ELF. | ||
|
||
The starter template provides developers with system calls that are useful | ||
to zero knowledge computing such as writing to | ||
the public output, hashing using sha256, and multiply big integers. | ||
|
||
## Building Rust programs | ||
|
||
Rust does not yet ship pre-compiled artifacts for this target. To compile for | ||
this target, you will either need to build Rust with the target enabled (see | ||
"Building the target" above). We do not recommend using `build-std` as we have | ||
run into issues building core in the past on our starter template. An alternate | ||
solution is to download the risc0 tool chain by running `cargo prove install-toolchain`. | ||
|
||
## Testing | ||
|
||
Note: the target is implemented as a software emulator called the zkVM and there | ||
is no hardware implementation of the target. | ||
|
||
The most practical way to test the target program is to use our starter template | ||
that can be generated by using the `cargo prove new` command. The template | ||
generates a sample "host" and "guest" code. The guest code compiled to the | ||
target (which is RV32IM) whereas the "host" code is compiled to run on the | ||
programmer's machine running either a Linux distribution or macOS. | ||
|
||
The host program is responsible for running the guest binary on the zkVM and retrieving | ||
its public output. | ||
|
||
The target currently does not support running the Rust test suite. | ||
|
||
## Cross-compilation toolchains and C code | ||
|
||
Compatible C code can be built for this target on any compiler that has a RV32IM | ||
target. On clang and ld.lld linker, it can be generated using the | ||
`-march=rv32im`, `-mabi=ilp32` with llvm features flag `features=+m` and llvm | ||
target `riscv32-unknown-none`. | ||
|
||
[RISC-V specification]: https://riscv.org/wp-content/uploads/2015/01/riscv-calling.pdf | ||
[cargo-prove]: https://docs.succinct.xyz/docs/sp1/getting-started/install | ||
[sp1-build]: https://crates.io/crates/sp1-build |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
By putting a dash in the target OS, you make it look like it's vendor:succinct, os:zkvm. I would recommend calling it
riscv32im-succinct_zkvm-elf
or even justrustc32im-succinct-elf
insteadThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed!