1. Install the Nexus zkVM
First, install Rust: https://www.rust-lang.org/tools/install. Next, install the RISC-V target:cargo nexus
CLI is minimal, providing just a cargo nexus host
command to setup an SDK based project.
2. Create a new Nexus host project
To use the zkVM programmatically, we need two programs: a guest program that runs on the zkVM, and a host program that operates the zkVM itself. Run:./src/main.rs
is our host program, while ./src/guest/src/main.rs
is our guest program.
As a slightly more interesting example than the default Hello, World! program, you can change the content of ./src/guest/src/main.rs
to:
./src/main.rs
to:
x = 5
and private input y = 3
.
The zkVM will then run the guest program, return a view containing the output (z = 15
) and logs, and produce a proof of its correct execution.
After the proving completes, the host program then reads the output out of the view, checks it and prints it along with any logs, and then verifies the proof.
3. Run your program
Next, we can run the host program (including executing and proving the guest program) with:4. Run in legacy mode
In addition the Stwo-based Nexus zkVM 3.0 prover, the SDK also supports a legacy mode that uses the Nova, HyperNova, and (experimental) Jolt-based Nexus zkVM 2.0 machine. This machine uses a different runtime and requires additional configuration on the host side due to the use of public parameters and reference strings. To use the legacy mode, you must first activate the appropriate feature for thenexus-sdk
dependency in the host program: legacy-nova
, legacy-hypernova
, or legacy-jolt
. Examples of using legacy mode to prove legacy guest programs are provided in the examples folder on Github.
To review the code used in the legacy mode, it corresponds to the Nexus zkVM v0.2.4 release.