fixed nullifier test

Restrict nullifier test to not include UTXO generation with Pedersen commitment.
This commit is contained in:
jonesmarvin8 2025-07-14 22:57:25 -04:00
parent b05e687e56
commit 73eef3bbdb
8 changed files with 188 additions and 13 deletions

4
risc0/nullifier_test/.gitignore vendored Normal file
View File

@ -0,0 +1,4 @@
.DS_Store
Cargo.lock
methods/guest/Cargo.lock
target/

View File

@ -0,0 +1,111 @@
# RISC Zero Rust Starter Template
Welcome to the RISC Zero Rust Starter Template! This template is intended to
give you a starting point for building a project using the RISC Zero zkVM.
Throughout the template (including in this README), you'll find comments
labelled `TODO` in places where you'll need to make changes. To better
understand the concepts behind this template, check out the [zkVM
Overview][zkvm-overview].
## Quick Start
First, make sure [rustup] is installed. The
[`rust-toolchain.toml`][rust-toolchain] file will be used by `cargo` to
automatically install the correct version.
To build all methods and execute the method within the zkVM, run the following
command:
```bash
cargo run
```
This is an empty template, and so there is no expected output (until you modify
the code).
### Executing the Project Locally in Development Mode
During development, faster iteration upon code changes can be achieved by leveraging [dev-mode], we strongly suggest activating it during your early development phase. Furthermore, you might want to get insights into the execution statistics of your project, and this can be achieved by specifying the environment variable `RUST_LOG="[executor]=info"` before running your project.
Put together, the command to run your project in development mode while getting execution statistics is:
```bash
RUST_LOG="[executor]=info" RISC0_DEV_MODE=1 cargo run
```
### Running Proofs Remotely on Bonsai
_Note: The Bonsai proving service is still in early Alpha; an API key is
required for access. [Click here to request access][bonsai access]._
If you have access to the URL and API key to Bonsai you can run your proofs
remotely. To prove in Bonsai mode, invoke `cargo run` with two additional
environment variables:
```bash
BONSAI_API_KEY="YOUR_API_KEY" BONSAI_API_URL="BONSAI_URL" cargo run
```
## How to Create a Project Based on This Template
Search this template for the string `TODO`, and make the necessary changes to
implement the required feature described by the `TODO` comment. Some of these
changes will be complex, and so we have a number of instructional resources to
assist you in learning how to write your own code for the RISC Zero zkVM:
- The [RISC Zero Developer Docs][dev-docs] is a great place to get started.
- Example projects are available in the [examples folder][examples] of
[`risc0`][risc0-repo] repository.
- Reference documentation is available at [https://docs.rs][docs.rs], including
[`risc0-zkvm`][risc0-zkvm], [`cargo-risczero`][cargo-risczero],
[`risc0-build`][risc0-build], and [others][crates].
## Directory Structure
It is possible to organize the files for these components in various ways.
However, in this starter template we use a standard directory structure for zkVM
applications, which we think is a good starting point for your applications.
```text
project_name
├── Cargo.toml
├── host
│ ├── Cargo.toml
│ └── src
│ └── main.rs <-- [Host code goes here]
└── methods
├── Cargo.toml
├── build.rs
├── guest
│ ├── Cargo.toml
│ └── src
│ └── method_name.rs <-- [Guest code goes here]
└── src
└── lib.rs
```
## Video Tutorial
For a walk-through of how to build with this template, check out this [excerpt
from our workshop at ZK HACK III][zkhack-iii].
## Questions, Feedback, and Collaborations
We'd love to hear from you on [Discord][discord] or [Twitter][twitter].
[bonsai access]: https://bonsai.xyz/apply
[cargo-risczero]: https://docs.rs/cargo-risczero
[crates]: https://github.com/risc0/risc0/blob/main/README.md#rust-binaries
[dev-docs]: https://dev.risczero.com
[dev-mode]: https://dev.risczero.com/api/generating-proofs/dev-mode
[discord]: https://discord.gg/risczero
[docs.rs]: https://docs.rs/releases/search?query=risc0
[examples]: https://github.com/risc0/risc0/tree/main/examples
[risc0-build]: https://docs.rs/risc0-build
[risc0-repo]: https://www.github.com/risc0/risc0
[risc0-zkvm]: https://docs.rs/risc0-zkvm
[rust-toolchain]: rust-toolchain.toml
[rustup]: https://rustup.rs
[twitter]: https://twitter.com/risczero
[zkhack-iii]: https://www.youtube.com/watch?v=Yg_BGqj_6lg&list=PLcPzhUaCxlCgig7ofeARMPwQ8vbuD6hC5&index=5
[zkvm-overview]: https://dev.risczero.com/zkvm

View File

@ -0,0 +1,10 @@
[package]
name = "host"
version = "0.1.0"
edition = "2021"
[dependencies]
methods = { path = "../methods" }
risc0-zkvm = { version = "^2.2.0" }
tracing-subscriber = { version = "0.3", features = ["env-filter"] }
serde = "1.0"

View File

@ -0,0 +1,56 @@
// These constants represent the RISC-V ELF and the image ID generated by risc0-build.
// The ELF is used for proving and the ID is used for verification.
use methods::{
GUEST_NULLIFIER_TEST_ELF, GUEST_NULLIFIER_TEST_ID
};
use risc0_zkvm::{default_prover, ExecutorEnv};
fn main() {
// Initialize tracing. In order to view logs, run `RUST_LOG=info cargo run`
tracing_subscriber::fmt()
.with_env_filter(tracing_subscriber::filter::EnvFilter::from_default_env())
.init();
// An executor environment describes the configurations for the zkVM
// including program inputs.
// A default ExecutorEnv can be created like so:
// `let env = ExecutorEnv::builder().build().unwrap();`
// However, this `env` does not have any inputs.
//
// To add guest input to the executor environment, use
// ExecutorEnvBuilder::write().
// To access this method, you'll need to use ExecutorEnv::builder(), which
// creates an ExecutorEnvBuilder. When you're done adding input, call
// ExecutorEnvBuilder::build().
// For example:
let input: u32 = 15 * u32::pow(2, 27) + 1;
let env = ExecutorEnv::builder()
.write(&input)
.unwrap()
.build()
.unwrap();
// Obtain the default prover.
let prover = default_prover();
// Proof information by proving the specified ELF binary.
// This struct contains the receipt along with statistics about execution of the guest
let prove_info = prover
.prove(env, GUEST_NULLIFIER_TEST_ELF)
.unwrap();
// extract the receipt.
let receipt = prove_info.receipt;
// TODO: Implement code for retrieving receipt journal here.
// For example:
let _output: u32 = receipt.journal.decode().unwrap();
// The receipt was verified at the end of proving, but the below code is an
// example of how someone else could verify this receipt.
receipt
.verify(GUEST_NULLIFIER_TEST_ID)
.unwrap();
}

View File

@ -4,7 +4,7 @@ version = "0.1.0"
edition = "2021"
[build-dependencies]
risc0-build = { version = "^2.1.2" }
risc0-build = { version = "^2.2.0" }
[package.metadata.risc0]
methods = ["guest"]

View File

@ -1,5 +1,5 @@
[package]
name = "nullifier_guest"
name = "guest_nullifier_test"
version = "0.1.0"
edition = "2021"

View File

@ -11,21 +11,11 @@ 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();
let rep_utxo = g1.to_bytes();
//Note: Fr here is ark_bn254's and not jubjub's...
let mut poseidon = light_poseidon::Poseidon::<Fr>::new_circom(2).unwrap();

View File

@ -0,0 +1,4 @@
[toolchain]
channel = "stable"
components = ["rustfmt", "rust-src"]
profile = "minimal"