Skip to content
Draft
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
12 changes: 5 additions & 7 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ sp1-sdk = { git = "https://github.com/succinctlabs/sp1.git", tag = "v1.0.1" }
risc0-zkvm = { git = "https://github.com/risc0/risc0.git", tag = "v1.0.1" }

# Aligned SDK
aligned-sdk = { git = "https://github.com/yetanotherco/aligned_layer", tag = "v0.8.0" }
aligned-sdk = { git = "https://github.com/yetanotherco/aligned_layer", tag = "v0.9.2" }
ethers = { tag = "v2.0.15-fix-reconnections", features = [
"ws",
"rustls",
Expand Down
9 changes: 3 additions & 6 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
use aligned_sdk::communication::serialization::cbor_serialize;
use aligned_sdk::core::errors::{AlignedError, SubmitError};
use ethers::utils::format_units;
use log::{error, info};
use risc0::PUBLIC_INPUT_FILE_PATH;
use std::fs::File;
use std::io::Write;
use std::path::PathBuf;
Expand All @@ -20,7 +18,6 @@ use dialoguer::Confirm;
use ethers::prelude::*;
use ethers::providers::Http;
use ethers::signers::LocalWallet;
use ethers::types::U256;

pub mod risc0;
pub mod sp1;
Expand Down Expand Up @@ -166,7 +163,7 @@ pub async fn submit_proof_to_aligned(
if Confirm::with_theme(&dialoguer::theme::ColorfulTheme::default())
.with_prompt(format!(
"Would you like to deposit {:?} eth into Aligned to fund proof submission?",
estimated_fee
format_estimated_fee
))
.interact()
.map_err(|e| {
Expand All @@ -176,7 +173,7 @@ pub async fn submit_proof_to_aligned(
{
info!("Submitting deposit to Batcher");
let Ok(tx_receipt) =
deposit_to_aligned(U256::from(estimated_fee), signer, network).await
deposit_to_aligned(estimated_fee, signer, network).await
else {
return Err(SubmitError::GenericError(
"Failed to Deposit Funds into the Batcher".to_string(),
Expand Down Expand Up @@ -214,10 +211,10 @@ pub async fn submit_proof_to_aligned(
let verification_data = VerificationData {
proving_system: proof_system_id,
proof,
proof_generator_addr: wallet.address(),
vm_program_code: Some(elf_data),
verification_key: None,
pub_input: pub_input.clone(),
proof_generator_addr: wallet.address(),
};

let nonce = get_next_nonce(&args.rpc_url, wallet.address(), network)
Expand Down
5 changes: 3 additions & 2 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,8 @@ async fn main() -> io::Result<()> {
}

let script_dir = home_dir.join(sp1::SP1_SCRIPT_DIR);
if sp1::generate_sp1_proof(&script_dir, &current_dir)?.success() {
let program_dir = home_dir.join(sp1::SP1_SRC_DIR);
if sp1::generate_sp1_proof(&script_dir, &program_dir, &current_dir)?.success() {
info!("SP1 proof and ELF generated");

utils::replace(
Expand All @@ -124,7 +125,7 @@ async fn main() -> io::Result<()> {
submit_proof_to_aligned(
sp1::SP1_PROOF_PATH,
sp1::SP1_ELF_PATH,
None,
Some(sp1::SP1_PUB_INPUT_PATH),
args,
ProvingSystemId::SP1,
)
Expand Down
14 changes: 13 additions & 1 deletion src/sp1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ pub const SP1_GUEST_CARGO_TOML: &str = "workspaces/sp1/program/Cargo.toml";
// Proof data generation paths
pub const SP1_ELF_PATH: &str = "./proof_data/sp1/sp1.elf";
pub const SP1_PROOF_PATH: &str = "./proof_data/sp1/sp1.proof";
pub const SP1_PUB_INPUT_PATH: &str = "./proof_data/sp1/sp1.pub";

/// SP1 header added to programs for generating proofs of their execution
pub const SP1_GUEST_PROGRAM_HEADER: &str = "#![no_main]\nsp1_zkvm::entrypoint!(main);\n";
Expand Down Expand Up @@ -66,7 +67,18 @@ pub fn prepare_host(
}

/// Generates SP1 proof and ELF
pub fn generate_sp1_proof(script_dir: &PathBuf, current_dir: &PathBuf) -> io::Result<ExitStatus> {
pub fn generate_sp1_proof(script_dir: &PathBuf, program_dir: &PathBuf, current_dir: &PathBuf) -> io::Result<ExitStatus> {
// Generate the ELF in Docker
Command::new("cargo")
.arg("prove")
.arg("build")
.arg("--docker")
.arg("--tag")
.arg("v1.0.1")
.current_dir(program_dir)
.status()?;

// Generate the Proof
Command::new("cargo")
.arg("run")
.arg("--release")
Expand Down
3 changes: 3 additions & 0 deletions src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -416,5 +416,8 @@ pub fn prepare_guest(
// Write to guest
let mut file = fs::File::create(guest_main_file_path)?;
file.write_all(guest_program.as_bytes())?;

//Remove zk_rust_io import
crate::utils::remove_lines(guest_main_file_path, "use zk_rust_io;")?;
Ok(())
}
13 changes: 3 additions & 10 deletions workspaces/base_files/sp1/host
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,7 @@ fn main() {

let proof_data = bincode::serialize(&proof).expect("Failed to serialize proof");
std::fs::create_dir_all(&current_dir.join("proof_data/sp1")).expect("Failed to create proof_data/sp1");
let mut proof_file = File::create(&current_dir.join("proof_data/sp1/sp1.proof")).expect("Failed to create SP1 elf file");
proof_file
.write_all(&proof_data)
.expect("Failed write SP1 elf to file");

// Save elf
let mut elf_file = File::create(&current_dir.join("proof_data/sp1/sp1.elf")).expect("Failed to create SP1 elf file");
elf_file
.write_all(&METHOD_ELF)
.expect("Failed write SP1 elf to file");
std::fs::write(&current_dir.join("proof_data/sp1/sp1.proof"), &proof_data).expect("Failed to create SP1 proof file");
std::fs::write(&current_dir.join("proof_data/sp1/sp1.elf"), &METHOD_ELF).expect("failed to save SP1 elf file");
std::fs::write(&current_dir.join("proof_data/sp1/sp1.pub"), &proof.public_values).expect("failed to save SP1 public input");
}
3 changes: 1 addition & 2 deletions workspaces/sp1/program/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,4 @@ name = "method"
edition = "2021"

[dependencies]
sp1-zkvm = { git = "https://github.com/succinctlabs/sp1.git", tag = "v1.1.1" }
zk_rust_io = { git = "https://github.com/yetanotherco/zkRust.git", branch = "feat/v2" }
sp1-zkvm = { git = "https://github.com/succinctlabs/sp1.git", tag = "v1.0.1" }
4 changes: 4 additions & 0 deletions workspaces/sp1/rust-toolchain.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[toolchain]
channel = "1.79.0"
components = ["llvm-tools", "rustc-dev"]

2 changes: 1 addition & 1 deletion workspaces/sp1/script/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ name = "method"
edition = "2021"

[build-dependencies]
sp1-helper = "1.0.1"
sp1-build = "1.0.1"

[dependencies]
sp1-sdk = { git = "https://github.com/succinctlabs/sp1.git", tag = "v1.0.1" }
Expand Down
8 changes: 6 additions & 2 deletions workspaces/sp1/script/build.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
use sp1_helper::build_program;
use sp1_build::{build_program_with_args, BuildArgs};

fn main() {
build_program("../program")
let args = BuildArgs {
docker: true,
..Default::default()
};
build_program_with_args("../program", args);
}
28 changes: 11 additions & 17 deletions workspaces/sp1/script/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ use std::{fs::File, io::Write};
///
/// This file is generated by running `cargo prove build` inside the `program` directory.
pub const METHOD_ELF: &[u8] = include_bytes!("../../elf/riscv32im-succinct-zkvm-elf");
const SP1_ELF_PATH: &str = "../../../sp1.elf";
const SP1_PROOF_PATH: &str = "../../../sp1.proof";

fn main() {
let args: Vec<String> = std::env::args().collect();
let current_dir = std::path::PathBuf::from(args[1].clone());
// Setup the logger.
sp1_sdk::utils::setup_logger();

Expand All @@ -25,21 +25,15 @@ fn main() {
.run()
.expect("failed to generate proof");

// Verify the proof.
client.verify(&proof, &vk).expect("failed to verify proof");

// OUTPUT //

// Save proof.
let proof_data = bincode::serialize(&proof).expect("failed to serialize proof");
let mut proof_file = File::create(SP1_PROOF_PATH).expect("Failed to create sp1 elf file");
proof_file
.write_all(&proof_data)
.expect("failed write sp1 elf to file");

// Save elf
let mut elf_file = File::create(SP1_ELF_PATH).expect("Failed to create sp1 elf file");
elf_file
.write_all(&METHOD_ELF)
.expect("failed write sp1 elf to file");
// Verify the proof.
client.verify(&proof, &vk).expect("Failed to verify proof");

let proof_data = bincode::serialize(&proof).expect("Failed to serialize proof");
std::fs::create_dir_all(&current_dir.join("proof_data/sp1")).expect("Failed to create proof_data/sp1");
std::fs::write(&current_dir.join("proof_data/sp1/sp1.proof"), &proof_data).expect("Failed to create SP1 proof file");
std::fs::write(&current_dir.join("../sp1.pub"), &proof.public_values).expect("failed to save SP1 public input");
std::fs::write(&current_dir.join("../sp1.elf"), &METHOD_ELF).expect("failed to save SP1 elf file");
}