SDK Quick Start
1
2
Create a new Nexus host project
$ rustup run nightly-2025-05-09 cargo nexus host nexus-host./nexus-host
├── Cargo.lock
├── Cargo.toml
├── rust-toolchain.toml
└── src
├── main.rs
└── guest
├── Cargo.toml
├── rust-toolchain.toml
└── src
└── main.rs#![cfg_attr(target_arch = "riscv32", no_std, no_main)]
use nexus_rt::println;
#[nexus_rt::main]
#[nexus_rt::public_input(x)]
fn main(x: u32, y: u32) -> u32 {
println!("Read public input: {}", x);
println!("Read private input: {}", y);
x * y
}use nexus_sdk::{
compile::{cargo::CargoPackager, Compile, Compiler},
stwo::seq::Stwo,
ByGuestCompilation, Local, Prover, Verifiable, Viewable,
};
const PACKAGE: &str = "guest";
fn main() {
println!("Compiling guest program...");
let mut prover_compiler = Compiler::<CargoPackager>::new(PACKAGE);
let prover: Stwo<Local> =
Stwo::compile(&mut prover_compiler).expect("failed to compile guest program");
let elf = prover.elf.clone(); // save elf for use with test verification
print!("Proving execution of vm... ");
let (view, proof) = prover
.prove_with_input::<u32, u32>(&3, &5)
.expect("failed to prove program"); // x = 5, y = 3
assert_eq!(view.exit_code().expect("failed to retrieve exit code"), nexus_sdk::KnownExitCodes::EXIT_SUCCESS as u32);
let output: u32 = view
.public_output::<u32>()
.expect("failed to retrieve public output");
assert_eq!(output, 15); // z = 15
println!("output is {}!", output);
println!(
">>>>> Logging\n{}<<<<<",
view.logs().expect("failed to retrieve debug logs").join("")
);
print!("Verifying execution...");
proof
.verify_expected::<u32, u32>(
&5, // x = 5
nexus_sdk::KnownExitCodes::EXIT_SUCCESS as u32,
&15, // z = 15
&elf, // expected elf (program binary)
&[], // no associated data,
)
.expect("failed to verify proof");
println!(" Succeeded!");
}3
Last updated

