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
3 changes: 3 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ anyhow = "1.0.86"
hex = "0.4.3"
tokio = "1.38.0"

# Jolt
jolt = { package = "jolt-sdk", git = "https://github.com/a16z/jolt", features = ["host"] }

# Sp1
sp1-sdk = { git = "https://github.com/succinctlabs/sp1.git", tag = "v1.0.8-testnet" }

Expand Down
6 changes: 6 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,12 @@ install_sp1:
@cargo prove --version
@echo "Sp1 Toolchain Installed"

install_jolt:
@curl -L https://sp1.succinct.xyz | bash
@sp1up
@cargo prove --version
@echo "Jolt Toolchain Installed"

# Default target
all: instal

Expand Down
52 changes: 52 additions & 0 deletions src/jolt.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
use std::{fs, io::{self, Write}, process::Command};

use crate::utils;

pub const JOLT_PROOF_PATH: &str = "./jolt.proof";
pub const JOLT_ELF_PATH: &str = "./jolt.elf";
pub const JOLT_WORKSPACE_DIR: &str = "./workspaces/jolt";
pub const JOLT_SRC_DIR: &str = "./workspaces/jolt/guest/src";
pub const JOLT_GUEST_MAIN: &str = "./workspaces/jolt/guest/src/main.rs";

pub const JOLT_GUEST_CARGO_TOML: &str = "./workspaces/jolt/guest/Cargo.toml";
pub const JOLT_BASE_CARGO_TOML: &str = "./workspaces/base_files/jolt";

pub const JOLT_GUEST_PROGRAM_HEADER_STD: &str = "#![no_main]\n";
pub const JOLT_GUEST_PROC_MACRO: &str = "\n#[jolt::provable]\n";

//pub const JOLT_GUEST_DEPS: &str =
// "\njolt = { package = \"jolt-sdk\", git = \"https://github.com/a16z/jolt\", features = [\"guest-std\"] }";

pub fn prepare_jolt_guest() -> io::Result<()> {
/*
#![no_main]
*/
utils::prepend_to_file(JOLT_GUEST_MAIN, JOLT_GUEST_PROGRAM_HEADER_STD)?;

// Find and replace function name
let content = fs::read_to_string(JOLT_GUEST_MAIN).unwrap();

let modified_content = content.replace("main()", "method()");

/*
#[jolt::provable]
*/
let modified_content =
utils::add_before_substring(&modified_content, "fn method()", JOLT_GUEST_PROC_MACRO);

let mut file = fs::File::create(JOLT_GUEST_MAIN).unwrap();
file.write_all(modified_content.as_bytes()).unwrap();
Ok(())
}

pub fn generate_jolt_proof() -> io::Result<()> {
let guest_path = fs::canonicalize(JOLT_WORKSPACE_DIR)?;

Command::new("cargo")
.arg("run")
.arg("--release")
.current_dir(guest_path)
.status()
.unwrap();
Ok(())
}
1 change: 1 addition & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ use ethers::types::Address;

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

const BATCHER_URL: &str = "wss://batcher.alignedlayer.com";
Expand Down
33 changes: 33 additions & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use std::io;
use std::path::PathBuf;
use zkRust::risc0;
use zkRust::sp1;
use zkRust::jolt;
use zkRust::submit_proof_to_aligned;
use zkRust::utils;

Expand All @@ -22,6 +23,7 @@ enum Commands {
/// Adds files to myapp
ProveSp1(ProofArgs),
ProveRisc0(ProofArgs),
ProveJolt(ProofArgs),
}

#[derive(Args, Debug)]
Expand Down Expand Up @@ -96,6 +98,37 @@ fn main() -> io::Result<()> {
println!("Proof submitted and verified on aligned");
}

Ok(())
}
Commands::ProveJolt(args) => {
println!("Proving with Jolt, program in: {}", args.guest_path);

utils::prepare_workspace(
&args.guest_path,
jolt::JOLT_SRC_DIR,
jolt::JOLT_GUEST_CARGO_TOML,
jolt::JOLT_BASE_CARGO_TOML,
)?;

jolt::prepare_jolt_guest()?;
jolt::generate_jolt_proof()?;

println!("Proof and Proof Image generated!");

// Submit to aligned
if let Some(keystore_path) = args.submit_to_aligned_with_keystore.clone() {
submit_proof_to_aligned(
keystore_path,
jolt::JOLT_PROOF_PATH,
jolt::JOLT_ELF_PATH,
//TODO: Change this to Jolt when upstream change is made
ProvingSystemId::Risc0,
)
.unwrap();

println!("Proof submitted and verified on aligned");
}

Ok(())
}
}
Expand Down
12 changes: 12 additions & 0 deletions src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,18 @@ use std::{
path::Path,
};

pub fn add_before_substring(original_string: &str, substring: &str, text_to_add: &str) -> String {
if let Some(index) = original_string.find(substring) {
let mut modified_string = String::with_capacity(original_string.len() + text_to_add.len());
modified_string.push_str(&original_string[..index]);
modified_string.push_str(text_to_add);
modified_string.push_str(&original_string[index..]);
modified_string
} else {
original_string.to_string()
}
}

pub fn prepend_to_file(file_path: &str, text_to_prepend: &str) -> io::Result<()> {
// Open the file in read mode to read its existing content
let mut file = OpenOptions::new().read(true).write(true).open(file_path)?;
Expand Down
14 changes: 14 additions & 0 deletions workspaces/base_files/jolt
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
[package]
name = "guest"
version = "0.1.0"
edition = "2021"

[[bin]]
name = "guest"
path = "./src/lib.rs"

[features]
guest = []

[dependencies]
jolt = { package = "jolt-sdk", git = "https://github.com/a16z/jolt", features = ["guest-std"] }
1 change: 1 addition & 0 deletions workspaces/jolt/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
target
21 changes: 21 additions & 0 deletions workspaces/jolt/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
[package]
name = "jolt"
version = "0.1.0"
edition = "2021"

[workspace]
members = ["guest"]

[profile.release]
debug = 1
codegen-units = 1
lto = "fat"

[dependencies]
jolt = { package = "jolt-sdk", git = "https://github.com/a16z/jolt", features = ["host"] }
guest = { path = "./guest" }

[patch.crates-io]
ark-ff = { git = "https://github.com/a16z/arkworks-algebra", branch = "optimize/field-from-u64" }
ark-ec = { git = "https://github.com/a16z/arkworks-algebra", branch = "optimize/field-from-u64" }
ark-serialize = { git = "https://github.com/a16z/arkworks-algebra", branch = "optimize/field-from-u64" }
14 changes: 14 additions & 0 deletions workspaces/jolt/guest/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
[package]
name = "guest"
version = "0.1.0"
edition = "2021"

[[bin]]
name = "guest"
path = "./src/lib.rs"

[features]
guest = []

[dependencies]
jolt = { package = "jolt-sdk", git = "https://github.com/a16z/jolt" }
4 changes: 4 additions & 0 deletions workspaces/jolt/rust-toolchain.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[toolchain]
channel = "nightly-2024-04-20"
targets = ["riscv32i-unknown-none-elf"]

9 changes: 9 additions & 0 deletions workspaces/jolt/src/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
pub fn main() {
let (prove_fib, verify_fib) = guest::build_method();

let (output, proof) = prove_method(50);
let is_valid = verify_method(proof);

println!("output: {}", output);
println!("valid: {}", is_valid);
}