108 lines
3.5 KiB
Markdown
Raw Permalink Normal View History

2024-11-14 10:31:32 +01:00
# Workflow of the Storage Proof Circuits
This crate guides you through generating the circuit input,
2025-04-10 12:41:32 +02:00
building the circuit,
running the circuits to generate a proof, aggregating multiple proofs, and finally verify the proof.
2024-11-14 10:31:32 +01:00
This crate can be used to:
- Generate circuit input from **fake data** with given params.
2025-04-10 12:41:32 +02:00
- Build the Plonky2 codex storage proof circuits.
2024-11-14 10:31:32 +01:00
- Generate a proof with given proof input in JSON file.
- Aggregate multiple proofs with 2-to-1 tree like aggregation to generate a final proof (with optional compression).
- Wrapping proof with BN254 Poseidon Hash.
2024-11-14 10:31:32 +01:00
- Verify the proof.
- Wrap the proof with Gnark-plonky2-verifier to get a final succinct Groth16 proof.
2024-11-14 10:31:32 +01:00
## Usage
### Prerequisites
- **Rust Toolchain**: Ensure you have Rust installed. If not, install it from [rustup.rs](https://rustup.rs/).
- **Rust nightly**:: This crate requires the Rust nightly compiler. To install the nightly toolchain, use `rustup`:
```bash
rustup install nightly
```
To ensure that the nightly toolchain is used when building this crate, you can set the override in the project directory:
```bash
rustup override set nightly
```
- Go 1.22+ (for the GNARK-based verifier)
2025-07-03 13:36:11 +02:00
### Workflow
2024-11-14 10:31:32 +01:00
#### Step 1: Setting Up Parameters
- Input params: parameters for generating the circuit input can be defined in [`params.sh`](scripts/params.sh).
2024-11-14 10:31:32 +01:00
You can customize the test parameters by setting the following environment variables:
```bash
export MAXDEPTH=32 # Maximum depth of the slot tree
export MAXSLOTS=256 # Maximum number of slots
export CELLSIZE=2048 # Cell size in bytes
export BLOCKSIZE=65536 # Block size in bytes
2025-04-10 12:41:32 +02:00
export NSAMPLES=100 # Number of samples to prove
2024-11-14 10:31:32 +01:00
export ENTROPY=1234567 # External randomness
export SEED=12345 # Seed for creating fake data
export NSLOTS=11 # Number of slots in the dataset
export SLOTINDEX=3 # Which slot to prove (0..NSLOTS-1)
export NCELLS=512 # Number of cells in this slot
```
- Circuit parameters: Edit [`circ_params.sh`](./scripts/circ_params.sh) for:
2024-11-14 10:31:32 +01:00
```bash
export MAX_DEPTH=32 # maximum depth of the slot tree
export MAX_LOG2_N_SLOTS=8 # Depth of the dataset tree = ceiling_log2(max_slots)
export BLOCK_TREE_DEPTH=5 # depth of the mini tree (block tree)
export N_FIELD_ELEMS_PER_CELL=272 # number of field elements per cell
export N_SAMPLES=100 # number of samples to prove
2024-11-14 10:31:32 +01:00
export T=4 # number of proofs to aggregate
2024-11-14 10:31:32 +01:00
```
- GNARK-verifier params [`gnark_params.sh`](./scripts/gnark_params.sh):
2024-11-14 10:31:32 +01:00
```bash
export CIRCUIT_DIR="$BASE_DIR/../output/wrap/verifier_data"
export DATA_DIR="$BASE_DIR/../output/gnark_output"
export PROOF_SYSTEM="groth16"
export DUMMY="false"
2024-11-14 10:31:32 +01:00
```
#### Step 2: Run the Rust CLI
All steps are unified under [`run_cli.sh`](./scripts/run_cli.sh) By default, it will run nothing until you specify the operations.
2024-11-14 10:31:32 +01:00
```bash
# Show help and list all available flags
./scripts/run_cli.sh -h
# Generate inputs, build, prove, aggregate, wrap & verify—all in one:
./scripts/run_cli.sh --all
# Or pick individual operations:
./scripts/run_cli.sh \
--gen-input \
--build \
--prove \
--aggregate \
--wrap-tree \
--verify-tree
2024-11-14 10:31:32 +01:00
```
#### Step 3: Go/GNARK CLI workflow
To compile, prove, or verify wrapped Plonky2 circuits via GNARK, use:
2025-04-10 12:41:32 +02:00
```bash
./scripts/run_gnark_cli.sh -h
2025-04-10 12:41:32 +02:00
# run all steps (compile, prove, verify) with defaults:
./scripts/run_gnark_cli.sh
2024-11-14 10:31:32 +01:00
# or individually:
./scripts/run_gnark_cli.sh --compile
./scripts/run_gnark_cli.sh --prove
./scripts/run_gnark_cli.sh --verify
2025-03-10 14:49:13 +01:00
```