From 210507f7d1c636c2430219830c4fd843329ea9f5 Mon Sep 17 00:00:00 2001 From: PatStiles Date: Wed, 16 Oct 2024 03:30:40 -0300 Subject: [PATCH 1/7] nits --- src/lib.rs | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 2185147..1d625c2 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -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; @@ -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; @@ -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| { @@ -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(), @@ -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) From ab814773de6c21d8b907de0b17350d5ac4f976e9 Mon Sep 17 00:00:00 2001 From: PatStiles Date: Wed, 16 Oct 2024 03:51:59 -0300 Subject: [PATCH 2/7] bump sdk version --- Cargo.lock | 12 +++++------- Cargo.toml | 2 +- 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 890bef6..1549ed1 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -73,7 +73,7 @@ dependencies = [ [[package]] name = "aligned-sdk" version = "0.1.0" -source = "git+https://github.com/yetanotherco/aligned_layer?tag=v0.8.0#042d8d8a9dfa736df2dd54436ab05e082f26c6d9" +source = "git+https://github.com/yetanotherco/aligned_layer?tag=v0.9.1#1608fc3a19f63bd14b512d362957504499ca22ad" dependencies = [ "ciborium", "dialoguer", @@ -3102,9 +3102,8 @@ dependencies = [ [[package]] name = "lambdaworks-crypto" -version = "0.7.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7fb5d4f22241504f7c7b8d2c3a7d7835d7c07117f10bff2a7d96a9ef6ef217c3" +version = "0.10.0" +source = "git+https://github.com/lambdaclass/lambdaworks.git?rev=efd46f0b0aea3aa95d94bba7de86cb96611b40d3#efd46f0b0aea3aa95d94bba7de86cb96611b40d3" dependencies = [ "lambdaworks-math", "serde", @@ -3114,9 +3113,8 @@ dependencies = [ [[package]] name = "lambdaworks-math" -version = "0.7.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "358e172628e713b80a530a59654154bfc45783a6ed70ea284839800cebdf8f97" +version = "0.10.0" +source = "git+https://github.com/lambdaclass/lambdaworks.git?rev=efd46f0b0aea3aa95d94bba7de86cb96611b40d3#efd46f0b0aea3aa95d94bba7de86cb96611b40d3" dependencies = [ "serde", "serde_json", diff --git a/Cargo.toml b/Cargo.toml index 2eb87f0..3d8ddc5 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -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", From 3277e2d56e9edcad206e1cd659a2955113f92acb Mon Sep 17 00:00:00 2001 From: PatStiles Date: Wed, 16 Oct 2024 03:58:53 -0300 Subject: [PATCH 3/7] make public inputs optional for sp1 even though they are not verified --- src/main.rs | 2 +- src/sp1.rs | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/src/main.rs b/src/main.rs index 682b041..9bef729 100644 --- a/src/main.rs +++ b/src/main.rs @@ -124,7 +124,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, ) diff --git a/src/sp1.rs b/src/sp1.rs index f55182e..71ecbac 100644 --- a/src/sp1.rs +++ b/src/sp1.rs @@ -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"; From 0673d5cd64b303300116aecdd93026380ffa70a5 Mon Sep 17 00:00:00 2001 From: PatStiles Date: Wed, 16 Oct 2024 04:37:10 -0300 Subject: [PATCH 4/7] write public inputs --- workspaces/base_files/sp1/host | 13 +++---------- workspaces/sp1/script/src/main.rs | 28 +++++++++++----------------- 2 files changed, 14 insertions(+), 27 deletions(-) diff --git a/workspaces/base_files/sp1/host b/workspaces/base_files/sp1/host index 05d3db2..1df4188 100644 --- a/workspaces/base_files/sp1/host +++ b/workspaces/base_files/sp1/host @@ -32,14 +32,7 @@ fn main() { let proof_data = bincode::serialize(&proof).expect("Failed to serialize proof"); std::fs::create_dir_all(¤t_dir.join("proof_data/sp1")).expect("Failed to create proof_data/sp1"); - let mut proof_file = File::create(¤t_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(¤t_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(¤t_dir.join("proof_data/sp1/sp1.proof"), &proof_data).expect("Failed to create SP1 proof file"); + std::fs::write(¤t_dir.join("proof_data/sp1/sp1.elf"), &METHOD_ELF).expect("failed to save SP1 elf file"); + std::fs::write(¤t_dir.join("proof_data/sp1/sp1.pub"), &proof.public_values).expect("failed to save SP1 public input"); } diff --git a/workspaces/sp1/script/src/main.rs b/workspaces/sp1/script/src/main.rs index 567e1c0..10eca2e 100644 --- a/workspaces/sp1/script/src/main.rs +++ b/workspaces/sp1/script/src/main.rs @@ -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 = std::env::args().collect(); + let current_dir = std::path::PathBuf::from(args[1].clone()); // Setup the logger. sp1_sdk::utils::setup_logger(); @@ -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(¤t_dir.join("proof_data/sp1")).expect("Failed to create proof_data/sp1"); + std::fs::write(¤t_dir.join("proof_data/sp1/sp1.proof"), &proof_data).expect("Failed to create SP1 proof file"); + std::fs::write(¤t_dir.join("../sp1.pub"), &proof.public_values).expect("failed to save SP1 public input"); + std::fs::write(¤t_dir.join("../sp1.elf"), &METHOD_ELF).expect("failed to save SP1 elf file"); } + From f548820e48c0b40de2f059b5dc1ce188c46e5183 Mon Sep 17 00:00:00 2001 From: PatStiles Date: Wed, 16 Oct 2024 04:37:26 -0300 Subject: [PATCH 5/7] define toolchain in sp1 workspace --- workspaces/sp1/rust-toolchain.toml | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 workspaces/sp1/rust-toolchain.toml diff --git a/workspaces/sp1/rust-toolchain.toml b/workspaces/sp1/rust-toolchain.toml new file mode 100644 index 0000000..114e32c --- /dev/null +++ b/workspaces/sp1/rust-toolchain.toml @@ -0,0 +1,4 @@ +[toolchain] +channel = "1.79.0" +components = ["llvm-tools", "rustc-dev"] + From 6bd2a00c31aa826cd1c14bf07898f799fd35fc14 Mon Sep 17 00:00:00 2001 From: PatStiles Date: Wed, 16 Oct 2024 04:38:06 -0300 Subject: [PATCH 6/7] add commands to call cargo prove build --- src/main.rs | 3 ++- src/sp1.rs | 13 ++++++++++++- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/src/main.rs b/src/main.rs index 9bef729..ccbc70f 100644 --- a/src/main.rs +++ b/src/main.rs @@ -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, ¤t_dir)?.success() { + let program_dir = home_dir.join(sp1::SP1_SRC_DIR); + if sp1::generate_sp1_proof(&script_dir, &program_dir, ¤t_dir)?.success() { info!("SP1 proof and ELF generated"); utils::replace( diff --git a/src/sp1.rs b/src/sp1.rs index 71ecbac..e3def51 100644 --- a/src/sp1.rs +++ b/src/sp1.rs @@ -67,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 { +pub fn generate_sp1_proof(script_dir: &PathBuf, program_dir: &PathBuf, current_dir: &PathBuf) -> io::Result { + // 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") From 2a3e72d2b608ec697a2a6f25d956c510b9a28bda Mon Sep 17 00:00:00 2001 From: PatStiles Date: Wed, 16 Oct 2024 04:39:15 -0300 Subject: [PATCH 7/7] update dependencies in workspace for reproducible builds --- src/utils.rs | 3 +++ workspaces/sp1/program/Cargo.toml | 3 +-- workspaces/sp1/script/Cargo.toml | 2 +- workspaces/sp1/script/build.rs | 8 ++++++-- 4 files changed, 11 insertions(+), 5 deletions(-) diff --git a/src/utils.rs b/src/utils.rs index db4ce3e..e0b3371 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -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(()) } diff --git a/workspaces/sp1/program/Cargo.toml b/workspaces/sp1/program/Cargo.toml index 31675c2..d547c8f 100644 --- a/workspaces/sp1/program/Cargo.toml +++ b/workspaces/sp1/program/Cargo.toml @@ -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" } diff --git a/workspaces/sp1/script/Cargo.toml b/workspaces/sp1/script/Cargo.toml index e961aa5..6ff4d08 100644 --- a/workspaces/sp1/script/Cargo.toml +++ b/workspaces/sp1/script/Cargo.toml @@ -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" } diff --git a/workspaces/sp1/script/build.rs b/workspaces/sp1/script/build.rs index 32b9927..c97648a 100644 --- a/workspaces/sp1/script/build.rs +++ b/workspaces/sp1/script/build.rs @@ -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); }