Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ install_risc0:
@rzup install
@cargo risczero --version

install_jolt:
@echo "Installing Jolt from source"
@cargo install --git https://github.com/a16z/jolt jolt-cli

all: install

__EXAMPLES__:
Expand Down Expand Up @@ -105,6 +109,16 @@ prove_sp1_iseven:
prove_sp1_bubble_sort:
cargo run --release -p prooflab -- prove-sp1 examples/bubble_sort

# JOLT
prove_jolt_fibonacci:
cargo run --release -p prooflab -- prove-jolt examples/fibonacci

prove_jolt_is_even:
cargo run --release -p prooflab -- prove-jolt examples/is_even

prove_jolt_bubble_sort:
cargo run --release -p prooflab -- prove-jolt examples/bubble_sort

# Benchmark Commands
benchmark_sp1_fibonacci:
cargo run --release -p prooflab -- prove-sp1 examples/fibonacci --enable-telemetry
Expand Down
30 changes: 19 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# prooflab-rs

prooflab-rs is a CLI tool that simplifies developing zero-knowledge applications in Rust using zkVMs like SP1 or Risc0.
prooflab-rs is a CLI tool that simplifies developing zero-knowledge applications in Rust using zkVMs like SP1, Risc0, or Jolt.

## Project Structure

Expand Down Expand Up @@ -199,6 +199,11 @@ To generate a proof of your code's execution, run one of the following commands:
cargo run --release -- prove-risc0 <PROGRAM_DIRECTORY_PATH>
```

- **Using Jolt**:
```sh
cargo run --release -- prove-jolt <PROGRAM_DIRECTORY_PATH>
```

> **Note:** Aligned currently supports verification of [Risc0](https://dev.risczero.com/api/zkvm/quickstart#1-install-the-risc-zero-toolchain) proofs from release version `v1.0.1`.

### Submitting Proofs to Aligned
Expand Down Expand Up @@ -257,16 +262,18 @@ For help with prooflab-rs or questions about implementation, please join our [Te

After installing prooflab-rs, run any of the following example commands. You can choose either Risc0 or SP1 as your zkVM backend:

| Example | Risc0 | SP1 |
|---------|-------|-----|
| **Fibonacci** | `make prove_risc0_fibonacci` | `make prove_sp1_fibonacci` |
| **RSA** | `make prove_risc0_rsa` | `make prove_sp1_rsa` |
| **ECDSA** | `make prove_risc0_ecdsa` | `make prove_sp1_ecdsa` |
| **Blockchain State Diff** | `make prove_risc0_json` | `make prove_sp1_json` |
| **Regex** | `make prove_risc0_regex` | `make prove_sp1_regex` |
| **SHA256** | `make prove_risc0_sha` | `make prove_sp1_sha` |
| **Tendermint** | `make prove_risc0_tendermint` | `make prove_sp1_tendermint` |
| **ZK Quiz** | `make prove_risc0_zkquiz` | `make prove_sp1_zkquiz` |
| Example | Risc0 | SP1 | Jolt |
|---------|-------|-----|------|
| **Fibonacci** | `make prove_risc0_fibonacci` | `make prove_sp1_fibonacci` | `make prove_jolt_fibonacci` |
| **RSA** | `make prove_risc0_rsa` | `make prove_sp1_rsa` | - |
| **ECDSA** | `make prove_risc0_ecdsa` | `make prove_sp1_ecdsa` | - |
| **Blockchain State Diff** | `make prove_risc0_json` | `make prove_sp1_json` | - |
| **Regex** | `make prove_risc0_regex` | `make prove_sp1_regex` | - |
| **SHA256** | `make prove_risc0_sha` | `make prove_sp1_sha` | - |
| **Tendermint** | `make prove_risc0_tendermint` | `make prove_sp1_tendermint` | - |
| **ZK Quiz** | `make prove_risc0_zkquiz` | `make prove_sp1_zkquiz` | - |
| **Is Even** | - | `make prove_sp1_iseven` | `make prove_jolt_is_even` |
| **Bubble Sort** | `make prove_risc0_bubble_sort` | `make prove_sp1_bubble_sort` | `make prove_jolt_bubble_sort` |

## Acknowledgments

Expand All @@ -278,6 +285,7 @@ We extend our deepest gratitude to:

- The [RISC0](https://github.com/risc0/risc0) team for their pioneering work on RISC-V based zero-knowledge virtual machines
- The [SP1](https://github.com/succinctlabs/sp1) team for their innovative approach to high-performance zero-knowledge computation
- The [Jolt](https://github.com/a16z/jolt) team for their novel Rust-native zero-knowledge VM
- The entire zero-knowledge community for pushing the boundaries of what's possible with this transformative technology

ProofLab is committed to advancing the state of zero-knowledge application development by providing open tools, standardized metrics, and a collaborative platform for the broader ecosystem.
116 changes: 116 additions & 0 deletions crates/prooflab/src/jolt.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
use serde::{Deserialize, Serialize};
use std::{
fs,
io::{self, Write},
path::PathBuf,
process::{Command, ExitStatus},
time::Duration,
};

use crate::utils;

#[derive(Default, Serialize, Deserialize)]
pub struct JoltMetrics {
pub cycles: u64,
pub num_segments: usize,
pub core_proof_size: usize,
pub recursive_proof_size: usize,
pub core_prove_duration: Duration,
pub core_verify_duration: Duration,
pub compress_prove_duration: Duration,
pub compress_verify_duration: Duration,
}

/// Jolt workspace directories
pub const JOLT_SCRIPT_DIR: &str = "workspaces/jolt/script";
pub const JOLT_SRC_DIR: &str = "workspaces/jolt/program";
pub const JOLT_GUEST_MAIN: &str = "workspaces/jolt/program/src/lib.rs";
pub const JOLT_HOST_MAIN: &str = "workspaces/jolt/script/src/main.rs";
pub const JOLT_BASE_GUEST_CARGO_TOML: &str = "workspaces/base_files/jolt/cargo_guest";
pub const JOLT_BASE_HOST_CARGO_TOML: &str = "workspaces/base_files/jolt/cargo_host";
pub const JOLT_BASE_HOST: &str = "workspaces/base_files/jolt/host";
pub const JOLT_BASE_HOST_FILE: &str = "workspaces/base_files/jolt/host";
pub const JOLT_GUEST_CARGO_TOML: &str = "workspaces/jolt/program/Cargo.toml";

// Proof data generation paths
pub const JOLT_ELF_PATH: &str = "./proof_data/jolt/jolt.elf";
pub const JOLT_PROOF_PATH: &str = "./proof_data/jolt/jolt.proof";
pub const JOLT_PUB_INPUT_PATH: &str = "./proof_data/jolt/jolt.pub";
pub const JOLT_METRICS_PATH: &str = "./proof_data/jolt/jolt_metrics.json";

/// Jolt header added to programs for generating proofs of their execution
pub const JOLT_GUEST_PROGRAM_HEADER: &str = "#![cfg_attr(feature = \"guest\", no_std)]\n#![no_main]\n";

/// Jolt Cargo patch for optimization (if needed in the future)
pub const JOLT_ACCELERATION_IMPORT: &str = "\n[patch.crates-io]\n# Jolt-specific optimized crates would go here\n";

/// Jolt User I/O
// Host
pub const JOLT_HOST_WRITE: &str = "input";
pub const JOLT_HOST_READ: &str = "output";

// Guest
pub const JOLT_IO_READ: &str = "jolt::io::read();";
pub const JOLT_IO_COMMIT: &str = "jolt::io::commit";

pub fn prepare_host(
input: &str,
output: &str,
imports: &str,
host_dir: &PathBuf,
host_main: &PathBuf,
) -> io::Result<()> {
let mut host_program = imports.to_string();
let contents = fs::read_to_string(host_dir)?;

host_program.push_str(&contents);

// Insert input body
let host_program = host_program.replace(utils::HOST_INPUT, input);
// Insert output body
let host_program = host_program.replace(utils::HOST_OUTPUT, output);

// replace prooflab_io::write
let host_program = host_program.replace(utils::IO_WRITE, JOLT_HOST_WRITE);
// replace prooflab_io::out()
let host_program = host_program.replace(utils::IO_OUT, JOLT_HOST_READ);

// Write to host
let mut file = fs::File::create(host_main)?;
file.write_all(host_program.as_bytes())?;
Ok(())
}

/// Build the Jolt program
pub fn build_jolt_program(script_dir: &PathBuf) -> io::Result<ExitStatus> {
Command::new("cargo")
.arg("build")
.arg("--release")
.current_dir(script_dir)
.status()
}

/// Generates Jolt proof
pub fn generate_jolt_proof(
script_dir: &PathBuf,
current_dir: &PathBuf,
use_gpu: bool,
) -> io::Result<ExitStatus> {
let mut cmd = Command::new("cargo");
cmd.arg("run").arg("--release");

if use_gpu {
cmd.arg("--features").arg("gpu");
cmd.env("JOLT_GPU", "1");
}

cmd.arg("--")
.arg(current_dir)
.current_dir(script_dir)
.status()
}

pub fn read_metrics() -> io::Result<JoltMetrics> {
let metrics_str = fs::read_to_string(JOLT_METRICS_PATH)?;
serde_json::from_str(&metrics_str).map_err(|e| io::Error::new(io::ErrorKind::InvalidData, e))
}
8 changes: 8 additions & 0 deletions crates/prooflab/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,17 @@ use ethers::signers::LocalWallet;

pub mod risc0;
pub mod sp1;
pub mod jolt;
pub mod telemetry;
pub mod utils;

// Add Jolt to ProvingSystemId enum
// Note: This is a temporary solution. In a proper implementation,
// this would be added to the aligned_sdk crate.
impl ProvingSystemId {
pub const JOLT: Self = Self(2); // Assuming RISC0=0, SP1=1
}

// Make proof_data path optional
// Make keystore unneeded
#[derive(Args, Debug)]
Expand Down
Loading
Loading