diff --git a/nexus/ped_bls12-381_test/.gitignore b/nexus/ped_bls12-381_test/.gitignore new file mode 100644 index 0000000..ea8c4bf --- /dev/null +++ b/nexus/ped_bls12-381_test/.gitignore @@ -0,0 +1 @@ +/target diff --git a/nexus/ped_bls12-381_test/Cargo.toml b/nexus/ped_bls12-381_test/Cargo.toml new file mode 100644 index 0000000..f1cf7e2 --- /dev/null +++ b/nexus/ped_bls12-381_test/Cargo.toml @@ -0,0 +1,14 @@ +[package] +name = "ped_bls12-381_test" +version = "0.1.0" +edition = "2024" + +[dependencies] +nexus-sdk = { git = "https://github.com/nexus-xyz/nexus-zkvm.git", tag = "0.3.4", version = "0.3.4" } + +[workspace] +members = [ + "src/guest" +] + + diff --git a/nexus/ped_bls12-381_test/rust-toolchain.toml b/nexus/ped_bls12-381_test/rust-toolchain.toml new file mode 100644 index 0000000..96e0415 --- /dev/null +++ b/nexus/ped_bls12-381_test/rust-toolchain.toml @@ -0,0 +1,2 @@ +[toolchain] +channel = "nightly-2025-04-06" diff --git a/nexus/ped_bls12-381_test/src/guest/.cargo/config.toml b/nexus/ped_bls12-381_test/src/guest/.cargo/config.toml new file mode 100644 index 0000000..80e2c50 --- /dev/null +++ b/nexus/ped_bls12-381_test/src/guest/.cargo/config.toml @@ -0,0 +1,5 @@ +[target.riscv32i-unknown-none-elf] +rustflags = [ + "-C", "link-arg=-Tlink.x", +] +runner="nexus-run" diff --git a/nexus/ped_bls12-381_test/src/guest/Cargo.toml b/nexus/ped_bls12-381_test/src/guest/Cargo.toml new file mode 100644 index 0000000..da8c52d --- /dev/null +++ b/nexus/ped_bls12-381_test/src/guest/Cargo.toml @@ -0,0 +1,14 @@ +[package] +name = "guest" +version = "0.1.0" +edition = "2024" + +[dependencies] +nexus-rt = { git = "https://github.com/nexus-xyz/nexus-zkvm.git", tag = "0.3.4", version = "0.3.4" } +postcard = { version = "1.1.1", default-features = false, features = ["alloc"] } + +# Generated by cargo-nexus, do not remove! +# +[features] +cycles = [] # Enable cycle counting for run command + diff --git a/nexus/ped_bls12-381_test/src/guest/rust-toolchain.toml b/nexus/ped_bls12-381_test/src/guest/rust-toolchain.toml new file mode 100644 index 0000000..96e0415 --- /dev/null +++ b/nexus/ped_bls12-381_test/src/guest/rust-toolchain.toml @@ -0,0 +1,2 @@ +[toolchain] +channel = "nightly-2025-04-06" diff --git a/nexus/ped_bls12-381_test/src/guest/src/main.rs b/nexus/ped_bls12-381_test/src/guest/src/main.rs new file mode 100644 index 0000000..9a982df --- /dev/null +++ b/nexus/ped_bls12-381_test/src/guest/src/main.rs @@ -0,0 +1,8 @@ +#![cfg_attr(target_arch = "riscv32", no_std, no_main)] + +use nexus_rt::print; + +#[nexus_rt::main] +fn main() { + print!("Hello, World!\n"); +} diff --git a/nexus/ped_bls12-381_test/src/main.rs b/nexus/ped_bls12-381_test/src/main.rs new file mode 100644 index 0000000..6ea72ac --- /dev/null +++ b/nexus/ped_bls12-381_test/src/main.rs @@ -0,0 +1,65 @@ +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::::new(PACKAGE); + let prover: Stwo = + Stwo::compile(&mut prover_compiler).expect("failed to compile guest program"); + + let elf = prover.elf.clone(); // save elf for use with verification + + println!("Proving execution of vm..."); + let (view, proof) = prover.prove().expect("failed to prove program"); + + println!( + ">>>>> Logging\n{}<<<<<", + view.logs().expect("failed to retrieve debug logs").join("") + ); + assert_eq!( + view.exit_code().expect("failed to retrieve exit code"), + nexus_sdk::KnownExitCodes::ExitSuccess as u32 + ); + + // Normally the prover communicates the seralized proof to the verifier who deserializes it. + // + // The verifier must also possess the program binary and the public i/o. Usually, either + // the verifier will rebuild the elf in a reproducible way (e.g., within a container) or + // the prover will communicate it to the verifier who will then check that it is a valid + // compilation of the claimed guest program. Here we simulate the latter. + // + // If we instead wanted to simulate the former, it might look something like: + // + // println!("Verifier recompiling guest program..."); + // let mut verifier_compiler = Compiler::::new(PACKAGE); + // let path = verifier_compiler.build().expect("failed to (re)compile guest program"); + // + // print!("Verifying execution..."); + // proof.verify_expected_from_program_path::<&str, (), ()>( + // &(), // no public input + // nexus_sdk::KnownExitCodes::ExitSuccess as u32, + // &(), // no public output + // &path, // path to expected program binary + // &[] // no associated data, + // ).expect("failed to verify proof"); + + print!("Verifying execution..."); + + #[rustfmt::skip] + proof + .verify_expected::<(), ()>( + &(), // no public input + nexus_sdk::KnownExitCodes::ExitSuccess as u32, + &(), // no public output + &elf, // expected elf (program binary) + &[], // no associated data, + ) + .expect("failed to verify proof"); + + println!(" Succeeded!"); +} diff --git a/nexus/ped_bn254_test/.gitignore b/nexus/ped_bn254_test/.gitignore new file mode 100644 index 0000000..ea8c4bf --- /dev/null +++ b/nexus/ped_bn254_test/.gitignore @@ -0,0 +1 @@ +/target diff --git a/nexus/ped_bn254_test/Cargo.toml b/nexus/ped_bn254_test/Cargo.toml new file mode 100644 index 0000000..2178469 --- /dev/null +++ b/nexus/ped_bn254_test/Cargo.toml @@ -0,0 +1,14 @@ +[package] +name = "ped_bn254_test" +version = "0.1.0" +edition = "2024" + +[dependencies] +nexus-sdk = { git = "https://github.com/nexus-xyz/nexus-zkvm.git", tag = "0.3.4", version = "0.3.4" } + +[workspace] +members = [ + "src/guest" +] + + diff --git a/nexus/ped_bn254_test/rust-toolchain.toml b/nexus/ped_bn254_test/rust-toolchain.toml new file mode 100644 index 0000000..96e0415 --- /dev/null +++ b/nexus/ped_bn254_test/rust-toolchain.toml @@ -0,0 +1,2 @@ +[toolchain] +channel = "nightly-2025-04-06" diff --git a/nexus/ped_bn254_test/src/guest/.cargo/config.toml b/nexus/ped_bn254_test/src/guest/.cargo/config.toml new file mode 100644 index 0000000..80e2c50 --- /dev/null +++ b/nexus/ped_bn254_test/src/guest/.cargo/config.toml @@ -0,0 +1,5 @@ +[target.riscv32i-unknown-none-elf] +rustflags = [ + "-C", "link-arg=-Tlink.x", +] +runner="nexus-run" diff --git a/nexus/ped_bn254_test/src/guest/Cargo.toml b/nexus/ped_bn254_test/src/guest/Cargo.toml new file mode 100644 index 0000000..96504ec --- /dev/null +++ b/nexus/ped_bn254_test/src/guest/Cargo.toml @@ -0,0 +1,16 @@ +[package] +name = "guest" +version = "0.1.0" +edition = "2024" + +[dependencies] +nexus-rt = { git = "https://github.com/nexus-xyz/nexus-zkvm.git", tag = "0.3.4", version = "0.3.4" } +postcard = { version = "1.1.1", default-features = false, features = ["alloc"] } +ark-bn254 = "0.5.0" +ark-ec = "0.5.0" + +# Generated by cargo-nexus, do not remove! +# +[features] +cycles = [] # Enable cycle counting for run command + diff --git a/nexus/ped_bn254_test/src/guest/rust-toolchain.toml b/nexus/ped_bn254_test/src/guest/rust-toolchain.toml new file mode 100644 index 0000000..96e0415 --- /dev/null +++ b/nexus/ped_bn254_test/src/guest/rust-toolchain.toml @@ -0,0 +1,2 @@ +[toolchain] +channel = "nightly-2025-04-06" diff --git a/nexus/ped_bn254_test/src/guest/src/main.rs b/nexus/ped_bn254_test/src/guest/src/main.rs new file mode 100644 index 0000000..bad2977 --- /dev/null +++ b/nexus/ped_bn254_test/src/guest/src/main.rs @@ -0,0 +1,20 @@ +#![cfg_attr(target_arch = "riscv32", no_std, no_main)] + +use ark_ec::{CurveGroup, PrimeGroup}; + +#[nexus_rt::main] +fn main() { + let g1 = ark_bn254::G1Projective::generator(); + let g2 = g1 + g1; + let g3 = g1 + g2; + let g4 = g1 + g3; + let g5 = g1 + g4; + + let s1 = ark_bn254::Fr::from(87329482u64); + let s2 = ark_bn254::Fr::from(37264829u64); + let s3 = ark_bn254::Fr::from(98098098u64); + let s4 = ark_bn254::Fr::from(63980948u64); + let s5 = ark_bn254::Fr::from(15098098u64); + + let _ = (g1*s1 + g2*s2 + g3*s3 + g4*s4 + g5*s5).into_affine(); +} diff --git a/nexus/ped_bn254_test/src/main.rs b/nexus/ped_bn254_test/src/main.rs new file mode 100644 index 0000000..6ea72ac --- /dev/null +++ b/nexus/ped_bn254_test/src/main.rs @@ -0,0 +1,65 @@ +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::::new(PACKAGE); + let prover: Stwo = + Stwo::compile(&mut prover_compiler).expect("failed to compile guest program"); + + let elf = prover.elf.clone(); // save elf for use with verification + + println!("Proving execution of vm..."); + let (view, proof) = prover.prove().expect("failed to prove program"); + + println!( + ">>>>> Logging\n{}<<<<<", + view.logs().expect("failed to retrieve debug logs").join("") + ); + assert_eq!( + view.exit_code().expect("failed to retrieve exit code"), + nexus_sdk::KnownExitCodes::ExitSuccess as u32 + ); + + // Normally the prover communicates the seralized proof to the verifier who deserializes it. + // + // The verifier must also possess the program binary and the public i/o. Usually, either + // the verifier will rebuild the elf in a reproducible way (e.g., within a container) or + // the prover will communicate it to the verifier who will then check that it is a valid + // compilation of the claimed guest program. Here we simulate the latter. + // + // If we instead wanted to simulate the former, it might look something like: + // + // println!("Verifier recompiling guest program..."); + // let mut verifier_compiler = Compiler::::new(PACKAGE); + // let path = verifier_compiler.build().expect("failed to (re)compile guest program"); + // + // print!("Verifying execution..."); + // proof.verify_expected_from_program_path::<&str, (), ()>( + // &(), // no public input + // nexus_sdk::KnownExitCodes::ExitSuccess as u32, + // &(), // no public output + // &path, // path to expected program binary + // &[] // no associated data, + // ).expect("failed to verify proof"); + + print!("Verifying execution..."); + + #[rustfmt::skip] + proof + .verify_expected::<(), ()>( + &(), // no public input + nexus_sdk::KnownExitCodes::ExitSuccess as u32, + &(), // no public output + &elf, // expected elf (program binary) + &[], // no associated data, + ) + .expect("failed to verify proof"); + + println!(" Succeeded!"); +} diff --git a/nexus/ped_curve25519_test/.gitignore b/nexus/ped_curve25519_test/.gitignore new file mode 100644 index 0000000..ea8c4bf --- /dev/null +++ b/nexus/ped_curve25519_test/.gitignore @@ -0,0 +1 @@ +/target diff --git a/nexus/ped_curve25519_test/Cargo.toml b/nexus/ped_curve25519_test/Cargo.toml new file mode 100644 index 0000000..95b9df4 --- /dev/null +++ b/nexus/ped_curve25519_test/Cargo.toml @@ -0,0 +1,14 @@ +[package] +name = "ped_curve25519_test" +version = "0.1.0" +edition = "2024" + +[dependencies] +nexus-sdk = { git = "https://github.com/nexus-xyz/nexus-zkvm.git", tag = "0.3.4", version = "0.3.4" } + +[workspace] +members = [ + "src/guest" +] + + diff --git a/nexus/ped_curve25519_test/rust-toolchain.toml b/nexus/ped_curve25519_test/rust-toolchain.toml new file mode 100644 index 0000000..96e0415 --- /dev/null +++ b/nexus/ped_curve25519_test/rust-toolchain.toml @@ -0,0 +1,2 @@ +[toolchain] +channel = "nightly-2025-04-06" diff --git a/nexus/ped_curve25519_test/src/guest/.cargo/config.toml b/nexus/ped_curve25519_test/src/guest/.cargo/config.toml new file mode 100644 index 0000000..80e2c50 --- /dev/null +++ b/nexus/ped_curve25519_test/src/guest/.cargo/config.toml @@ -0,0 +1,5 @@ +[target.riscv32i-unknown-none-elf] +rustflags = [ + "-C", "link-arg=-Tlink.x", +] +runner="nexus-run" diff --git a/nexus/ped_curve25519_test/src/guest/Cargo.toml b/nexus/ped_curve25519_test/src/guest/Cargo.toml new file mode 100644 index 0000000..517fa06 --- /dev/null +++ b/nexus/ped_curve25519_test/src/guest/Cargo.toml @@ -0,0 +1,15 @@ +[package] +name = "guest" +version = "0.1.0" +edition = "2024" + +[dependencies] +nexus-rt = { git = "https://github.com/nexus-xyz/nexus-zkvm.git", tag = "0.3.4", version = "0.3.4" } +postcard = { version = "1.1.1", default-features = false, features = ["alloc"] } +curve25519-dalek = "4" + +# Generated by cargo-nexus, do not remove! +# +[features] +cycles = [] # Enable cycle counting for run command + diff --git a/nexus/ped_curve25519_test/src/guest/rust-toolchain.toml b/nexus/ped_curve25519_test/src/guest/rust-toolchain.toml new file mode 100644 index 0000000..96e0415 --- /dev/null +++ b/nexus/ped_curve25519_test/src/guest/rust-toolchain.toml @@ -0,0 +1,2 @@ +[toolchain] +channel = "nightly-2025-04-06" diff --git a/nexus/ped_curve25519_test/src/guest/src/main.rs b/nexus/ped_curve25519_test/src/guest/src/main.rs new file mode 100644 index 0000000..277e13f --- /dev/null +++ b/nexus/ped_curve25519_test/src/guest/src/main.rs @@ -0,0 +1,29 @@ +#![cfg_attr(target_arch = "riscv32", no_std, no_main)] + +use curve25519_dalek::constants; +use curve25519_dalek::ristretto::RistrettoPoint; +use curve25519_dalek::scalar::Scalar; +use curve25519_dalek::traits::MultiscalarMul; + +#[nexus_rt::main] +fn main() { + // read the input + let input: u32 = env::read(); + + // TODO: do something with the input + let s1 = Scalar::from(87329482u64); + let s2 = Scalar::from(37264829u64); + let s3 = Scalar::from(98098098u64); + let s4 = Scalar::from(63980948u64); + let s5 = Scalar::from(15098098u64); + + let g1 = constants::RISTRETTO_BASEPOINT_POINT; + let g2 = g1 + g1; + let g3 = g1 + g2; + let g4 = g1 + g3; + let g5 = g1 + g4; + + let nums = [s1,s2,s3,s4,s5]; + + let _ = RistrettoPoint::multiscalar_mul(&nums, &[g1,g2,g3,g4,g5]); +} diff --git a/nexus/ped_curve25519_test/src/main.rs b/nexus/ped_curve25519_test/src/main.rs new file mode 100644 index 0000000..6ea72ac --- /dev/null +++ b/nexus/ped_curve25519_test/src/main.rs @@ -0,0 +1,65 @@ +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::::new(PACKAGE); + let prover: Stwo = + Stwo::compile(&mut prover_compiler).expect("failed to compile guest program"); + + let elf = prover.elf.clone(); // save elf for use with verification + + println!("Proving execution of vm..."); + let (view, proof) = prover.prove().expect("failed to prove program"); + + println!( + ">>>>> Logging\n{}<<<<<", + view.logs().expect("failed to retrieve debug logs").join("") + ); + assert_eq!( + view.exit_code().expect("failed to retrieve exit code"), + nexus_sdk::KnownExitCodes::ExitSuccess as u32 + ); + + // Normally the prover communicates the seralized proof to the verifier who deserializes it. + // + // The verifier must also possess the program binary and the public i/o. Usually, either + // the verifier will rebuild the elf in a reproducible way (e.g., within a container) or + // the prover will communicate it to the verifier who will then check that it is a valid + // compilation of the claimed guest program. Here we simulate the latter. + // + // If we instead wanted to simulate the former, it might look something like: + // + // println!("Verifier recompiling guest program..."); + // let mut verifier_compiler = Compiler::::new(PACKAGE); + // let path = verifier_compiler.build().expect("failed to (re)compile guest program"); + // + // print!("Verifying execution..."); + // proof.verify_expected_from_program_path::<&str, (), ()>( + // &(), // no public input + // nexus_sdk::KnownExitCodes::ExitSuccess as u32, + // &(), // no public output + // &path, // path to expected program binary + // &[] // no associated data, + // ).expect("failed to verify proof"); + + print!("Verifying execution..."); + + #[rustfmt::skip] + proof + .verify_expected::<(), ()>( + &(), // no public input + nexus_sdk::KnownExitCodes::ExitSuccess as u32, + &(), // no public output + &elf, // expected elf (program binary) + &[], // no associated data, + ) + .expect("failed to verify proof"); + + println!(" Succeeded!"); +} diff --git a/nexus/ped_jubjub_test/.gitignore b/nexus/ped_jubjub_test/.gitignore new file mode 100644 index 0000000..ea8c4bf --- /dev/null +++ b/nexus/ped_jubjub_test/.gitignore @@ -0,0 +1 @@ +/target diff --git a/nexus/ped_jubjub_test/Cargo.toml b/nexus/ped_jubjub_test/Cargo.toml new file mode 100644 index 0000000..bb46ab0 --- /dev/null +++ b/nexus/ped_jubjub_test/Cargo.toml @@ -0,0 +1,14 @@ +[package] +name = "ped_jubjub_test" +version = "0.1.0" +edition = "2024" + +[dependencies] +nexus-sdk = { git = "https://github.com/nexus-xyz/nexus-zkvm.git", tag = "0.3.4", version = "0.3.4" } + +[workspace] +members = [ + "src/guest" +] + + diff --git a/nexus/ped_jubjub_test/rust-toolchain.toml b/nexus/ped_jubjub_test/rust-toolchain.toml new file mode 100644 index 0000000..96e0415 --- /dev/null +++ b/nexus/ped_jubjub_test/rust-toolchain.toml @@ -0,0 +1,2 @@ +[toolchain] +channel = "nightly-2025-04-06" diff --git a/nexus/ped_jubjub_test/src/guest/.cargo/config.toml b/nexus/ped_jubjub_test/src/guest/.cargo/config.toml new file mode 100644 index 0000000..80e2c50 --- /dev/null +++ b/nexus/ped_jubjub_test/src/guest/.cargo/config.toml @@ -0,0 +1,5 @@ +[target.riscv32i-unknown-none-elf] +rustflags = [ + "-C", "link-arg=-Tlink.x", +] +runner="nexus-run" diff --git a/nexus/ped_jubjub_test/src/guest/Cargo.toml b/nexus/ped_jubjub_test/src/guest/Cargo.toml new file mode 100644 index 0000000..6292895 --- /dev/null +++ b/nexus/ped_jubjub_test/src/guest/Cargo.toml @@ -0,0 +1,15 @@ +[package] +name = "guest" +version = "0.1.0" +edition = "2024" + +[dependencies] +nexus-rt = { git = "https://github.com/nexus-xyz/nexus-zkvm.git", tag = "0.3.4", version = "0.3.4" } +postcard = { version = "1.1.1", default-features = false, features = ["alloc"] } +jubjub = "0.10.0" +group = "0.13.0" +# Generated by cargo-nexus, do not remove! +# +[features] +cycles = [] # Enable cycle counting for run command + diff --git a/nexus/ped_jubjub_test/src/guest/rust-toolchain.toml b/nexus/ped_jubjub_test/src/guest/rust-toolchain.toml new file mode 100644 index 0000000..96e0415 --- /dev/null +++ b/nexus/ped_jubjub_test/src/guest/rust-toolchain.toml @@ -0,0 +1,2 @@ +[toolchain] +channel = "nightly-2025-04-06" diff --git a/nexus/ped_jubjub_test/src/guest/src/main.rs b/nexus/ped_jubjub_test/src/guest/src/main.rs new file mode 100644 index 0000000..44f20b7 --- /dev/null +++ b/nexus/ped_jubjub_test/src/guest/src/main.rs @@ -0,0 +1,19 @@ +#![cfg_attr(target_arch = "riscv32", no_std, no_main)] +use group::Group; + +#[nexus_rt::main] +fn main() { + let g1 = jubjub::SubgroupPoint::generator(); + let g2 = g1 + g1; + let g3 = g1 + g2; + let g4 = g1 + g3; + let g5 = g1 + g4; + + let s1 = jubjub::Fr::from(87329482u64); + let s2 = jubjub::Fr::from(37264829u64); + let s3 = jubjub::Fr::from(98098098u64); + let s4 = jubjub::Fr::from(63980948u64); + let s5 = jubjub::Fr::from(15098098u64); + + let _ = g1*s1 + g2*s2 + g3*s3 + g4*s4 + g5*s5; +} diff --git a/nexus/ped_jubjub_test/src/main.rs b/nexus/ped_jubjub_test/src/main.rs new file mode 100644 index 0000000..6ea72ac --- /dev/null +++ b/nexus/ped_jubjub_test/src/main.rs @@ -0,0 +1,65 @@ +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::::new(PACKAGE); + let prover: Stwo = + Stwo::compile(&mut prover_compiler).expect("failed to compile guest program"); + + let elf = prover.elf.clone(); // save elf for use with verification + + println!("Proving execution of vm..."); + let (view, proof) = prover.prove().expect("failed to prove program"); + + println!( + ">>>>> Logging\n{}<<<<<", + view.logs().expect("failed to retrieve debug logs").join("") + ); + assert_eq!( + view.exit_code().expect("failed to retrieve exit code"), + nexus_sdk::KnownExitCodes::ExitSuccess as u32 + ); + + // Normally the prover communicates the seralized proof to the verifier who deserializes it. + // + // The verifier must also possess the program binary and the public i/o. Usually, either + // the verifier will rebuild the elf in a reproducible way (e.g., within a container) or + // the prover will communicate it to the verifier who will then check that it is a valid + // compilation of the claimed guest program. Here we simulate the latter. + // + // If we instead wanted to simulate the former, it might look something like: + // + // println!("Verifier recompiling guest program..."); + // let mut verifier_compiler = Compiler::::new(PACKAGE); + // let path = verifier_compiler.build().expect("failed to (re)compile guest program"); + // + // print!("Verifying execution..."); + // proof.verify_expected_from_program_path::<&str, (), ()>( + // &(), // no public input + // nexus_sdk::KnownExitCodes::ExitSuccess as u32, + // &(), // no public output + // &path, // path to expected program binary + // &[] // no associated data, + // ).expect("failed to verify proof"); + + print!("Verifying execution..."); + + #[rustfmt::skip] + proof + .verify_expected::<(), ()>( + &(), // no public input + nexus_sdk::KnownExitCodes::ExitSuccess as u32, + &(), // no public output + &elf, // expected elf (program binary) + &[], // no associated data, + ) + .expect("failed to verify proof"); + + println!(" Succeeded!"); +} diff --git a/nexus/ped_pallas_test/.gitignore b/nexus/ped_pallas_test/.gitignore new file mode 100644 index 0000000..ea8c4bf --- /dev/null +++ b/nexus/ped_pallas_test/.gitignore @@ -0,0 +1 @@ +/target diff --git a/nexus/ped_pallas_test/Cargo.toml b/nexus/ped_pallas_test/Cargo.toml new file mode 100644 index 0000000..c20f652 --- /dev/null +++ b/nexus/ped_pallas_test/Cargo.toml @@ -0,0 +1,14 @@ +[package] +name = "ped_pallas_test" +version = "0.1.0" +edition = "2024" + +[dependencies] +nexus-sdk = { git = "https://github.com/nexus-xyz/nexus-zkvm.git", tag = "0.3.4", version = "0.3.4" } + +[workspace] +members = [ + "src/guest" +] + + diff --git a/nexus/ped_pallas_test/rust-toolchain.toml b/nexus/ped_pallas_test/rust-toolchain.toml new file mode 100644 index 0000000..96e0415 --- /dev/null +++ b/nexus/ped_pallas_test/rust-toolchain.toml @@ -0,0 +1,2 @@ +[toolchain] +channel = "nightly-2025-04-06" diff --git a/nexus/ped_pallas_test/src/guest/.cargo/config.toml b/nexus/ped_pallas_test/src/guest/.cargo/config.toml new file mode 100644 index 0000000..80e2c50 --- /dev/null +++ b/nexus/ped_pallas_test/src/guest/.cargo/config.toml @@ -0,0 +1,5 @@ +[target.riscv32i-unknown-none-elf] +rustflags = [ + "-C", "link-arg=-Tlink.x", +] +runner="nexus-run" diff --git a/nexus/ped_pallas_test/src/guest/Cargo.toml b/nexus/ped_pallas_test/src/guest/Cargo.toml new file mode 100644 index 0000000..0287e21 --- /dev/null +++ b/nexus/ped_pallas_test/src/guest/Cargo.toml @@ -0,0 +1,15 @@ +[package] +name = "guest" +version = "0.1.0" +edition = "2024" + +[dependencies] +nexus-rt = { git = "https://github.com/nexus-xyz/nexus-zkvm.git", tag = "0.3.4", version = "0.3.4" } +postcard = { version = "1.1.1", default-features = false, features = ["alloc"] } +pasta_curves = "0.5.1" + +# Generated by cargo-nexus, do not remove! +# +[features] +cycles = [] # Enable cycle counting for run command + diff --git a/nexus/ped_pallas_test/src/guest/rust-toolchain.toml b/nexus/ped_pallas_test/src/guest/rust-toolchain.toml new file mode 100644 index 0000000..96e0415 --- /dev/null +++ b/nexus/ped_pallas_test/src/guest/rust-toolchain.toml @@ -0,0 +1,2 @@ +[toolchain] +channel = "nightly-2025-04-06" diff --git a/nexus/ped_pallas_test/src/guest/src/main.rs b/nexus/ped_pallas_test/src/guest/src/main.rs new file mode 100644 index 0000000..8a3f49d --- /dev/null +++ b/nexus/ped_pallas_test/src/guest/src/main.rs @@ -0,0 +1,19 @@ +#![cfg_attr(target_arch = "riscv32", no_std, no_main)] +use pasta_curves::group::Group; + +#[nexus_rt::main] +fn main() { + let g1 = pasta_curves::pallas::Point::generator(); + let g2 = g1 + g1; + let g3 = g1 + g2; + let g4 = g1 + g3; + let g5 = g1 + g4; + + let s1 = pasta_curves::pallas::Scalar::from(87329482u64); + let s2 = pasta_curves::pallas::Scalar::from(37264829u64); + let s3 = pasta_curves::pallas::Scalar::from(98098098u64); + let s4 = pasta_curves::pallas::Scalar::from(63980948u64); + let s5 = pasta_curves::pallas::Scalar::from(15098098u64); + + let _ = g1*s1 + g2*s2 + g3*s3 + g4*s4 + g5*s5; +} diff --git a/nexus/ped_pallas_test/src/main.rs b/nexus/ped_pallas_test/src/main.rs new file mode 100644 index 0000000..6ea72ac --- /dev/null +++ b/nexus/ped_pallas_test/src/main.rs @@ -0,0 +1,65 @@ +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::::new(PACKAGE); + let prover: Stwo = + Stwo::compile(&mut prover_compiler).expect("failed to compile guest program"); + + let elf = prover.elf.clone(); // save elf for use with verification + + println!("Proving execution of vm..."); + let (view, proof) = prover.prove().expect("failed to prove program"); + + println!( + ">>>>> Logging\n{}<<<<<", + view.logs().expect("failed to retrieve debug logs").join("") + ); + assert_eq!( + view.exit_code().expect("failed to retrieve exit code"), + nexus_sdk::KnownExitCodes::ExitSuccess as u32 + ); + + // Normally the prover communicates the seralized proof to the verifier who deserializes it. + // + // The verifier must also possess the program binary and the public i/o. Usually, either + // the verifier will rebuild the elf in a reproducible way (e.g., within a container) or + // the prover will communicate it to the verifier who will then check that it is a valid + // compilation of the claimed guest program. Here we simulate the latter. + // + // If we instead wanted to simulate the former, it might look something like: + // + // println!("Verifier recompiling guest program..."); + // let mut verifier_compiler = Compiler::::new(PACKAGE); + // let path = verifier_compiler.build().expect("failed to (re)compile guest program"); + // + // print!("Verifying execution..."); + // proof.verify_expected_from_program_path::<&str, (), ()>( + // &(), // no public input + // nexus_sdk::KnownExitCodes::ExitSuccess as u32, + // &(), // no public output + // &path, // path to expected program binary + // &[] // no associated data, + // ).expect("failed to verify proof"); + + print!("Verifying execution..."); + + #[rustfmt::skip] + proof + .verify_expected::<(), ()>( + &(), // no public input + nexus_sdk::KnownExitCodes::ExitSuccess as u32, + &(), // no public output + &elf, // expected elf (program binary) + &[], // no associated data, + ) + .expect("failed to verify proof"); + + println!(" Succeeded!"); +} diff --git a/nexus/ped_secp256k1_test/.gitignore b/nexus/ped_secp256k1_test/.gitignore new file mode 100644 index 0000000..ea8c4bf --- /dev/null +++ b/nexus/ped_secp256k1_test/.gitignore @@ -0,0 +1 @@ +/target diff --git a/nexus/ped_secp256k1_test/Cargo.toml b/nexus/ped_secp256k1_test/Cargo.toml new file mode 100644 index 0000000..58f7e80 --- /dev/null +++ b/nexus/ped_secp256k1_test/Cargo.toml @@ -0,0 +1,14 @@ +[package] +name = "ped_secp256k1_test" +version = "0.1.0" +edition = "2024" + +[dependencies] +nexus-sdk = { git = "https://github.com/nexus-xyz/nexus-zkvm.git", tag = "0.3.4", version = "0.3.4" } + +[workspace] +members = [ + "src/guest" +] + + diff --git a/nexus/ped_secp256k1_test/rust-toolchain.toml b/nexus/ped_secp256k1_test/rust-toolchain.toml new file mode 100644 index 0000000..96e0415 --- /dev/null +++ b/nexus/ped_secp256k1_test/rust-toolchain.toml @@ -0,0 +1,2 @@ +[toolchain] +channel = "nightly-2025-04-06" diff --git a/nexus/ped_secp256k1_test/src/guest/.cargo/config.toml b/nexus/ped_secp256k1_test/src/guest/.cargo/config.toml new file mode 100644 index 0000000..80e2c50 --- /dev/null +++ b/nexus/ped_secp256k1_test/src/guest/.cargo/config.toml @@ -0,0 +1,5 @@ +[target.riscv32i-unknown-none-elf] +rustflags = [ + "-C", "link-arg=-Tlink.x", +] +runner="nexus-run" diff --git a/nexus/ped_secp256k1_test/src/guest/Cargo.toml b/nexus/ped_secp256k1_test/src/guest/Cargo.toml new file mode 100644 index 0000000..331079f --- /dev/null +++ b/nexus/ped_secp256k1_test/src/guest/Cargo.toml @@ -0,0 +1,14 @@ +[package] +name = "guest" +version = "0.1.0" +edition = "2024" + +[dependencies] +nexus-rt = { git = "https://github.com/nexus-xyz/nexus-zkvm.git", tag = "0.3.4", version = "0.3.4" } +postcard = { version = "1.1.1", default-features = false, features = ["alloc"] } +k256 = "0.13.4" +# Generated by cargo-nexus, do not remove! +# +[features] +cycles = [] # Enable cycle counting for run command + diff --git a/nexus/ped_secp256k1_test/src/guest/rust-toolchain.toml b/nexus/ped_secp256k1_test/src/guest/rust-toolchain.toml new file mode 100644 index 0000000..96e0415 --- /dev/null +++ b/nexus/ped_secp256k1_test/src/guest/rust-toolchain.toml @@ -0,0 +1,2 @@ +[toolchain] +channel = "nightly-2025-04-06" diff --git a/nexus/ped_secp256k1_test/src/guest/src/main.rs b/nexus/ped_secp256k1_test/src/guest/src/main.rs new file mode 100644 index 0000000..c4c1291 --- /dev/null +++ b/nexus/ped_secp256k1_test/src/guest/src/main.rs @@ -0,0 +1,21 @@ +#![cfg_attr(target_arch = "riscv32", no_std, no_main)] + +use nexus_rt::print; + +#[nexus_rt::main] +fn main() { + let g1 = k256::ProjectivePoint::GENERATOR; + let g2 = g1 + g1; + let g3 = g1 + g2; + let g4 = g1 + g3; + let g5 = g1 + g4; + + + let s1 = k256::Scalar::from(87329482u64); + let s2 = k256::Scalar::from(37264829u64); + let s3 = k256::Scalar::from(98098098u64); + let s4 = k256::Scalar::from(63980948u64); + let s5 = k256::Scalar::from(15098098u64); + + let _ = g1*s1 + g2*s2 + g3*s3 + g4*s4 + g5*s5; +} diff --git a/nexus/ped_secp256k1_test/src/main.rs b/nexus/ped_secp256k1_test/src/main.rs new file mode 100644 index 0000000..6ea72ac --- /dev/null +++ b/nexus/ped_secp256k1_test/src/main.rs @@ -0,0 +1,65 @@ +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::::new(PACKAGE); + let prover: Stwo = + Stwo::compile(&mut prover_compiler).expect("failed to compile guest program"); + + let elf = prover.elf.clone(); // save elf for use with verification + + println!("Proving execution of vm..."); + let (view, proof) = prover.prove().expect("failed to prove program"); + + println!( + ">>>>> Logging\n{}<<<<<", + view.logs().expect("failed to retrieve debug logs").join("") + ); + assert_eq!( + view.exit_code().expect("failed to retrieve exit code"), + nexus_sdk::KnownExitCodes::ExitSuccess as u32 + ); + + // Normally the prover communicates the seralized proof to the verifier who deserializes it. + // + // The verifier must also possess the program binary and the public i/o. Usually, either + // the verifier will rebuild the elf in a reproducible way (e.g., within a container) or + // the prover will communicate it to the verifier who will then check that it is a valid + // compilation of the claimed guest program. Here we simulate the latter. + // + // If we instead wanted to simulate the former, it might look something like: + // + // println!("Verifier recompiling guest program..."); + // let mut verifier_compiler = Compiler::::new(PACKAGE); + // let path = verifier_compiler.build().expect("failed to (re)compile guest program"); + // + // print!("Verifying execution..."); + // proof.verify_expected_from_program_path::<&str, (), ()>( + // &(), // no public input + // nexus_sdk::KnownExitCodes::ExitSuccess as u32, + // &(), // no public output + // &path, // path to expected program binary + // &[] // no associated data, + // ).expect("failed to verify proof"); + + print!("Verifying execution..."); + + #[rustfmt::skip] + proof + .verify_expected::<(), ()>( + &(), // no public input + nexus_sdk::KnownExitCodes::ExitSuccess as u32, + &(), // no public output + &elf, // expected elf (program binary) + &[], // no associated data, + ) + .expect("failed to verify proof"); + + println!(" Succeeded!"); +} diff --git a/nexus/ped_vesta_test/.gitignore b/nexus/ped_vesta_test/.gitignore new file mode 100644 index 0000000..ea8c4bf --- /dev/null +++ b/nexus/ped_vesta_test/.gitignore @@ -0,0 +1 @@ +/target diff --git a/nexus/ped_vesta_test/Cargo.toml b/nexus/ped_vesta_test/Cargo.toml new file mode 100644 index 0000000..a26c2b4 --- /dev/null +++ b/nexus/ped_vesta_test/Cargo.toml @@ -0,0 +1,14 @@ +[package] +name = "ped_vesta_test" +version = "0.1.0" +edition = "2024" + +[dependencies] +nexus-sdk = { git = "https://github.com/nexus-xyz/nexus-zkvm.git", tag = "0.3.4", version = "0.3.4" } + +[workspace] +members = [ + "src/guest" +] + + diff --git a/nexus/ped_vesta_test/rust-toolchain.toml b/nexus/ped_vesta_test/rust-toolchain.toml new file mode 100644 index 0000000..96e0415 --- /dev/null +++ b/nexus/ped_vesta_test/rust-toolchain.toml @@ -0,0 +1,2 @@ +[toolchain] +channel = "nightly-2025-04-06" diff --git a/nexus/ped_vesta_test/src/guest/.cargo/config.toml b/nexus/ped_vesta_test/src/guest/.cargo/config.toml new file mode 100644 index 0000000..80e2c50 --- /dev/null +++ b/nexus/ped_vesta_test/src/guest/.cargo/config.toml @@ -0,0 +1,5 @@ +[target.riscv32i-unknown-none-elf] +rustflags = [ + "-C", "link-arg=-Tlink.x", +] +runner="nexus-run" diff --git a/nexus/ped_vesta_test/src/guest/Cargo.toml b/nexus/ped_vesta_test/src/guest/Cargo.toml new file mode 100644 index 0000000..03db174 --- /dev/null +++ b/nexus/ped_vesta_test/src/guest/Cargo.toml @@ -0,0 +1,14 @@ +[package] +name = "guest" +version = "0.1.0" +edition = "2024" + +[dependencies] +nexus-rt = { git = "https://github.com/nexus-xyz/nexus-zkvm.git", tag = "0.3.4", version = "0.3.4" } +postcard = { version = "1.1.1", default-features = false, features = ["alloc"] } +pasta_curves = "0.5.1" +# Generated by cargo-nexus, do not remove! +# +[features] +cycles = [] # Enable cycle counting for run command + diff --git a/nexus/ped_vesta_test/src/guest/rust-toolchain.toml b/nexus/ped_vesta_test/src/guest/rust-toolchain.toml new file mode 100644 index 0000000..96e0415 --- /dev/null +++ b/nexus/ped_vesta_test/src/guest/rust-toolchain.toml @@ -0,0 +1,2 @@ +[toolchain] +channel = "nightly-2025-04-06" diff --git a/nexus/ped_vesta_test/src/guest/src/main.rs b/nexus/ped_vesta_test/src/guest/src/main.rs new file mode 100644 index 0000000..b64f3f9 --- /dev/null +++ b/nexus/ped_vesta_test/src/guest/src/main.rs @@ -0,0 +1,19 @@ +#![cfg_attr(target_arch = "riscv32", no_std, no_main)] +use pasta_curves::group::Group; + +#[nexus_rt::main] +fn main() { + let g1 = pasta_curves::vesta::Point::generator(); + let g2 = g1 + g1; + let g3 = g1 + g2; + let g4 = g1 + g3; + let g5 = g1 + g4; + + let s1 = pasta_curves::vesta::Scalar::from(87329482u64); + let s2 = pasta_curves::vesta::Scalar::from(37264829u64); + let s3 = pasta_curves::vesta::Scalar::from(98098098u64); + let s4 = pasta_curves::vesta::Scalar::from(63980948u64); + let s5 = pasta_curves::vesta::Scalar::from(15098098u64); + + let _ = g1*s1 + g2*s2 + g3*s3 + g4*s4 + g5*s5; +} diff --git a/nexus/ped_vesta_test/src/main.rs b/nexus/ped_vesta_test/src/main.rs new file mode 100644 index 0000000..6ea72ac --- /dev/null +++ b/nexus/ped_vesta_test/src/main.rs @@ -0,0 +1,65 @@ +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::::new(PACKAGE); + let prover: Stwo = + Stwo::compile(&mut prover_compiler).expect("failed to compile guest program"); + + let elf = prover.elf.clone(); // save elf for use with verification + + println!("Proving execution of vm..."); + let (view, proof) = prover.prove().expect("failed to prove program"); + + println!( + ">>>>> Logging\n{}<<<<<", + view.logs().expect("failed to retrieve debug logs").join("") + ); + assert_eq!( + view.exit_code().expect("failed to retrieve exit code"), + nexus_sdk::KnownExitCodes::ExitSuccess as u32 + ); + + // Normally the prover communicates the seralized proof to the verifier who deserializes it. + // + // The verifier must also possess the program binary and the public i/o. Usually, either + // the verifier will rebuild the elf in a reproducible way (e.g., within a container) or + // the prover will communicate it to the verifier who will then check that it is a valid + // compilation of the claimed guest program. Here we simulate the latter. + // + // If we instead wanted to simulate the former, it might look something like: + // + // println!("Verifier recompiling guest program..."); + // let mut verifier_compiler = Compiler::::new(PACKAGE); + // let path = verifier_compiler.build().expect("failed to (re)compile guest program"); + // + // print!("Verifying execution..."); + // proof.verify_expected_from_program_path::<&str, (), ()>( + // &(), // no public input + // nexus_sdk::KnownExitCodes::ExitSuccess as u32, + // &(), // no public output + // &path, // path to expected program binary + // &[] // no associated data, + // ).expect("failed to verify proof"); + + print!("Verifying execution..."); + + #[rustfmt::skip] + proof + .verify_expected::<(), ()>( + &(), // no public input + nexus_sdk::KnownExitCodes::ExitSuccess as u32, + &(), // no public output + &elf, // expected elf (program binary) + &[], // no associated data, + ) + .expect("failed to verify proof"); + + println!(" Succeeded!"); +}