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!");
}