From 98d4fd2d2a3e4b499a661773c0b3b376a34fd116 Mon Sep 17 00:00:00 2001 From: jonesmarvin8 <83104039+jonesmarvin8@users.noreply.github.com> Date: Thu, 3 Jul 2025 22:04:32 -0400 Subject: [PATCH 1/3] pedersen tests nexus includes: bn254, pallas, vesta, jubjub, curve25519 --- nexus/ped_bls12-381_test/.gitignore | 1 + nexus/ped_bls12-381_test/Cargo.toml | 14 ++++ nexus/ped_bls12-381_test/rust-toolchain.toml | 2 + .../src/guest/.cargo/config.toml | 5 ++ nexus/ped_bls12-381_test/src/guest/Cargo.toml | 14 ++++ .../src/guest/rust-toolchain.toml | 2 + .../ped_bls12-381_test/src/guest/src/main.rs | 8 +++ nexus/ped_bls12-381_test/src/main.rs | 65 +++++++++++++++++++ nexus/ped_bn254_test/.gitignore | 1 + nexus/ped_bn254_test/Cargo.toml | 14 ++++ nexus/ped_bn254_test/rust-toolchain.toml | 2 + .../src/guest/.cargo/config.toml | 5 ++ nexus/ped_bn254_test/src/guest/Cargo.toml | 16 +++++ .../src/guest/rust-toolchain.toml | 2 + nexus/ped_bn254_test/src/guest/src/main.rs | 20 ++++++ nexus/ped_bn254_test/src/main.rs | 65 +++++++++++++++++++ nexus/ped_curve25519_test/.gitignore | 1 + nexus/ped_curve25519_test/Cargo.toml | 14 ++++ nexus/ped_curve25519_test/rust-toolchain.toml | 2 + .../src/guest/.cargo/config.toml | 5 ++ .../ped_curve25519_test/src/guest/Cargo.toml | 15 +++++ .../src/guest/rust-toolchain.toml | 2 + .../ped_curve25519_test/src/guest/src/main.rs | 29 +++++++++ nexus/ped_curve25519_test/src/main.rs | 65 +++++++++++++++++++ nexus/ped_jubjub_test/.gitignore | 1 + nexus/ped_jubjub_test/Cargo.toml | 14 ++++ nexus/ped_jubjub_test/rust-toolchain.toml | 2 + .../src/guest/.cargo/config.toml | 5 ++ nexus/ped_jubjub_test/src/guest/Cargo.toml | 15 +++++ .../src/guest/rust-toolchain.toml | 2 + nexus/ped_jubjub_test/src/guest/src/main.rs | 19 ++++++ nexus/ped_jubjub_test/src/main.rs | 65 +++++++++++++++++++ nexus/ped_pallas_test/.gitignore | 1 + nexus/ped_pallas_test/Cargo.toml | 14 ++++ nexus/ped_pallas_test/rust-toolchain.toml | 2 + .../src/guest/.cargo/config.toml | 5 ++ nexus/ped_pallas_test/src/guest/Cargo.toml | 15 +++++ .../src/guest/rust-toolchain.toml | 2 + nexus/ped_pallas_test/src/guest/src/main.rs | 19 ++++++ nexus/ped_pallas_test/src/main.rs | 65 +++++++++++++++++++ nexus/ped_secp256k1_test/.gitignore | 1 + nexus/ped_secp256k1_test/Cargo.toml | 14 ++++ nexus/ped_secp256k1_test/rust-toolchain.toml | 2 + .../src/guest/.cargo/config.toml | 5 ++ nexus/ped_secp256k1_test/src/guest/Cargo.toml | 14 ++++ .../src/guest/rust-toolchain.toml | 2 + .../ped_secp256k1_test/src/guest/src/main.rs | 21 ++++++ nexus/ped_secp256k1_test/src/main.rs | 65 +++++++++++++++++++ nexus/ped_vesta_test/.gitignore | 1 + nexus/ped_vesta_test/Cargo.toml | 14 ++++ nexus/ped_vesta_test/rust-toolchain.toml | 2 + .../src/guest/.cargo/config.toml | 5 ++ nexus/ped_vesta_test/src/guest/Cargo.toml | 14 ++++ .../src/guest/rust-toolchain.toml | 2 + nexus/ped_vesta_test/src/guest/src/main.rs | 19 ++++++ nexus/ped_vesta_test/src/main.rs | 65 +++++++++++++++++++ 56 files changed, 861 insertions(+) create mode 100644 nexus/ped_bls12-381_test/.gitignore create mode 100644 nexus/ped_bls12-381_test/Cargo.toml create mode 100644 nexus/ped_bls12-381_test/rust-toolchain.toml create mode 100644 nexus/ped_bls12-381_test/src/guest/.cargo/config.toml create mode 100644 nexus/ped_bls12-381_test/src/guest/Cargo.toml create mode 100644 nexus/ped_bls12-381_test/src/guest/rust-toolchain.toml create mode 100644 nexus/ped_bls12-381_test/src/guest/src/main.rs create mode 100644 nexus/ped_bls12-381_test/src/main.rs create mode 100644 nexus/ped_bn254_test/.gitignore create mode 100644 nexus/ped_bn254_test/Cargo.toml create mode 100644 nexus/ped_bn254_test/rust-toolchain.toml create mode 100644 nexus/ped_bn254_test/src/guest/.cargo/config.toml create mode 100644 nexus/ped_bn254_test/src/guest/Cargo.toml create mode 100644 nexus/ped_bn254_test/src/guest/rust-toolchain.toml create mode 100644 nexus/ped_bn254_test/src/guest/src/main.rs create mode 100644 nexus/ped_bn254_test/src/main.rs create mode 100644 nexus/ped_curve25519_test/.gitignore create mode 100644 nexus/ped_curve25519_test/Cargo.toml create mode 100644 nexus/ped_curve25519_test/rust-toolchain.toml create mode 100644 nexus/ped_curve25519_test/src/guest/.cargo/config.toml create mode 100644 nexus/ped_curve25519_test/src/guest/Cargo.toml create mode 100644 nexus/ped_curve25519_test/src/guest/rust-toolchain.toml create mode 100644 nexus/ped_curve25519_test/src/guest/src/main.rs create mode 100644 nexus/ped_curve25519_test/src/main.rs create mode 100644 nexus/ped_jubjub_test/.gitignore create mode 100644 nexus/ped_jubjub_test/Cargo.toml create mode 100644 nexus/ped_jubjub_test/rust-toolchain.toml create mode 100644 nexus/ped_jubjub_test/src/guest/.cargo/config.toml create mode 100644 nexus/ped_jubjub_test/src/guest/Cargo.toml create mode 100644 nexus/ped_jubjub_test/src/guest/rust-toolchain.toml create mode 100644 nexus/ped_jubjub_test/src/guest/src/main.rs create mode 100644 nexus/ped_jubjub_test/src/main.rs create mode 100644 nexus/ped_pallas_test/.gitignore create mode 100644 nexus/ped_pallas_test/Cargo.toml create mode 100644 nexus/ped_pallas_test/rust-toolchain.toml create mode 100644 nexus/ped_pallas_test/src/guest/.cargo/config.toml create mode 100644 nexus/ped_pallas_test/src/guest/Cargo.toml create mode 100644 nexus/ped_pallas_test/src/guest/rust-toolchain.toml create mode 100644 nexus/ped_pallas_test/src/guest/src/main.rs create mode 100644 nexus/ped_pallas_test/src/main.rs create mode 100644 nexus/ped_secp256k1_test/.gitignore create mode 100644 nexus/ped_secp256k1_test/Cargo.toml create mode 100644 nexus/ped_secp256k1_test/rust-toolchain.toml create mode 100644 nexus/ped_secp256k1_test/src/guest/.cargo/config.toml create mode 100644 nexus/ped_secp256k1_test/src/guest/Cargo.toml create mode 100644 nexus/ped_secp256k1_test/src/guest/rust-toolchain.toml create mode 100644 nexus/ped_secp256k1_test/src/guest/src/main.rs create mode 100644 nexus/ped_secp256k1_test/src/main.rs create mode 100644 nexus/ped_vesta_test/.gitignore create mode 100644 nexus/ped_vesta_test/Cargo.toml create mode 100644 nexus/ped_vesta_test/rust-toolchain.toml create mode 100644 nexus/ped_vesta_test/src/guest/.cargo/config.toml create mode 100644 nexus/ped_vesta_test/src/guest/Cargo.toml create mode 100644 nexus/ped_vesta_test/src/guest/rust-toolchain.toml create mode 100644 nexus/ped_vesta_test/src/guest/src/main.rs create mode 100644 nexus/ped_vesta_test/src/main.rs 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!"); +} From 909701eae4daba6c73fe29364db4b2fab029fcb8 Mon Sep 17 00:00:00 2001 From: jonesmarvin8 <83104039+jonesmarvin8@users.noreply.github.com> Date: Wed, 9 Jul 2025 12:00:57 -0400 Subject: [PATCH 2/3] fixes Fixes to jubjub, curve25519 and bls-12 381 tests --- .../ped_bls12-381_test/src/guest/src/main.rs | 8 -------- .../.gitignore | 0 .../Cargo.toml | 0 .../rust-toolchain.toml | 0 .../src/guest/.cargo/config.toml | 0 .../src/guest/Cargo.toml | 2 +- .../src/guest/rust-toolchain.toml | 0 .../ped_bls12_381_test/src/guest/src/main.rs | 20 +++++++++++++++++++ .../src/main.rs | 0 .../ped_curve25519_test/src/guest/src/main.rs | 3 --- nexus/ped_jubjub_test/src/guest/Cargo.toml | 1 + nexus/ped_jubjub_test/src/guest/src/main.rs | 2 +- nexus/ped_pallas_test/.gitignore | 1 - nexus/ped_pallas_test/src/guest/src/main.rs | 3 ++- 14 files changed, 25 insertions(+), 15 deletions(-) delete mode 100644 nexus/ped_bls12-381_test/src/guest/src/main.rs rename nexus/{ped_bls12-381_test => ped_bls12_381_test}/.gitignore (100%) rename nexus/{ped_bls12-381_test => ped_bls12_381_test}/Cargo.toml (100%) rename nexus/{ped_bls12-381_test => ped_bls12_381_test}/rust-toolchain.toml (100%) rename nexus/{ped_bls12-381_test => ped_bls12_381_test}/src/guest/.cargo/config.toml (100%) rename nexus/{ped_bls12-381_test => ped_bls12_381_test}/src/guest/Cargo.toml (94%) rename nexus/{ped_bls12-381_test => ped_bls12_381_test}/src/guest/rust-toolchain.toml (100%) create mode 100644 nexus/ped_bls12_381_test/src/guest/src/main.rs rename nexus/{ped_bls12-381_test => ped_bls12_381_test}/src/main.rs (100%) delete mode 100644 nexus/ped_pallas_test/.gitignore diff --git a/nexus/ped_bls12-381_test/src/guest/src/main.rs b/nexus/ped_bls12-381_test/src/guest/src/main.rs deleted file mode 100644 index 9a982df..0000000 --- a/nexus/ped_bls12-381_test/src/guest/src/main.rs +++ /dev/null @@ -1,8 +0,0 @@ -#![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/.gitignore b/nexus/ped_bls12_381_test/.gitignore similarity index 100% rename from nexus/ped_bls12-381_test/.gitignore rename to nexus/ped_bls12_381_test/.gitignore diff --git a/nexus/ped_bls12-381_test/Cargo.toml b/nexus/ped_bls12_381_test/Cargo.toml similarity index 100% rename from nexus/ped_bls12-381_test/Cargo.toml rename to nexus/ped_bls12_381_test/Cargo.toml diff --git a/nexus/ped_bls12-381_test/rust-toolchain.toml b/nexus/ped_bls12_381_test/rust-toolchain.toml similarity index 100% rename from nexus/ped_bls12-381_test/rust-toolchain.toml rename to nexus/ped_bls12_381_test/rust-toolchain.toml diff --git a/nexus/ped_bls12-381_test/src/guest/.cargo/config.toml b/nexus/ped_bls12_381_test/src/guest/.cargo/config.toml similarity index 100% rename from nexus/ped_bls12-381_test/src/guest/.cargo/config.toml rename to nexus/ped_bls12_381_test/src/guest/.cargo/config.toml diff --git a/nexus/ped_bls12-381_test/src/guest/Cargo.toml b/nexus/ped_bls12_381_test/src/guest/Cargo.toml similarity index 94% rename from nexus/ped_bls12-381_test/src/guest/Cargo.toml rename to nexus/ped_bls12_381_test/src/guest/Cargo.toml index da8c52d..f9357f4 100644 --- a/nexus/ped_bls12-381_test/src/guest/Cargo.toml +++ b/nexus/ped_bls12_381_test/src/guest/Cargo.toml @@ -6,7 +6,7 @@ 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"] } - +bls12_381 = "0.8.0" # Generated by cargo-nexus, do not remove! # [features] diff --git a/nexus/ped_bls12-381_test/src/guest/rust-toolchain.toml b/nexus/ped_bls12_381_test/src/guest/rust-toolchain.toml similarity index 100% rename from nexus/ped_bls12-381_test/src/guest/rust-toolchain.toml rename to nexus/ped_bls12_381_test/src/guest/rust-toolchain.toml 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..c89667a --- /dev/null +++ b/nexus/ped_bls12_381_test/src/guest/src/main.rs @@ -0,0 +1,20 @@ +#![cfg_attr(target_arch = "riscv32", no_std, no_main)] + +#[nexus_rt::main] +fn main() { + // TODO: do something with the input + let g1 = bls12_381::G1Affine::generator(); + let g1_proj = bls12_381::G1Projective::from(g1); + let g2 = g1_proj + g1; + let g3 = g1 + g2; + let g4 = g1 + g3; + let g5 = g1 + g4; + + let s1 = bls12_381::Scalar::from(87329482u64); + let s2 = bls12_381::Scalar::from(37264829u64); + let s3 = bls12_381::Scalar::from(98098098u64); + let s4 = bls12_381::Scalar::from(63980948u64); + let s5 = bls12_381::Scalar::from(15098098u64); + + let _ = s1*g1 + s2*g2 + s3*g3 + s4*g4 + s5*g5; +} diff --git a/nexus/ped_bls12-381_test/src/main.rs b/nexus/ped_bls12_381_test/src/main.rs similarity index 100% rename from nexus/ped_bls12-381_test/src/main.rs rename to nexus/ped_bls12_381_test/src/main.rs diff --git a/nexus/ped_curve25519_test/src/guest/src/main.rs b/nexus/ped_curve25519_test/src/guest/src/main.rs index 277e13f..2721c1c 100644 --- a/nexus/ped_curve25519_test/src/guest/src/main.rs +++ b/nexus/ped_curve25519_test/src/guest/src/main.rs @@ -7,9 +7,6 @@ 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); diff --git a/nexus/ped_jubjub_test/src/guest/Cargo.toml b/nexus/ped_jubjub_test/src/guest/Cargo.toml index 6292895..7619d7a 100644 --- a/nexus/ped_jubjub_test/src/guest/Cargo.toml +++ b/nexus/ped_jubjub_test/src/guest/Cargo.toml @@ -8,6 +8,7 @@ nexus-rt = { git = "https://github.com/nexus-xyz/nexus-zkvm.git", tag = "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] diff --git a/nexus/ped_jubjub_test/src/guest/src/main.rs b/nexus/ped_jubjub_test/src/guest/src/main.rs index 44f20b7..03a7494 100644 --- a/nexus/ped_jubjub_test/src/guest/src/main.rs +++ b/nexus/ped_jubjub_test/src/guest/src/main.rs @@ -8,7 +8,7 @@ fn main() { 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); diff --git a/nexus/ped_pallas_test/.gitignore b/nexus/ped_pallas_test/.gitignore deleted file mode 100644 index ea8c4bf..0000000 --- a/nexus/ped_pallas_test/.gitignore +++ /dev/null @@ -1 +0,0 @@ -/target diff --git a/nexus/ped_pallas_test/src/guest/src/main.rs b/nexus/ped_pallas_test/src/guest/src/main.rs index 8a3f49d..2017736 100644 --- a/nexus/ped_pallas_test/src/guest/src/main.rs +++ b/nexus/ped_pallas_test/src/guest/src/main.rs @@ -1,4 +1,5 @@ #![cfg_attr(target_arch = "riscv32", no_std, no_main)] + use pasta_curves::group::Group; #[nexus_rt::main] @@ -8,7 +9,7 @@ fn main() { 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); From be174dee80939018ab81ba49037e98cf00fa993a Mon Sep 17 00:00:00 2001 From: jonesmarvin8 <83104039+jonesmarvin8@users.noreply.github.com> Date: Wed, 9 Jul 2025 12:58:47 -0400 Subject: [PATCH 3/3] updates --- nexus/nullifier_test/Cargo.toml | 14 ++++ nexus/nullifier_test/rust-toolchain.toml | 2 + .../src/guest/.cargo/config.toml | 5 ++ nexus/nullifier_test/src/guest/Cargo.toml | 18 +++++ .../src/guest/rust-toolchain.toml | 2 + nexus/nullifier_test/src/guest/src/main.rs | 31 +++++++++ nexus/nullifier_test/src/main.rs | 65 +++++++++++++++++++ nexus/ped_vesta_test/src/guest/src/main.rs | 24 +++---- 8 files changed, 149 insertions(+), 12 deletions(-) create mode 100644 nexus/nullifier_test/Cargo.toml create mode 100644 nexus/nullifier_test/rust-toolchain.toml create mode 100644 nexus/nullifier_test/src/guest/.cargo/config.toml create mode 100644 nexus/nullifier_test/src/guest/Cargo.toml create mode 100644 nexus/nullifier_test/src/guest/rust-toolchain.toml create mode 100644 nexus/nullifier_test/src/guest/src/main.rs create mode 100644 nexus/nullifier_test/src/main.rs diff --git a/nexus/nullifier_test/Cargo.toml b/nexus/nullifier_test/Cargo.toml new file mode 100644 index 0000000..1ff8a81 --- /dev/null +++ b/nexus/nullifier_test/Cargo.toml @@ -0,0 +1,14 @@ +[package] +name = "nullifier_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/nullifier_test/rust-toolchain.toml b/nexus/nullifier_test/rust-toolchain.toml new file mode 100644 index 0000000..96e0415 --- /dev/null +++ b/nexus/nullifier_test/rust-toolchain.toml @@ -0,0 +1,2 @@ +[toolchain] +channel = "nightly-2025-04-06" diff --git a/nexus/nullifier_test/src/guest/.cargo/config.toml b/nexus/nullifier_test/src/guest/.cargo/config.toml new file mode 100644 index 0000000..80e2c50 --- /dev/null +++ b/nexus/nullifier_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/nullifier_test/src/guest/Cargo.toml b/nexus/nullifier_test/src/guest/Cargo.toml new file mode 100644 index 0000000..127cfc7 --- /dev/null +++ b/nexus/nullifier_test/src/guest/Cargo.toml @@ -0,0 +1,18 @@ +[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" +light-poseidon = "0.3.0" +ark-bn254 = "0.5.0" + +# Generated by cargo-nexus, do not remove! +# +[features] +cycles = [] # Enable cycle counting for run command + diff --git a/nexus/nullifier_test/src/guest/rust-toolchain.toml b/nexus/nullifier_test/src/guest/rust-toolchain.toml new file mode 100644 index 0000000..96e0415 --- /dev/null +++ b/nexus/nullifier_test/src/guest/rust-toolchain.toml @@ -0,0 +1,2 @@ +[toolchain] +channel = "nightly-2025-04-06" diff --git a/nexus/nullifier_test/src/guest/src/main.rs b/nexus/nullifier_test/src/guest/src/main.rs new file mode 100644 index 0000000..e7e9b22 --- /dev/null +++ b/nexus/nullifier_test/src/guest/src/main.rs @@ -0,0 +1,31 @@ +#![cfg_attr(target_arch = "riscv32", no_std, no_main)] +use group::{Group, GroupEncoding}; +use ark_bn254::Fr; +use light_poseidon::PoseidonBytesHasher; + + +#[nexus_rt::main] +fn main() { + // TODO: do something with the input + 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 utxo = g1*s1 + g2*s2 + g3*s3 + g4*s4 + g5*s5; + + let rep_nsk = s1.to_bytes(); + let rep_utxo = utxo.to_bytes(); + + //Note: Fr here is ark_bn254's and not jubjub's... + let mut poseidon = light_poseidon::Poseidon::::new_circom(2).unwrap(); + + let _ = poseidon.hash_bytes_le(&[&rep_utxo, &rep_nsk]); +} diff --git a/nexus/nullifier_test/src/main.rs b/nexus/nullifier_test/src/main.rs new file mode 100644 index 0000000..6ea72ac --- /dev/null +++ b/nexus/nullifier_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/src/guest/src/main.rs b/nexus/ped_vesta_test/src/guest/src/main.rs index b64f3f9..14418ad 100644 --- a/nexus/ped_vesta_test/src/guest/src/main.rs +++ b/nexus/ped_vesta_test/src/guest/src/main.rs @@ -1,19 +1,19 @@ #![cfg_attr(target_arch = "riscv32", no_std, no_main)] -use pasta_curves::group::Group; +//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 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 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; + // let _ = g1*s1 + g2*s2 + g3*s3 + g4*s4 + g5*s5; }