From e735708f9b2b1f6882aee8877c3e7f1dc78a92a9 Mon Sep 17 00:00:00 2001 From: Prajwol Gyawali Date: Fri, 29 Nov 2024 12:29:10 +0545 Subject: [PATCH 01/12] feat: create a new ProofReceipt type --- crates/zkvm/zkvm/src/proof.rs | 39 +++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/crates/zkvm/zkvm/src/proof.rs b/crates/zkvm/zkvm/src/proof.rs index 849b0b235..037366bcc 100644 --- a/crates/zkvm/zkvm/src/proof.rs +++ b/crates/zkvm/zkvm/src/proof.rs @@ -34,6 +34,45 @@ impl From<&Proof> for Vec { } } +#[derive( + Debug, Clone, Serialize, Deserialize, BorshSerialize, BorshDeserialize, PartialEq, Eq, Arbitrary, +)] +pub struct PublicValues(Vec); + +impl PublicValues { + pub fn new(data: Vec) -> Self { + Self(data) + } + + pub fn as_bytes(&self) -> &[u8] { + &self.0 + } + + pub fn is_empty(&self) -> bool { + self.0.is_empty() + } +} + +impl From for Vec { + fn from(value: PublicValues) -> Self { + value.0 + } +} + +impl From<&PublicValues> for Vec { + fn from(value: &PublicValues) -> Self { + value.0.clone() + } +} + +#[derive( + Debug, Clone, Serialize, Deserialize, BorshSerialize, BorshDeserialize, PartialEq, Eq, Arbitrary, +)] +pub struct ProofReceipt { + pub proof: Proof, + pub public_values: PublicValues, +} + /// Verification Key required to verify proof generated from `ZKVMHost` #[derive( Debug, From a2ee0c4da6bfdfe7eba5e8aa82514cf192f195ae Mon Sep 17 00:00:00 2001 From: Prajwol Gyawali Date: Fri, 29 Nov 2024 12:39:11 +0545 Subject: [PATCH 02/12] fix: update host and prover --- crates/zkvm/zkvm/src/host.rs | 30 +++++++++++------------------- crates/zkvm/zkvm/src/prover.rs | 14 +++++++------- 2 files changed, 18 insertions(+), 26 deletions(-) diff --git a/crates/zkvm/zkvm/src/host.rs b/crates/zkvm/zkvm/src/host.rs index 825006ca8..b5b94d168 100644 --- a/crates/zkvm/zkvm/src/host.rs +++ b/crates/zkvm/zkvm/src/host.rs @@ -1,9 +1,10 @@ use std::fmt::Display; -use borsh::BorshDeserialize; use serde::{de::DeserializeOwned, Serialize}; -use crate::{input::ZkVmInputBuilder, proof::Proof, ProofType, VerificationKey, ZkVmResult}; +use crate::{ + input::ZkVmInputBuilder, ProofReceipt, ProofType, PublicValues, VerificationKey, ZkVmResult, +}; /// A trait implemented by the prover ("host") of a zkVM program. pub trait ZkVmHost: Send + Sync + Clone + Display + 'static { @@ -14,26 +15,17 @@ pub trait ZkVmHost: Send + Sync + Clone + Display + 'static { &self, input: as ZkVmInputBuilder<'a>>::Input, proof_type: ProofType, - ) -> ZkVmResult<(Proof, VerificationKey)>; - - /// Extracts the raw public output from the given proof - fn extract_raw_public_output(proof: &Proof) -> ZkVmResult>; - - /// Extracts the public output from the given proof using standard `serde` - /// serialization/deserialization. - fn extract_serde_public_output(proof: &Proof) - -> ZkVmResult; - - /// Extracts the public output from the given proof assuming the data was serialized using - /// Borsh. - fn extract_borsh_public_output(proof: &Proof) -> ZkVmResult { - let raw = Self::extract_raw_public_output(proof)?; - borsh::from_slice(&raw).map_err(|e| e.into()) - } + ) -> ZkVmResult; /// Reuturns the Verification key for the loaded ELF program fn get_verification_key(&self) -> VerificationKey; + /// Extracts the public output from the public values using ZkVm's `serde` + /// serialization/deserialization. + fn extract_serde_public_output( + proof: &PublicValues, + ) -> ZkVmResult; + /// Verifies the proof generated by the prover against the `program_id`. - fn verify(&self, proof: &Proof) -> ZkVmResult<()>; + fn verify(&self, proof: &ProofReceipt) -> ZkVmResult<()>; } diff --git a/crates/zkvm/zkvm/src/prover.rs b/crates/zkvm/zkvm/src/prover.rs index cf164cd92..0fdaeccab 100644 --- a/crates/zkvm/zkvm/src/prover.rs +++ b/crates/zkvm/zkvm/src/prover.rs @@ -1,4 +1,6 @@ -use crate::{host::ZkVmHost, input::ZkVmInputBuilder, proof::Proof, ProofType, ZkVmError}; +use crate::{ + host::ZkVmHost, input::ZkVmInputBuilder, proof::Proof, ProofType, PublicValues, ZkVmError, +}; pub trait ZkVmProver { type Input; @@ -12,9 +14,7 @@ pub trait ZkVmProver { B: ZkVmInputBuilder<'a>; /// Processes the proof to produce the final output. - fn process_output(proof: &Proof, host: &H) -> Result - where - H: ZkVmHost; + fn process_output(proof: &PublicValues) -> Result; /// Proves the computation using any zkVM host. fn prove<'a, H>(input: &'a Self::Input, host: &H) -> Result<(Proof, Self::Output), ZkVmError> @@ -26,11 +26,11 @@ pub trait ZkVmProver { let zkvm_input = Self::prepare_input::>(input)?; // Use the host to prove. - let (proof, _) = host.prove(zkvm_input, Self::proof_type())?; + let proof = host.prove(zkvm_input, Self::proof_type())?; // Process and return the output using the verifier. - let output = Self::process_output(&proof, host)?; + let output = Self::process_output(&proof.public_values)?; - Ok((proof, output)) + Ok((proof.proof, output)) } } From c1df709ce9d918c7f35a8e372999d29f67691f90 Mon Sep 17 00:00:00 2001 From: Prajwol Gyawali Date: Fri, 29 Nov 2024 14:39:25 +0545 Subject: [PATCH 03/12] fix(risc0): use ProofReceipt --- crates/zkvm/adapters/risc0/src/host.rs | 64 +++++++++++--------------- 1 file changed, 27 insertions(+), 37 deletions(-) diff --git a/crates/zkvm/adapters/risc0/src/host.rs b/crates/zkvm/adapters/risc0/src/host.rs index 8e1ba62d9..e83f9f340 100644 --- a/crates/zkvm/adapters/risc0/src/host.rs +++ b/crates/zkvm/adapters/risc0/src/host.rs @@ -1,10 +1,13 @@ use std::fmt; use hex::encode; -use risc0_zkvm::{compute_image_id, default_prover, sha::Digest, ProverOpts, Receipt}; +use risc0_zkvm::{ + compute_image_id, default_prover, sha::Digest, InnerReceipt, Journal, ProverOpts, Receipt, +}; use serde::{de::DeserializeOwned, Serialize}; use strata_zkvm::{ - Proof, ProofType, VerificationKey, ZkVmError, ZkVmHost, ZkVmInputBuilder, ZkVmResult, + Proof, ProofReceipt, ProofType, PublicValues, VerificationKey, ZkVmError, ZkVmHost, + ZkVmInputBuilder, ZkVmResult, }; use crate::input::Risc0ProofInputBuilder; @@ -34,7 +37,7 @@ impl ZkVmHost for Risc0Host { &self, prover_input: as ZkVmInputBuilder<'a>>::Input, proof_type: ProofType, - ) -> ZkVmResult<(Proof, VerificationKey)> { + ) -> ZkVmResult { #[cfg(feature = "mock")] { std::env::set_var("RISC0_DEV_MODE", "true"); @@ -47,44 +50,28 @@ impl ZkVmHost for Risc0Host { ProofType::Groth16 => ProverOpts::groth16(), }; - // let prover = get_prover_server(&opts)?; let prover = default_prover(); - // Setup verification key - let program_id = - compute_image_id(&self.elf).map_err(|e| ZkVmError::InvalidELF(e.to_string()))?; - let verification_key = bincode::serialize(&program_id)?; - - // Generate the session - // let mut exec = ExecutorImpl::from_elf(prover_input, &self.elf)?; - // let session = exec.run()?; - // Generate the proof - // let ctx = VerifierContext::default(); - // let proof_info = prover.prove_session(&ctx, &session)?; let proof_info = prover .prove_with_opts(prover_input, &self.elf, &opts) .map_err(|e| ZkVmError::ProofGenerationError(e.to_string()))?; // Proof serialization - let serialized_proof = bincode::serialize(&proof_info.receipt)?; - Ok(( - Proof::new(serialized_proof), - VerificationKey::new(verification_key), - )) - } + let proof = Proof::new(bincode::serialize(&proof_info.receipt.inner)?); + let public_values = PublicValues::new(proof_info.receipt.journal.bytes); - fn extract_raw_public_output(proof: &Proof) -> ZkVmResult> { - let receipt: Receipt = bincode::deserialize(proof.as_bytes())?; - Ok(receipt.journal.bytes) + Ok(ProofReceipt { + proof, + public_values, + }) } fn extract_serde_public_output( - proof: &Proof, + proof: &PublicValues, ) -> ZkVmResult { - let receipt: Receipt = bincode::deserialize(proof.as_bytes())?; - receipt - .journal + let journal = Journal::new(proof.as_bytes().to_vec()); + journal .decode() .map_err(|e| ZkVmError::DeserializationError { source: strata_zkvm::DeserializationErrorSource::Serde(e.to_string()), @@ -95,8 +82,10 @@ impl ZkVmHost for Risc0Host { VerificationKey::new(self.id.as_bytes().to_vec()) } - fn verify(&self, proof: &Proof) -> ZkVmResult<()> { - let receipt: Receipt = bincode::deserialize(proof.as_bytes())?; + fn verify(&self, proof: &ProofReceipt) -> ZkVmResult<()> { + let journal = proof.public_values.as_bytes().to_vec(); + let inner: InnerReceipt = bincode::deserialize(proof.proof.as_bytes())?; + let receipt = Receipt::new(inner, journal); receipt .verify(self.id) .map_err(|e| ZkVmError::ProofVerificationError(e.to_string()))?; @@ -136,7 +125,7 @@ mod tests { let zkvm_input = zkvm_input_builder.build().unwrap(); // assert proof generation works - let (proof, _) = host + let proof = host .prove(zkvm_input, ProofType::Core) .expect("Failed to generate proof"); @@ -144,7 +133,7 @@ mod tests { host.verify(&proof).expect("Proof verification failed"); // assert public outputs extraction from proof works - let out: u32 = Risc0Host::extract_serde_public_output(&proof) + let out: u32 = Risc0Host::extract_serde_public_output(&proof.public_values) .expect("Failed to extract public outputs"); assert_eq!(input, out) } @@ -160,7 +149,7 @@ mod tests { let zkvm_input = zkvm_input_builder.build().unwrap(); // assert proof generation works - let (proof, _) = zkvm + let proof = zkvm .prove(zkvm_input, ProofType::Core) .expect("Failed to generate proof"); @@ -168,7 +157,7 @@ mod tests { zkvm.verify(&proof).expect("Proof verification failed"); // assert public outputs extraction from proof works - let out: u32 = Risc0Host::extract_serde_public_output(&proof).expect( + let out: u32 = Risc0Host::extract_serde_public_output(&proof.public_values).expect( "Failed to extract public outputs", ); @@ -195,7 +184,7 @@ outputs", .unwrap(); // assert proof generation works - let (proof, vk) = zkvm + let proof = zkvm .prove(zkvm_input, ProofType::Groth16) .expect("Failed to generate proof"); @@ -206,8 +195,9 @@ outputs", let filename = "proof-groth16.bin"; let mut file = File::create(filename).unwrap(); - file.write_all(proof.as_bytes()).unwrap(); + file.write_all(&bincode::serialize(&proof).expect("bincode serialization")) + .unwrap(); - assert_eq!(vk.as_bytes(), expected_vk); + assert_eq!(zkvm.get_verification_key().as_bytes(), expected_vk); } } From 2f38c06f1f866d9409f1b5dc8c002b27490da329 Mon Sep 17 00:00:00 2001 From: Prajwol Gyawali Date: Fri, 29 Nov 2024 14:56:59 +0545 Subject: [PATCH 04/12] fix(sp1): use ProofReceipt --- crates/zkvm/adapters/risc0/src/host.rs | 2 +- crates/zkvm/adapters/sp1/src/host.rs | 76 +++++++++++--------------- crates/zkvm/zkvm/src/host.rs | 11 +++- crates/zkvm/zkvm/src/prover.rs | 8 ++- 4 files changed, 49 insertions(+), 48 deletions(-) diff --git a/crates/zkvm/adapters/risc0/src/host.rs b/crates/zkvm/adapters/risc0/src/host.rs index e83f9f340..cc4bd9952 100644 --- a/crates/zkvm/adapters/risc0/src/host.rs +++ b/crates/zkvm/adapters/risc0/src/host.rs @@ -195,7 +195,7 @@ outputs", let filename = "proof-groth16.bin"; let mut file = File::create(filename).unwrap(); - file.write_all(&bincode::serialize(&proof).expect("bincode serialization")) + file.write_all(&bincode::serialize(&proof).expect("bincode serialization failed")) .unwrap(); assert_eq!(zkvm.get_verification_key().as_bytes(), expected_vk); diff --git a/crates/zkvm/adapters/sp1/src/host.rs b/crates/zkvm/adapters/sp1/src/host.rs index 8d59a72ea..fbb93e63b 100644 --- a/crates/zkvm/adapters/sp1/src/host.rs +++ b/crates/zkvm/adapters/sp1/src/host.rs @@ -2,10 +2,12 @@ use std::fmt; use serde::{de::DeserializeOwned, Serialize}; use sp1_sdk::{ - HashableKey, ProverClient, SP1ProofWithPublicValues, SP1ProvingKey, SP1VerifyingKey, + HashableKey, ProverClient, SP1Proof, SP1ProofWithPublicValues, SP1ProvingKey, SP1PublicValues, + SP1Stdin, SP1VerifyingKey, }; use strata_zkvm::{ - Proof, ProofType, VerificationKey, ZkVmError, ZkVmHost, ZkVmInputBuilder, ZkVmResult, + Proof, ProofReceipt, ProofType, PublicValues, VerificationKey, ZkVmError, ZkVmHost, + ZkVmInputBuilder, ZkVmResult, }; use crate::input::SP1ProofInputBuilder; @@ -58,7 +60,7 @@ impl ZkVmHost for SP1Host { &self, prover_input: as ZkVmInputBuilder<'a>>::Input, proof_type: ProofType, - ) -> ZkVmResult<(Proof, VerificationKey)> { + ) -> ZkVmResult { #[cfg(feature = "mock")] { std::env::set_var("SP1_PROVER", "mock"); @@ -75,23 +77,22 @@ impl ZkVmHost for SP1Host { ProofType::Groth16 => prover.groth16(), }; - let proof = prover + let proof_info = prover .run() .map_err(|e| ZkVmError::ProofGenerationError(e.to_string()))?; // Proof serialization - let serialized_proof = bincode::serialize(&proof)?; + let proof = Proof::new(bincode::serialize(&proof_info.proof)?); + let public_values = PublicValues::new(proof_info.public_values.to_vec()); - Ok((Proof::new(serialized_proof), self.get_verification_key())) - } - - fn extract_raw_public_output(proof: &Proof) -> Result, ZkVmError> { - let proof: SP1ProofWithPublicValues = bincode::deserialize(proof.as_bytes())?; - Ok(proof.public_values.as_slice().to_vec()) + Ok(ProofReceipt { + proof, + public_values, + }) } fn extract_serde_public_output( - proof: &Proof, + proof: &PublicValues, ) -> ZkVmResult { let mut proof: SP1ProofWithPublicValues = bincode::deserialize(proof.as_bytes())?; let public_params: T = proof.public_values.read(); @@ -103,12 +104,20 @@ impl ZkVmHost for SP1Host { VerificationKey::new(verification_key) } - fn verify(&self, proof: &Proof) -> ZkVmResult<()> { - let proof: SP1ProofWithPublicValues = bincode::deserialize(proof.as_bytes())?; + fn verify(&self, proof: &ProofReceipt) -> ZkVmResult<()> { + let public_values = SP1PublicValues::from(proof.public_values.as_bytes()); + let proof: SP1Proof = bincode::deserialize(proof.proof.as_bytes())?; + let sp1_version = sp1_sdk::SP1_CIRCUIT_VERSION.to_string(); + let proof_with_public_values = SP1ProofWithPublicValues { + proof, + public_values, + stdin: SP1Stdin::default(), + sp1_version, + }; let client = ProverClient::new(); client - .verify(&proof, &self.verifying_key) + .verify(&proof_with_public_values, &self.verifying_key) .map_err(|e| ZkVmError::ProofVerificationError(e.to_string()))?; Ok(()) @@ -128,11 +137,10 @@ mod tests { use std::{fs::File, io::Write}; - use sp1_sdk::{HashableKey, SP1VerifyingKey}; + use sp1_sdk::HashableKey; use strata_zkvm::{ProofType, ZkVmHost}; use super::*; - use crate::SP1Verifier; // Adding compiled guest code `TEST_ELF` to save the build time // #![no_main] @@ -148,12 +156,12 @@ mod tests { let input: u32 = 1; let mut prover_input_builder = SP1ProofInputBuilder::new(); - prover_input_builder.write(&input).unwrap(); + prover_input_builder.write_serde(&input).unwrap(); let prover_input = prover_input_builder.build().unwrap(); // assert proof generation works let zkvm = SP1Host::init(TEST_ELF); - let (proof, _) = zkvm + let proof = zkvm .prove(prover_input, ProofType::Core) .expect("Failed to generate proof"); @@ -161,30 +169,13 @@ mod tests { zkvm.verify(&proof).expect("Proof verification failed"); // assert public outputs extraction from proof works - let out: u32 = SP1Verifier::extract_public_output(&proof).expect( + let out: u32 = SP1Host::extract_serde_public_output(&proof.public_values).expect( "Failed to extract public outputs", ); assert_eq!(input, out) } - #[test] - fn test_mock_prover_with_public_param() { - let input: u32 = 1; - - let mut prover_input_builder = SP1ProofInputBuilder::new(); - prover_input_builder.write(&input).unwrap(); - let prover_input = prover_input_builder.build().unwrap(); - - // assert proof generation works - let zkvm = SP1Host::init(TEST_ELF.to_vec(), ProverOptions::default()); - let (proof, vk) = zkvm.prove(prover_input).expect("Failed to generate proof"); - - // assert proof verification works - SP1Verifier::verify_with_public_params(&vk, input, &proof) - .expect("Proof verification failed"); - } - #[test] fn test_groth16_proof_generation() { sp1_sdk::utils::setup_logger(); @@ -192,7 +183,7 @@ mod tests { let input: u32 = 1; let prover_input = SP1ProofInputBuilder::new() - .write(&input) + .write_serde(&input) .unwrap() .build() .unwrap(); @@ -200,20 +191,19 @@ mod tests { let zkvm = SP1Host::init(TEST_ELF); // assert proof generation works - let (proof, vk) = zkvm + let proof = zkvm .prove(prover_input, ProofType::Groth16) .expect("Failed to generate proof"); - let vk: SP1VerifyingKey = bincode::deserialize(vk.as_bytes()).unwrap(); - // Note: For the fixed ELF and fixed SP1 version, the vk is fixed assert_eq!( - vk.bytes32(), + zkvm.verifying_key.bytes32(), "0x00efb1120491119751e75bc55bc95b64d33f973ecf68fcf5cbff08506c5788f9" ); let filename = "proof-groth16.bin"; let mut file = File::create(filename).unwrap(); - file.write_all(proof.as_bytes()).unwrap(); + file.write_all(&bincode::serialize(&proof).expect("bincode serialization failed")) + .unwrap(); } } diff --git a/crates/zkvm/zkvm/src/host.rs b/crates/zkvm/zkvm/src/host.rs index b5b94d168..64b35201c 100644 --- a/crates/zkvm/zkvm/src/host.rs +++ b/crates/zkvm/zkvm/src/host.rs @@ -1,5 +1,6 @@ use std::fmt::Display; +use borsh::BorshDeserialize; use serde::{de::DeserializeOwned, Serialize}; use crate::{ @@ -23,9 +24,17 @@ pub trait ZkVmHost: Send + Sync + Clone + Display + 'static { /// Extracts the public output from the public values using ZkVm's `serde` /// serialization/deserialization. fn extract_serde_public_output( - proof: &PublicValues, + public_values: &PublicValues, ) -> ZkVmResult; + /// Extracts the public output from the given proof assuming the data was serialized using + /// Borsh. + fn extract_borsh_public_output( + public_values: &PublicValues, + ) -> ZkVmResult { + borsh::from_slice(public_values.as_bytes()).map_err(|e| e.into()) + } + /// Verifies the proof generated by the prover against the `program_id`. fn verify(&self, proof: &ProofReceipt) -> ZkVmResult<()>; } diff --git a/crates/zkvm/zkvm/src/prover.rs b/crates/zkvm/zkvm/src/prover.rs index 0fdaeccab..6b8c6d196 100644 --- a/crates/zkvm/zkvm/src/prover.rs +++ b/crates/zkvm/zkvm/src/prover.rs @@ -13,8 +13,10 @@ pub trait ZkVmProver { where B: ZkVmInputBuilder<'a>; - /// Processes the proof to produce the final output. - fn process_output(proof: &PublicValues) -> Result; + /// Processes the [`PublicValues`] to produce the final output. + fn process_output(public_values: &PublicValues) -> Result + where + H: ZkVmHost; /// Proves the computation using any zkVM host. fn prove<'a, H>(input: &'a Self::Input, host: &H) -> Result<(Proof, Self::Output), ZkVmError> @@ -29,7 +31,7 @@ pub trait ZkVmProver { let proof = host.prove(zkvm_input, Self::proof_type())?; // Process and return the output using the verifier. - let output = Self::process_output(&proof.public_values)?; + let output = Self::process_output::(&proof.public_values)?; Ok((proof.proof, output)) } From 5609e3f69d81340718264031413ba4063f87fa70 Mon Sep 17 00:00:00 2001 From: Prajwol Gyawali Date: Fri, 29 Nov 2024 15:11:25 +0545 Subject: [PATCH 05/12] fix: update proof-impls --- crates/proof-impl/btc-blockspace/src/prover.rs | 6 +++--- crates/proof-impl/checkpoint/src/prover.rs | 6 +++--- crates/proof-impl/cl-agg/src/prover.rs | 6 +++--- crates/proof-impl/cl-stf/src/prover.rs | 6 +++--- crates/proof-impl/evm-ee-stf/src/prover.rs | 6 +++--- crates/proof-impl/l1-batch/src/prover.rs | 6 +++--- 6 files changed, 18 insertions(+), 18 deletions(-) diff --git a/crates/proof-impl/btc-blockspace/src/prover.rs b/crates/proof-impl/btc-blockspace/src/prover.rs index 8ba86f995..973428123 100644 --- a/crates/proof-impl/btc-blockspace/src/prover.rs +++ b/crates/proof-impl/btc-blockspace/src/prover.rs @@ -1,5 +1,5 @@ use bitcoin::consensus::serialize; -use strata_zkvm::{Proof, ProofType, ZkVmHost, ZkVmInputBuilder, ZkVmProver, ZkVmResult}; +use strata_zkvm::{ProofType, PublicValues, ZkVmHost, ZkVmInputBuilder, ZkVmProver, ZkVmResult}; use crate::logic::{BlockspaceProofInput, BlockspaceProofOutput}; @@ -27,10 +27,10 @@ impl ZkVmProver for BtcBlockspaceProver { Ok(zkvm_input) } - fn process_output(proof: &Proof, _host: &H) -> ZkVmResult + fn process_output(public_values: &PublicValues) -> ZkVmResult where H: ZkVmHost, { - H::extract_borsh_public_output(proof) + H::extract_borsh_public_output(public_values) } } diff --git a/crates/proof-impl/checkpoint/src/prover.rs b/crates/proof-impl/checkpoint/src/prover.rs index a2c987168..1ea94d02f 100644 --- a/crates/proof-impl/checkpoint/src/prover.rs +++ b/crates/proof-impl/checkpoint/src/prover.rs @@ -1,7 +1,7 @@ use strata_primitives::params::RollupParams; use strata_proofimpl_cl_stf::L2BatchProofOutput; use strata_proofimpl_l1_batch::L1BatchProofOutput; -use strata_zkvm::{AggregationInput, Proof, VerificationKey, ZkVmProver, ZkVmResult}; +use strata_zkvm::{AggregationInput, Proof, PublicValues, VerificationKey, ZkVmProver, ZkVmResult}; use crate::CheckpointProofOutput; @@ -40,10 +40,10 @@ impl ZkVmProver for CheckpointProver { .build() } - fn process_output(proof: &Proof, _host: &H) -> ZkVmResult + fn process_output(public_values: &PublicValues) -> ZkVmResult where H: strata_zkvm::ZkVmHost, { - H::extract_borsh_public_output(proof) + H::extract_borsh_public_output(public_values) } } diff --git a/crates/proof-impl/cl-agg/src/prover.rs b/crates/proof-impl/cl-agg/src/prover.rs index d47cd37ce..5226da7dd 100644 --- a/crates/proof-impl/cl-agg/src/prover.rs +++ b/crates/proof-impl/cl-agg/src/prover.rs @@ -1,5 +1,5 @@ use strata_proofimpl_cl_stf::L2BatchProofOutput; -use strata_zkvm::{AggregationInput, Proof, VerificationKey, ZkVmProver, ZkVmResult}; +use strata_zkvm::{AggregationInput, Proof, PublicValues, VerificationKey, ZkVmProver, ZkVmResult}; pub struct ClAggInput { pub batch: Vec<(Proof, L2BatchProofOutput)>, @@ -34,10 +34,10 @@ impl ZkVmProver for ClAggProver { input_builder.build() } - fn process_output(proof: &Proof, _host: &H) -> ZkVmResult + fn process_output(public_values: &PublicValues) -> ZkVmResult where H: strata_zkvm::ZkVmHost, { - H::extract_borsh_public_output(proof) + H::extract_borsh_public_output(public_values) } } diff --git a/crates/proof-impl/cl-stf/src/prover.rs b/crates/proof-impl/cl-stf/src/prover.rs index f9c9296d4..0aa0300c6 100644 --- a/crates/proof-impl/cl-stf/src/prover.rs +++ b/crates/proof-impl/cl-stf/src/prover.rs @@ -1,6 +1,6 @@ use strata_primitives::params::RollupParams; use strata_state::{block::L2Block, chain_state::Chainstate}; -use strata_zkvm::{AggregationInput, Proof, VerificationKey, ZkVmProver, ZkVmResult}; +use strata_zkvm::{AggregationInput, Proof, PublicValues, VerificationKey, ZkVmProver, ZkVmResult}; use crate::L2BatchProofOutput; @@ -36,10 +36,10 @@ impl ZkVmProver for ClStfProver { .build() } - fn process_output(proof: &Proof, _host: &H) -> ZkVmResult + fn process_output(public_values: &PublicValues) -> ZkVmResult where H: strata_zkvm::ZkVmHost, { - H::extract_borsh_public_output(proof) + H::extract_borsh_public_output(public_values) } } diff --git a/crates/proof-impl/evm-ee-stf/src/prover.rs b/crates/proof-impl/evm-ee-stf/src/prover.rs index 81883a8ec..3bd6e8f52 100644 --- a/crates/proof-impl/evm-ee-stf/src/prover.rs +++ b/crates/proof-impl/evm-ee-stf/src/prover.rs @@ -1,4 +1,4 @@ -use strata_zkvm::{ProofType, ZkVmProver, ZkVmResult}; +use strata_zkvm::{ProofType, PublicValues, ZkVmProver, ZkVmResult}; use crate::{ELProofInput, ELProofPublicParams}; @@ -19,10 +19,10 @@ impl ZkVmProver for EvmEeProver { B::new().write_serde(input)?.build() } - fn process_output(proof: &strata_zkvm::Proof, _host: &H) -> ZkVmResult + fn process_output(public_values: &PublicValues) -> ZkVmResult where H: strata_zkvm::ZkVmHost, { - H::extract_serde_public_output(proof) + H::extract_serde_public_output(public_values) } } diff --git a/crates/proof-impl/l1-batch/src/prover.rs b/crates/proof-impl/l1-batch/src/prover.rs index d637df7f8..7acabedfa 100644 --- a/crates/proof-impl/l1-batch/src/prover.rs +++ b/crates/proof-impl/l1-batch/src/prover.rs @@ -1,7 +1,7 @@ use borsh::{BorshDeserialize, BorshSerialize}; use strata_proofimpl_btc_blockspace::logic::BlockspaceProofOutput; use strata_state::l1::HeaderVerificationState; -use strata_zkvm::{AggregationInput, Proof, VerificationKey, ZkVmProver, ZkVmResult}; +use strata_zkvm::{AggregationInput, Proof, PublicValues, VerificationKey, ZkVmProver, ZkVmResult}; use crate::logic::L1BatchProofOutput; @@ -42,10 +42,10 @@ impl ZkVmProver for L1BatchProver { input_builder.build() } - fn process_output(proof: &Proof, _host: &H) -> ZkVmResult + fn process_output(public_values: &PublicValues) -> ZkVmResult where H: strata_zkvm::ZkVmHost, { - H::extract_borsh_public_output(proof) + H::extract_borsh_public_output(public_values) } } From ab6a9fca944da4e61c73251888a3d83a2359173a Mon Sep 17 00:00:00 2001 From: Prajwol Gyawali Date: Fri, 29 Nov 2024 15:46:06 +0545 Subject: [PATCH 06/12] fix: AggregationInput and it's usage --- crates/zkvm/adapters/risc0/src/input.rs | 10 ++++++---- crates/zkvm/adapters/sp1/src/input.rs | 9 +++++---- crates/zkvm/zkvm/src/proof.rs | 6 +++--- 3 files changed, 14 insertions(+), 11 deletions(-) diff --git a/crates/zkvm/adapters/risc0/src/input.rs b/crates/zkvm/adapters/risc0/src/input.rs index 61183f049..a32e349fe 100644 --- a/crates/zkvm/adapters/risc0/src/input.rs +++ b/crates/zkvm/adapters/risc0/src/input.rs @@ -1,4 +1,4 @@ -use risc0_zkvm::{sha::Digest, ExecutorEnv, ExecutorEnvBuilder, Receipt}; +use risc0_zkvm::{sha::Digest, ExecutorEnv, ExecutorEnvBuilder, InnerReceipt, Receipt}; use strata_zkvm::{SerializationErrorSource, ZkVmError, ZkVmInputBuilder, ZkVmResult}; pub struct Risc0ProofInputBuilder<'a>(ExecutorEnvBuilder<'a>); @@ -38,7 +38,8 @@ impl<'a> ZkVmInputBuilder<'a> for Risc0ProofInputBuilder<'a> { fn write_proof(&mut self, item: strata_zkvm::AggregationInput) -> ZkVmResult<&mut Self> { // Learn more about assumption and proof compositions at https://dev.risczero.com/api/zkvm/composition - let receipt: Receipt = bincode::deserialize(item.proof().as_bytes())?; + let journal = item.proof().public_values.as_bytes().to_vec(); + let inner: InnerReceipt = bincode::deserialize(item.proof().public_values.as_bytes())?; let vk: Digest = item .vk() .as_bytes() @@ -48,7 +49,7 @@ impl<'a> ZkVmInputBuilder<'a> for Risc0ProofInputBuilder<'a> { // Write the verification key of the program that'll be proven in the guest. // Note: The vkey is written here so we don't have to hardcode it in guest code. // TODO: This should be fixed once the guest code is finalized - self.write_buf(&receipt.journal.bytes)?; + self.write_buf(&journal)?; self.0 .write(&vk) .map_err(|e| ZkVmError::SerializationError { @@ -56,7 +57,8 @@ impl<'a> ZkVmInputBuilder<'a> for Risc0ProofInputBuilder<'a> { })?; // `add_assumption` makes the receipt to be verified available to the prover. - self.0.add_assumption(receipt.clone()); + let receipt = Receipt::new(inner, journal); + self.0.add_assumption(receipt); Ok(self) } diff --git a/crates/zkvm/adapters/sp1/src/input.rs b/crates/zkvm/adapters/sp1/src/input.rs index 2cebc93b6..22f2b8fa2 100644 --- a/crates/zkvm/adapters/sp1/src/input.rs +++ b/crates/zkvm/adapters/sp1/src/input.rs @@ -1,4 +1,4 @@ -use sp1_sdk::{SP1Proof, SP1ProofWithPublicValues, SP1Stdin, SP1VerifyingKey}; +use sp1_sdk::{SP1Proof, SP1PublicValues, SP1Stdin, SP1VerifyingKey}; use strata_zkvm::{AggregationInput, ZkVmError, ZkVmInputBuilder, ZkVmResult}; // A wrapper around SP1Stdin @@ -26,18 +26,19 @@ impl<'a> ZkVmInputBuilder<'a> for SP1ProofInputBuilder { } fn write_proof(&mut self, item: AggregationInput) -> ZkVmResult<&mut Self> { - let proof: SP1ProofWithPublicValues = bincode::deserialize(item.proof().as_bytes())?; + let public_values = SP1PublicValues::from(item.proof().public_values.as_bytes()); + let proof: SP1Proof = bincode::deserialize(item.proof().proof.as_bytes())?; let vkey: SP1VerifyingKey = bincode::deserialize(item.vk().as_bytes())?; // Write the public values of the program that'll be proven inside zkVM. - self.0.write_slice(proof.public_values.as_slice()); + self.0.write_slice(public_values.as_slice()); // Write the proofs. // // Note: this data will not actually be read by the aggregation program, instead it will // be witnessed by the prover during the recursive aggregation process // inside SP1 itself. - match proof.proof { + match proof { SP1Proof::Compressed(compressed_proof) => { self.0.write_proof(*compressed_proof, vkey.vk); } diff --git a/crates/zkvm/zkvm/src/proof.rs b/crates/zkvm/zkvm/src/proof.rs index 037366bcc..0c77f3d56 100644 --- a/crates/zkvm/zkvm/src/proof.rs +++ b/crates/zkvm/zkvm/src/proof.rs @@ -103,16 +103,16 @@ impl VerificationKey { /// Consists of a proof and a verification key. #[derive(Debug, Clone, PartialEq, Eq)] pub struct AggregationInput { - proof: Proof, + proof: ProofReceipt, vk: VerificationKey, } impl AggregationInput { - pub fn new(proof: Proof, vk: VerificationKey) -> Self { + pub fn new(proof: ProofReceipt, vk: VerificationKey) -> Self { Self { proof, vk } } - pub fn proof(&self) -> &Proof { + pub fn proof(&self) -> &ProofReceipt { &self.proof } From bef77d7240ffc8823ca13903a4df6ee29111ff46 Mon Sep 17 00:00:00 2001 From: Prajwol Gyawali Date: Fri, 29 Nov 2024 16:20:19 +0545 Subject: [PATCH 07/12] fix: use ProofReceipt --- bin/prover-client/src/ckp_runner.rs | 2 +- bin/prover-client/src/prover.rs | 21 ++++++++--------- crates/proof-impl/checkpoint/src/prover.rs | 20 +++++------------ crates/proof-impl/cl-agg/src/prover.rs | 10 +++++---- crates/proof-impl/cl-stf/src/prover.rs | 8 ++++--- crates/proof-impl/l1-batch/src/prover.rs | 11 ++++----- crates/zkvm/adapters/risc0/src/input.rs | 10 +++++---- crates/zkvm/adapters/sp1/src/input.rs | 6 ++--- crates/zkvm/zkvm/src/input.rs | 2 +- crates/zkvm/zkvm/src/proof.rs | 12 +++++----- crates/zkvm/zkvm/src/prover.rs | 16 ++++++------- provers/tests/src/provers/mod.rs | 26 ++++++++++++---------- 12 files changed, 72 insertions(+), 72 deletions(-) diff --git a/bin/prover-client/src/ckp_runner.rs b/bin/prover-client/src/ckp_runner.rs index 1ff9e7805..e97ecab1f 100644 --- a/bin/prover-client/src/ckp_runner.rs +++ b/bin/prover-client/src/ckp_runner.rs @@ -119,7 +119,7 @@ async fn check_and_submit_proof( if proving_task.status == ProvingTaskStatus::Completed { match &proving_task.proof { Some(proof) => { - let proof_bytes = HexBytes::from(proof.proof().as_bytes()); + let proof_bytes = HexBytes::from(proof.receipt().proof.as_bytes()); info!( "Sending checkpoint proof: {:?} ckp id: {:?} to the sequencer", current_task_id, current_idx diff --git a/bin/prover-client/src/prover.rs b/bin/prover-client/src/prover.rs index 703059db0..956455c4f 100644 --- a/bin/prover-client/src/prover.rs +++ b/bin/prover-client/src/prover.rs @@ -11,7 +11,7 @@ use strata_rocksdb::{ }; use strata_sp1_adapter::SP1Host; use strata_sp1_guest_builder::*; -use strata_zkvm::{Proof, ProofType, ZkVmHost, ZkVmInputBuilder}; +use strata_zkvm::{Proof, ProofReceipt, ProofType, ZkVmHost, ZkVmInputBuilder}; use tracing::{error, info}; use uuid::Uuid; @@ -122,7 +122,7 @@ where input_builder.write_serde(&l1_batch_input.btc_task_ids.len())?; // Write each proof input for proof_input in l1_batch_input.get_proofs() { - input_builder.write_proof(proof_input)?; + input_builder.write_proof(&proof_input)?; } (input_builder.build()?, ProofType::Compressed) @@ -133,7 +133,7 @@ where .write_serde(&get_pm_rollup_params())? .write_buf(&cl_proof_input.cl_raw_witness)? .write_proof( - cl_proof_input + &cl_proof_input .el_proof .expect("CL Proving was sent without EL proof"), )? @@ -150,7 +150,7 @@ where // Write each proof input for proof_input in l2_batch_input.get_proofs() { - input_builder.write_proof(proof_input)?; + input_builder.write_proof(&proof_input)?; } (input_builder.build()?, ProofType::Compressed) @@ -167,14 +167,15 @@ where let mut input_builder = Vm::Input::new(); input_builder.write_serde(&get_pm_rollup_params())?; - input_builder.write_proof(l1_batch_proof)?; - input_builder.write_proof(l2_batch_proof)?; + input_builder.write_proof(&l1_batch_proof)?; + input_builder.write_proof(&l2_batch_proof)?; (input_builder.build()?, ProofType::Groth16) } }; - let (proof, vk) = vm.prove(zkvm_input, proof_type)?; + let proof = vm.prove(zkvm_input, proof_type)?; + let vk = vm.get_verification_key(); let agg_input = ProofWithVkey::new(proof, vk); Ok(agg_input) } @@ -321,7 +322,7 @@ impl Prover { Ok(ProofSubmissionStatus::ProofGenerationInProgress) } ProvingTaskState::Proved(proof) => { - self.save_proof_to_db(task_id, proof.proof())?; + self.save_proof_to_db(task_id, proof.receipt())?; let aggr_proof = proof.clone(); status_entry.remove(); @@ -338,10 +339,10 @@ impl Prover { } } - fn save_proof_to_db(&self, task_id: Uuid, proof: &Proof) -> Result<(), anyhow::Error> { + fn save_proof_to_db(&self, task_id: Uuid, proof: &ProofReceipt) -> Result<(), anyhow::Error> { self.db .prover_task_db() - .insert_new_task_entry(*task_id.as_bytes(), proof.into())?; + .insert_new_task_entry(*task_id.as_bytes(), bincode::serialize(&proof)?)?; Ok(()) } diff --git a/crates/proof-impl/checkpoint/src/prover.rs b/crates/proof-impl/checkpoint/src/prover.rs index 1ea94d02f..23959079e 100644 --- a/crates/proof-impl/checkpoint/src/prover.rs +++ b/crates/proof-impl/checkpoint/src/prover.rs @@ -1,16 +1,12 @@ use strata_primitives::params::RollupParams; -use strata_proofimpl_cl_stf::L2BatchProofOutput; -use strata_proofimpl_l1_batch::L1BatchProofOutput; -use strata_zkvm::{AggregationInput, Proof, PublicValues, VerificationKey, ZkVmProver, ZkVmResult}; +use strata_zkvm::{AggregationInput, PublicValues, ZkVmProver, ZkVmResult}; use crate::CheckpointProofOutput; pub struct CheckpointProverInput { pub rollup_params: RollupParams, - pub l1_batch: (Proof, L1BatchProofOutput), - pub l2_batch: (Proof, L2BatchProofOutput), - pub l1_batch_vk: VerificationKey, - pub l2_batch_vk: VerificationKey, + pub l1_batch: AggregationInput, + pub l2_batch: AggregationInput, } pub struct CheckpointProver; @@ -29,14 +25,8 @@ impl ZkVmProver for CheckpointProver { { B::new() .write_serde(&input.rollup_params)? - .write_proof(AggregationInput::new( - input.l1_batch.0.clone(), - input.l1_batch_vk.clone(), - ))? - .write_proof(AggregationInput::new( - input.l2_batch.0.clone(), - input.l2_batch_vk.clone(), - ))? + .write_proof(&input.l1_batch)? + .write_proof(&input.l2_batch)? .build() } diff --git a/crates/proof-impl/cl-agg/src/prover.rs b/crates/proof-impl/cl-agg/src/prover.rs index 5226da7dd..88ac8fdd4 100644 --- a/crates/proof-impl/cl-agg/src/prover.rs +++ b/crates/proof-impl/cl-agg/src/prover.rs @@ -1,8 +1,10 @@ use strata_proofimpl_cl_stf::L2BatchProofOutput; -use strata_zkvm::{AggregationInput, Proof, PublicValues, VerificationKey, ZkVmProver, ZkVmResult}; +use strata_zkvm::{ + AggregationInput, ProofReceipt, PublicValues, VerificationKey, ZkVmProver, ZkVmResult, +}; pub struct ClAggInput { - pub batch: Vec<(Proof, L2BatchProofOutput)>, + pub batch: Vec, pub cl_stf_vk: VerificationKey, } @@ -24,8 +26,8 @@ impl ZkVmProver for ClAggProver { let mut input_builder = B::new(); input_builder.write_serde(&len)?; - for (proof, _) in &input.batch { - input_builder.write_proof(AggregationInput::new( + for proof in &input.batch { + input_builder.write_proof(&AggregationInput::new( proof.clone(), input.cl_stf_vk.clone(), ))?; diff --git a/crates/proof-impl/cl-stf/src/prover.rs b/crates/proof-impl/cl-stf/src/prover.rs index 0aa0300c6..adc51f98a 100644 --- a/crates/proof-impl/cl-stf/src/prover.rs +++ b/crates/proof-impl/cl-stf/src/prover.rs @@ -1,6 +1,8 @@ use strata_primitives::params::RollupParams; use strata_state::{block::L2Block, chain_state::Chainstate}; -use strata_zkvm::{AggregationInput, Proof, PublicValues, VerificationKey, ZkVmProver, ZkVmResult}; +use strata_zkvm::{ + AggregationInput, ProofReceipt, PublicValues, VerificationKey, ZkVmProver, ZkVmResult, +}; use crate::L2BatchProofOutput; @@ -8,7 +10,7 @@ pub struct ClStfInput { pub rollup_params: RollupParams, pub pre_state: Chainstate, pub l2_block: L2Block, - pub evm_ee_proof: Proof, + pub evm_ee_proof: ProofReceipt, pub evm_ee_vk: VerificationKey, } @@ -29,7 +31,7 @@ impl ZkVmProver for ClStfProver { B::new() .write_serde(&input.rollup_params)? .write_borsh(&(&input.pre_state, &input.l2_block))? - .write_proof(AggregationInput::new( + .write_proof(&AggregationInput::new( input.evm_ee_proof.clone(), input.evm_ee_vk.clone(), ))? diff --git a/crates/proof-impl/l1-batch/src/prover.rs b/crates/proof-impl/l1-batch/src/prover.rs index 7acabedfa..a34925c1c 100644 --- a/crates/proof-impl/l1-batch/src/prover.rs +++ b/crates/proof-impl/l1-batch/src/prover.rs @@ -1,13 +1,14 @@ use borsh::{BorshDeserialize, BorshSerialize}; -use strata_proofimpl_btc_blockspace::logic::BlockspaceProofOutput; use strata_state::l1::HeaderVerificationState; -use strata_zkvm::{AggregationInput, Proof, PublicValues, VerificationKey, ZkVmProver, ZkVmResult}; +use strata_zkvm::{ + AggregationInput, ProofReceipt, PublicValues, VerificationKey, ZkVmProver, ZkVmResult, +}; use crate::logic::L1BatchProofOutput; #[derive(Debug, BorshSerialize, BorshDeserialize)] pub struct L1BatchProofInput { - pub batch: Vec<(Proof, BlockspaceProofOutput)>, + pub batch: Vec, pub state: HeaderVerificationState, pub blockspace_vk: VerificationKey, } @@ -32,8 +33,8 @@ impl ZkVmProver for L1BatchProver { let len = input.batch.len() as u32; input_builder.write_serde(&len)?; - for (proof, _) in &input.batch { - input_builder.write_proof(AggregationInput::new( + for proof in &input.batch { + input_builder.write_proof(&AggregationInput::new( proof.clone(), input.blockspace_vk.clone(), ))?; diff --git a/crates/zkvm/adapters/risc0/src/input.rs b/crates/zkvm/adapters/risc0/src/input.rs index a32e349fe..fddebb072 100644 --- a/crates/zkvm/adapters/risc0/src/input.rs +++ b/crates/zkvm/adapters/risc0/src/input.rs @@ -1,5 +1,7 @@ use risc0_zkvm::{sha::Digest, ExecutorEnv, ExecutorEnvBuilder, InnerReceipt, Receipt}; -use strata_zkvm::{SerializationErrorSource, ZkVmError, ZkVmInputBuilder, ZkVmResult}; +use strata_zkvm::{ + AggregationInput, SerializationErrorSource, ZkVmError, ZkVmInputBuilder, ZkVmResult, +}; pub struct Risc0ProofInputBuilder<'a>(ExecutorEnvBuilder<'a>); @@ -36,10 +38,10 @@ impl<'a> ZkVmInputBuilder<'a> for Risc0ProofInputBuilder<'a> { Ok(self) } - fn write_proof(&mut self, item: strata_zkvm::AggregationInput) -> ZkVmResult<&mut Self> { + fn write_proof(&mut self, item: &AggregationInput) -> ZkVmResult<&mut Self> { // Learn more about assumption and proof compositions at https://dev.risczero.com/api/zkvm/composition - let journal = item.proof().public_values.as_bytes().to_vec(); - let inner: InnerReceipt = bincode::deserialize(item.proof().public_values.as_bytes())?; + let journal = item.receipt().public_values.as_bytes().to_vec(); + let inner: InnerReceipt = bincode::deserialize(item.receipt().public_values.as_bytes())?; let vk: Digest = item .vk() .as_bytes() diff --git a/crates/zkvm/adapters/sp1/src/input.rs b/crates/zkvm/adapters/sp1/src/input.rs index 22f2b8fa2..9194a0ee6 100644 --- a/crates/zkvm/adapters/sp1/src/input.rs +++ b/crates/zkvm/adapters/sp1/src/input.rs @@ -25,9 +25,9 @@ impl<'a> ZkVmInputBuilder<'a> for SP1ProofInputBuilder { Ok(self) } - fn write_proof(&mut self, item: AggregationInput) -> ZkVmResult<&mut Self> { - let public_values = SP1PublicValues::from(item.proof().public_values.as_bytes()); - let proof: SP1Proof = bincode::deserialize(item.proof().proof.as_bytes())?; + fn write_proof(&mut self, item: &AggregationInput) -> ZkVmResult<&mut Self> { + let public_values = SP1PublicValues::from(item.receipt().public_values.as_bytes()); + let proof: SP1Proof = bincode::deserialize(item.receipt().proof.as_bytes())?; let vkey: SP1VerifyingKey = bincode::deserialize(item.vk().as_bytes())?; // Write the public values of the program that'll be proven inside zkVM. diff --git a/crates/zkvm/zkvm/src/input.rs b/crates/zkvm/zkvm/src/input.rs index c3f82e7ac..41ade921f 100644 --- a/crates/zkvm/zkvm/src/input.rs +++ b/crates/zkvm/zkvm/src/input.rs @@ -26,7 +26,7 @@ pub trait ZkVmInputBuilder<'a> { /// /// This method is specifically used for cases where proof aggregation or composition /// is involved, allowing for proof and verification inputs to be provided to the zkVM. - fn write_proof(&mut self, item: AggregationInput) -> ZkVmResult<&mut Self>; + fn write_proof(&mut self, item: &AggregationInput) -> ZkVmResult<&mut Self>; fn build(&mut self) -> Result; } diff --git a/crates/zkvm/zkvm/src/proof.rs b/crates/zkvm/zkvm/src/proof.rs index 0c77f3d56..25a36397f 100644 --- a/crates/zkvm/zkvm/src/proof.rs +++ b/crates/zkvm/zkvm/src/proof.rs @@ -100,20 +100,20 @@ impl VerificationKey { /// An input to the aggregation program. /// -/// Consists of a proof and a verification key. +/// Consists of a [`ProofReceipt`] and a [`VerificationKey`]. #[derive(Debug, Clone, PartialEq, Eq)] pub struct AggregationInput { - proof: ProofReceipt, + receipt: ProofReceipt, vk: VerificationKey, } impl AggregationInput { - pub fn new(proof: ProofReceipt, vk: VerificationKey) -> Self { - Self { proof, vk } + pub fn new(receipt: ProofReceipt, vk: VerificationKey) -> Self { + Self { receipt, vk } } - pub fn proof(&self) -> &ProofReceipt { - &self.proof + pub fn receipt(&self) -> &ProofReceipt { + &self.receipt } pub fn vk(&self) -> &VerificationKey { diff --git a/crates/zkvm/zkvm/src/prover.rs b/crates/zkvm/zkvm/src/prover.rs index 6b8c6d196..034759a5b 100644 --- a/crates/zkvm/zkvm/src/prover.rs +++ b/crates/zkvm/zkvm/src/prover.rs @@ -1,5 +1,5 @@ use crate::{ - host::ZkVmHost, input::ZkVmInputBuilder, proof::Proof, ProofType, PublicValues, ZkVmError, + host::ZkVmHost, input::ZkVmInputBuilder, ProofReceipt, ProofType, PublicValues, ZkVmResult, }; pub trait ZkVmProver { @@ -9,17 +9,17 @@ pub trait ZkVmProver { fn proof_type() -> ProofType; /// Prepares the input for the zkVM. - fn prepare_input<'a, B>(input: &'a Self::Input) -> Result + fn prepare_input<'a, B>(input: &'a Self::Input) -> ZkVmResult where B: ZkVmInputBuilder<'a>; /// Processes the [`PublicValues`] to produce the final output. - fn process_output(public_values: &PublicValues) -> Result + fn process_output(public_values: &PublicValues) -> ZkVmResult where H: ZkVmHost; /// Proves the computation using any zkVM host. - fn prove<'a, H>(input: &'a Self::Input, host: &H) -> Result<(Proof, Self::Output), ZkVmError> + fn prove<'a, H>(input: &'a Self::Input, host: &H) -> ZkVmResult where H: ZkVmHost, H::Input<'a>: ZkVmInputBuilder<'a>, @@ -28,11 +28,11 @@ pub trait ZkVmProver { let zkvm_input = Self::prepare_input::>(input)?; // Use the host to prove. - let proof = host.prove(zkvm_input, Self::proof_type())?; + let receipt = host.prove(zkvm_input, Self::proof_type())?; - // Process and return the output using the verifier. - let output = Self::process_output::(&proof.public_values)?; + // Process output to see if we are getting the expected output. + let _ = Self::process_output::(&receipt.public_values)?; - Ok((proof.proof, output)) + Ok(receipt) } } diff --git a/provers/tests/src/provers/mod.rs b/provers/tests/src/provers/mod.rs index 8f70584e8..1eb0a9cf6 100644 --- a/provers/tests/src/provers/mod.rs +++ b/provers/tests/src/provers/mod.rs @@ -1,7 +1,9 @@ use std::{fs, path::PathBuf}; use anyhow::Result; -use strata_zkvm::{Proof, ZkVmError, ZkVmHost, ZkVmProver, ZkVmResult}; +use strata_zkvm::{ + Proof, ProofReceipt, ZkVmError, ZkVmHost, ZkVmProver, ZkVmResult, +}; pub mod btc; mod checkpoint; @@ -17,14 +19,14 @@ pub trait ProofGenerator { fn get_host(&self) -> impl ZkVmHost; /// Generates a proof based on the input. - fn gen_proof(&self, input: &T) -> ZkVmResult<(Proof, P::Output)>; + fn gen_proof(&self, input: &T) -> ZkVmResult; /// Generates a unique proof ID based on the input. /// The proof ID will be the hash of the input and potentially other unique identifiers. fn get_proof_id(&self, input: &T) -> String; /// Retrieves a proof from cache or generates it if not found. - fn get_proof(&self, input: &T) -> ZkVmResult<(Proof, P::Output)> { + fn get_proof(&self, input: &T) -> ZkVmResult { // 1. Create the unique proof ID let proof_id = format!("{}_{}.proof", self.get_proof_id(input), self.get_host()); println!("Getting proof for {}", proof_id); @@ -37,13 +39,12 @@ pub trait ProofGenerator { .map_err(|e| ZkVmError::InputError(e.to_string()))?; let host = self.get_host(); verify_proof(&proof, &host)?; - let output = P::process_output(&proof, &host)?; - return Ok((proof, output)); + return Ok(proof); } // 3. Generate the proof println!("Proof not found in cache, generating proof..."); - let (proof, output) = self.gen_proof(input)?; + let proof = self.gen_proof(input)?; // Verify the proof verify_proof(&proof, &self.get_host())?; @@ -51,7 +52,7 @@ pub trait ProofGenerator { // Save the proof to cache write_proof_to_file(&proof, &proof_file).unwrap(); - Ok((proof, output)) + Ok(proof) } // Simulate the proof. This is different than running the in the MOCK_PROVER mode @@ -65,7 +66,7 @@ fn get_cache_dir() -> std::path::PathBuf { } /// Reads a proof from a file. -fn read_proof_from_file(proof_file: &std::path::Path) -> Result { +fn read_proof_from_file(proof_file: &std::path::Path) -> Result { use std::{fs::File, io::Read}; use anyhow::Context; @@ -76,12 +77,13 @@ fn read_proof_from_file(proof_file: &std::path::Path) -> Result { let mut buffer = Vec::new(); file.read_to_end(&mut buffer) .context("Failed to read proof file")?; + let proof_receipt: ProofReceipt = bincode::deserialize(&buffer)?; - Ok(Proof::new(buffer)) + Ok(proof_receipt) } /// Writes a proof to a file. -fn write_proof_to_file(proof: &Proof, proof_file: &std::path::Path) -> Result<()> { +fn write_proof_to_file(proof: &ProofReceipt, proof_file: &std::path::Path) -> Result<()> { use std::{fs::File, io::Write}; use anyhow::Context; @@ -94,13 +96,13 @@ fn write_proof_to_file(proof: &Proof, proof_file: &std::path::Path) -> Result<() let mut file = File::create(proof_file) .with_context(|| format!("Failed to create proof file {:?}", proof_file))?; - file.write_all(proof.as_bytes()) + file.write_all(&bincode::serialize(&proof)?) .context("Failed to write proof to file")?; Ok(()) } /// Verifies a proof independently. -fn verify_proof(proof: &Proof, host: &impl ZkVmHost) -> ZkVmResult<()> { +fn verify_proof(proof: &ProofReceipt, host: &impl ZkVmHost) -> ZkVmResult<()> { host.verify(proof) } From ad1d3f47561de442e7348a67c2a8774203431fd0 Mon Sep 17 00:00:00 2001 From: Prajwol Gyawali Date: Sat, 30 Nov 2024 12:29:04 +0545 Subject: [PATCH 08/12] fix(sp1): proof verification in mock mode --- crates/zkvm/adapters/sp1/src/host.rs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/crates/zkvm/adapters/sp1/src/host.rs b/crates/zkvm/adapters/sp1/src/host.rs index fbb93e63b..079ff05fe 100644 --- a/crates/zkvm/adapters/sp1/src/host.rs +++ b/crates/zkvm/adapters/sp1/src/host.rs @@ -105,6 +105,10 @@ impl ZkVmHost for SP1Host { } fn verify(&self, proof: &ProofReceipt) -> ZkVmResult<()> { + #[cfg(feature = "mock")] + { + std::env::set_var("SP1_PROVER", "mock"); + } let public_values = SP1PublicValues::from(proof.public_values.as_bytes()); let proof: SP1Proof = bincode::deserialize(proof.proof.as_bytes())?; let sp1_version = sp1_sdk::SP1_CIRCUIT_VERSION.to_string(); From 9b51c6498788a26cce7c1dae2ec7380284d1cc0f Mon Sep 17 00:00:00 2001 From: Prajwol Gyawali Date: Mon, 2 Dec 2024 15:38:41 +0545 Subject: [PATCH 09/12] refactor: use ByteWrapper --- crates/zkvm/zkvm/src/proof.rs | 90 ++++++++++++----------------------- 1 file changed, 30 insertions(+), 60 deletions(-) diff --git a/crates/zkvm/zkvm/src/proof.rs b/crates/zkvm/zkvm/src/proof.rs index 25a36397f..9e68894f7 100644 --- a/crates/zkvm/zkvm/src/proof.rs +++ b/crates/zkvm/zkvm/src/proof.rs @@ -2,128 +2,98 @@ use arbitrary::Arbitrary; use borsh::{BorshDeserialize, BorshSerialize}; use serde::{Deserialize, Serialize}; -/// Validity proof generated by the `ZkVmHost` +/// Represents a wrapper around a byte vector for various proofs and keys. +/// +/// Provides common utilities such as byte access and emptiness checks. #[derive( Debug, Clone, Serialize, Deserialize, BorshSerialize, BorshDeserialize, PartialEq, Eq, Arbitrary, )] -pub struct Proof(Vec); +pub struct ByteWrapper(Vec); -impl Proof { +impl ByteWrapper { + /// Creates a new instance from a `Vec`. pub fn new(data: Vec) -> Self { Self(data) } + /// Returns a reference to the inner byte slice. pub fn as_bytes(&self) -> &[u8] { &self.0 } + /// Checks if the byte vector is empty. pub fn is_empty(&self) -> bool { self.0.is_empty() } } -impl From for Vec { - fn from(value: Proof) -> Self { +impl From for Vec { + fn from(value: ByteWrapper) -> Self { value.0 } } -impl From<&Proof> for Vec { - fn from(value: &Proof) -> Self { +impl From<&ByteWrapper> for Vec { + fn from(value: &ByteWrapper) -> Self { value.0.clone() } } -#[derive( - Debug, Clone, Serialize, Deserialize, BorshSerialize, BorshDeserialize, PartialEq, Eq, Arbitrary, -)] -pub struct PublicValues(Vec); +/// Validity proof generated by the `ZkVmHost`. +pub type Proof = ByteWrapper; -impl PublicValues { - pub fn new(data: Vec) -> Self { - Self(data) - } - - pub fn as_bytes(&self) -> &[u8] { - &self.0 - } +/// Public values associated with a [`Proof`]. +pub type PublicValues = ByteWrapper; - pub fn is_empty(&self) -> bool { - self.0.is_empty() - } -} - -impl From for Vec { - fn from(value: PublicValues) -> Self { - value.0 - } -} - -impl From<&PublicValues> for Vec { - fn from(value: &PublicValues) -> Self { - value.0.clone() - } -} +/// Verification Key required to verify proof generated from `ZkVmHost`. +pub type VerificationKey = ByteWrapper; +/// A receipt containing a `Proof` and associated `PublicValues`. #[derive( Debug, Clone, Serialize, Deserialize, BorshSerialize, BorshDeserialize, PartialEq, Eq, Arbitrary, )] pub struct ProofReceipt { + /// The validity proof. pub proof: Proof, + /// The public values associated with the proof. pub public_values: PublicValues, } -/// Verification Key required to verify proof generated from `ZKVMHost` -#[derive( - Debug, - Clone, - PartialEq, - Eq, - Default, - Serialize, - Deserialize, - BorshSerialize, - BorshDeserialize, - Arbitrary, -)] -pub struct VerificationKey(Vec); - -impl VerificationKey { - pub fn new(data: Vec) -> Self { - Self(data) - } - - pub fn as_bytes(&self) -> &[u8] { - &self.0 - } -} - /// An input to the aggregation program. /// /// Consists of a [`ProofReceipt`] and a [`VerificationKey`]. #[derive(Debug, Clone, PartialEq, Eq)] pub struct AggregationInput { + /// The proof receipt containing the proof and its public values. receipt: ProofReceipt, + /// The verification key for validating the proof. vk: VerificationKey, } impl AggregationInput { + /// Creates a new `AggregationInput`. pub fn new(receipt: ProofReceipt, vk: VerificationKey) -> Self { Self { receipt, vk } } + /// Returns a reference to the `ProofReceipt`. pub fn receipt(&self) -> &ProofReceipt { &self.receipt } + /// Returns a reference to the `VerificationKey`. pub fn vk(&self) -> &VerificationKey { &self.vk } } +/// Enumeration of proof types supported by the system. #[derive(Debug, Clone, Copy, PartialEq, Eq)] pub enum ProofType { + /// Represents a Groth16 proof. Groth16, + /// Represents a core proof. Core, + /// Represents a compressed proof. Compressed, } From b7e4eae654a551ae47a606a2ca41043a0ff2e623 Mon Sep 17 00:00:00 2001 From: Prajwol Gyawali Date: Tue, 3 Dec 2024 08:59:24 +0545 Subject: [PATCH 10/12] fix: update native adapter --- crates/zkvm/adapters/native/src/host.rs | 16 ++++++++-------- crates/zkvm/adapters/native/src/input.rs | 9 +++++---- 2 files changed, 13 insertions(+), 12 deletions(-) diff --git a/crates/zkvm/adapters/native/src/host.rs b/crates/zkvm/adapters/native/src/host.rs index e060ae111..dda7c8311 100644 --- a/crates/zkvm/adapters/native/src/host.rs +++ b/crates/zkvm/adapters/native/src/host.rs @@ -1,6 +1,8 @@ use std::{fmt, sync::Arc}; -use strata_zkvm::{Proof, ProofType, VerificationKey, ZkVmHost, ZkVmResult}; +use strata_zkvm::{ + Proof, ProofReceipt, ProofType, PublicValues, VerificationKey, ZkVmHost, ZkVmResult, +}; use crate::{env::NativeMachine, input::NativeMachineInputBuilder}; @@ -18,10 +20,12 @@ impl ZkVmHost for NativeHost { &self, native_machine: NativeMachine, _proof_type: ProofType, - ) -> ZkVmResult<(Proof, VerificationKey)> { + ) -> ZkVmResult { (self.process_proof)(&native_machine)?; let output = native_machine.state.borrow().output.clone(); - Ok((Proof::new(output), self.get_verification_key())) + let proof = Proof::default(); + let public_values = PublicValues::new(output); + Ok(ProofReceipt::new(proof, public_values)) } fn get_verification_key(&self) -> VerificationKey { @@ -38,11 +42,7 @@ impl ZkVmHost for NativeHost { bincode::deserialize(proof.as_bytes()).map_err(|e| e.into()) } - fn extract_raw_public_output(proof: &Proof) -> ZkVmResult> { - Ok(proof.as_bytes().to_vec()) - } - - fn verify(&self, _proof: &Proof) -> ZkVmResult<()> { + fn verify(&self, _proof: &ProofReceipt) -> ZkVmResult<()> { Ok(()) } } diff --git a/crates/zkvm/adapters/native/src/input.rs b/crates/zkvm/adapters/native/src/input.rs index 677bbe8d1..d17786905 100644 --- a/crates/zkvm/adapters/native/src/input.rs +++ b/crates/zkvm/adapters/native/src/input.rs @@ -1,4 +1,4 @@ -use strata_zkvm::{ZkVmInputBuilder, ZkVmResult}; +use strata_zkvm::{AggregationInput, ZkVmInputBuilder, ZkVmResult}; use crate::env::NativeMachine; @@ -26,9 +26,10 @@ impl<'a> ZkVmInputBuilder<'a> for NativeMachineInputBuilder { self.write_buf(&slice) } - fn write_proof(&mut self, item: strata_zkvm::AggregationInput) -> ZkVmResult<&mut Self> { - // TODO: figure this out - self.write_buf(item.proof().as_bytes()) + fn write_proof(&mut self, item: &AggregationInput) -> ZkVmResult<&mut Self> { + // For the native mode we only write the public values since the proof is expected to be + // empty + self.write_buf(item.receipt().public_values().as_bytes()) } fn build(&mut self) -> ZkVmResult { From 220c08df19dd23cbb261ab43f17527ce24f62ef6 Mon Sep 17 00:00:00 2001 From: Prajwol Gyawali Date: Tue, 3 Dec 2024 09:02:18 +0545 Subject: [PATCH 11/12] fix: make ProofReceipt fields private and instead use a pub getter --- bin/prover-client/src/ckp_runner.rs | 2 +- crates/zkvm/adapters/risc0/src/host.rs | 13 +++++------ crates/zkvm/adapters/risc0/src/input.rs | 4 ++-- crates/zkvm/adapters/sp1/src/host.rs | 9 +++----- crates/zkvm/adapters/sp1/src/input.rs | 4 ++-- crates/zkvm/zkvm/src/proof.rs | 30 +++++++++++++++++++++++-- crates/zkvm/zkvm/src/prover.rs | 2 +- 7 files changed, 42 insertions(+), 22 deletions(-) diff --git a/bin/prover-client/src/ckp_runner.rs b/bin/prover-client/src/ckp_runner.rs index e97ecab1f..ce58608b2 100644 --- a/bin/prover-client/src/ckp_runner.rs +++ b/bin/prover-client/src/ckp_runner.rs @@ -119,7 +119,7 @@ async fn check_and_submit_proof( if proving_task.status == ProvingTaskStatus::Completed { match &proving_task.proof { Some(proof) => { - let proof_bytes = HexBytes::from(proof.receipt().proof.as_bytes()); + let proof_bytes = HexBytes::from(proof.receipt().proof().as_bytes()); info!( "Sending checkpoint proof: {:?} ckp id: {:?} to the sequencer", current_task_id, current_idx diff --git a/crates/zkvm/adapters/risc0/src/host.rs b/crates/zkvm/adapters/risc0/src/host.rs index cc4bd9952..ec2300cef 100644 --- a/crates/zkvm/adapters/risc0/src/host.rs +++ b/crates/zkvm/adapters/risc0/src/host.rs @@ -61,10 +61,7 @@ impl ZkVmHost for Risc0Host { let proof = Proof::new(bincode::serialize(&proof_info.receipt.inner)?); let public_values = PublicValues::new(proof_info.receipt.journal.bytes); - Ok(ProofReceipt { - proof, - public_values, - }) + Ok(ProofReceipt::new(proof, public_values)) } fn extract_serde_public_output( @@ -83,8 +80,8 @@ impl ZkVmHost for Risc0Host { } fn verify(&self, proof: &ProofReceipt) -> ZkVmResult<()> { - let journal = proof.public_values.as_bytes().to_vec(); - let inner: InnerReceipt = bincode::deserialize(proof.proof.as_bytes())?; + let journal = proof.public_values().as_bytes().to_vec(); + let inner: InnerReceipt = bincode::deserialize(proof.proof().as_bytes())?; let receipt = Receipt::new(inner, journal); receipt .verify(self.id) @@ -133,7 +130,7 @@ mod tests { host.verify(&proof).expect("Proof verification failed"); // assert public outputs extraction from proof works - let out: u32 = Risc0Host::extract_serde_public_output(&proof.public_values) + let out: u32 = Risc0Host::extract_serde_public_output(proof.public_values()) .expect("Failed to extract public outputs"); assert_eq!(input, out) } @@ -157,7 +154,7 @@ mod tests { zkvm.verify(&proof).expect("Proof verification failed"); // assert public outputs extraction from proof works - let out: u32 = Risc0Host::extract_serde_public_output(&proof.public_values).expect( + let out: u32 = Risc0Host::extract_serde_public_output(proof.public_values()).expect( "Failed to extract public outputs", ); diff --git a/crates/zkvm/adapters/risc0/src/input.rs b/crates/zkvm/adapters/risc0/src/input.rs index fddebb072..0ae25a284 100644 --- a/crates/zkvm/adapters/risc0/src/input.rs +++ b/crates/zkvm/adapters/risc0/src/input.rs @@ -40,8 +40,8 @@ impl<'a> ZkVmInputBuilder<'a> for Risc0ProofInputBuilder<'a> { fn write_proof(&mut self, item: &AggregationInput) -> ZkVmResult<&mut Self> { // Learn more about assumption and proof compositions at https://dev.risczero.com/api/zkvm/composition - let journal = item.receipt().public_values.as_bytes().to_vec(); - let inner: InnerReceipt = bincode::deserialize(item.receipt().public_values.as_bytes())?; + let journal = item.receipt().public_values().as_bytes().to_vec(); + let inner: InnerReceipt = bincode::deserialize(item.receipt().public_values().as_bytes())?; let vk: Digest = item .vk() .as_bytes() diff --git a/crates/zkvm/adapters/sp1/src/host.rs b/crates/zkvm/adapters/sp1/src/host.rs index 079ff05fe..33845cab4 100644 --- a/crates/zkvm/adapters/sp1/src/host.rs +++ b/crates/zkvm/adapters/sp1/src/host.rs @@ -85,10 +85,7 @@ impl ZkVmHost for SP1Host { let proof = Proof::new(bincode::serialize(&proof_info.proof)?); let public_values = PublicValues::new(proof_info.public_values.to_vec()); - Ok(ProofReceipt { - proof, - public_values, - }) + Ok(ProofReceipt::new(proof, public_values)) } fn extract_serde_public_output( @@ -109,8 +106,8 @@ impl ZkVmHost for SP1Host { { std::env::set_var("SP1_PROVER", "mock"); } - let public_values = SP1PublicValues::from(proof.public_values.as_bytes()); - let proof: SP1Proof = bincode::deserialize(proof.proof.as_bytes())?; + let public_values = SP1PublicValues::from(proof.public_values().as_bytes()); + let proof: SP1Proof = bincode::deserialize(proof.proof().as_bytes())?; let sp1_version = sp1_sdk::SP1_CIRCUIT_VERSION.to_string(); let proof_with_public_values = SP1ProofWithPublicValues { proof, diff --git a/crates/zkvm/adapters/sp1/src/input.rs b/crates/zkvm/adapters/sp1/src/input.rs index 9194a0ee6..75b9d5b51 100644 --- a/crates/zkvm/adapters/sp1/src/input.rs +++ b/crates/zkvm/adapters/sp1/src/input.rs @@ -26,8 +26,8 @@ impl<'a> ZkVmInputBuilder<'a> for SP1ProofInputBuilder { } fn write_proof(&mut self, item: &AggregationInput) -> ZkVmResult<&mut Self> { - let public_values = SP1PublicValues::from(item.receipt().public_values.as_bytes()); - let proof: SP1Proof = bincode::deserialize(item.receipt().proof.as_bytes())?; + let public_values = SP1PublicValues::from(item.receipt().public_values().as_bytes()); + let proof: SP1Proof = bincode::deserialize(item.receipt().proof().as_bytes())?; let vkey: SP1VerifyingKey = bincode::deserialize(item.vk().as_bytes())?; // Write the public values of the program that'll be proven inside zkVM. diff --git a/crates/zkvm/zkvm/src/proof.rs b/crates/zkvm/zkvm/src/proof.rs index 9e68894f7..a98bdcae5 100644 --- a/crates/zkvm/zkvm/src/proof.rs +++ b/crates/zkvm/zkvm/src/proof.rs @@ -39,6 +39,12 @@ impl From<&ByteWrapper> for Vec { } } +impl Default for ByteWrapper { + fn default() -> Self { + ByteWrapper::new(Vec::new()) + } +} + /// Validity proof generated by the `ZkVmHost`. pub type Proof = ByteWrapper; @@ -54,9 +60,29 @@ pub type VerificationKey = ByteWrapper; )] pub struct ProofReceipt { /// The validity proof. - pub proof: Proof, + proof: Proof, /// The public values associated with the proof. - pub public_values: PublicValues, + public_values: PublicValues, +} + +impl ProofReceipt { + /// Creates a new `ProofReceipt` from proof and it's associated public values + pub fn new(proof: Proof, public_values: PublicValues) -> Self { + Self { + proof, + public_values, + } + } + + /// Returns the validity proof + pub fn proof(&self) -> &Proof { + &self.proof + } + + /// Returns the public values associated with the proof. + pub fn public_values(&self) -> &PublicValues { + &self.public_values + } } /// An input to the aggregation program. diff --git a/crates/zkvm/zkvm/src/prover.rs b/crates/zkvm/zkvm/src/prover.rs index 034759a5b..c4b2c39ee 100644 --- a/crates/zkvm/zkvm/src/prover.rs +++ b/crates/zkvm/zkvm/src/prover.rs @@ -31,7 +31,7 @@ pub trait ZkVmProver { let receipt = host.prove(zkvm_input, Self::proof_type())?; // Process output to see if we are getting the expected output. - let _ = Self::process_output::(&receipt.public_values)?; + let _ = Self::process_output::(receipt.public_values())?; Ok(receipt) } From 38d3e01821a7e20b57cef8085fa227509f959af7 Mon Sep 17 00:00:00 2001 From: Prajwol Gyawali Date: Tue, 3 Dec 2024 09:02:29 +0545 Subject: [PATCH 12/12] fix: adjust test --- provers/tests/src/provers/btc.rs | 9 +++------ provers/tests/src/provers/checkpoint.rs | 23 ++++++++--------------- provers/tests/src/provers/cl.rs | 11 ++++------- provers/tests/src/provers/el.rs | 6 +++--- provers/tests/src/provers/l1_batch.rs | 6 +++--- provers/tests/src/provers/l2_batch.rs | 5 ++--- provers/tests/src/provers/mod.rs | 4 +--- 7 files changed, 24 insertions(+), 40 deletions(-) diff --git a/provers/tests/src/provers/btc.rs b/provers/tests/src/provers/btc.rs index 6ebff938f..19f45042e 100644 --- a/provers/tests/src/provers/btc.rs +++ b/provers/tests/src/provers/btc.rs @@ -1,10 +1,7 @@ use bitcoin::Block; -use strata_proofimpl_btc_blockspace::{ - logic::{BlockspaceProofInput, BlockspaceProofOutput}, - prover::BtcBlockspaceProver, -}; +use strata_proofimpl_btc_blockspace::{logic::BlockspaceProofInput, prover::BtcBlockspaceProver}; use strata_test_utils::l2::gen_params; -use strata_zkvm::{Proof, ZkVmHost, ZkVmProver, ZkVmResult}; +use strata_zkvm::{ProofReceipt, ZkVmHost, ZkVmProver, ZkVmResult}; use super::ProofGenerator; @@ -29,7 +26,7 @@ impl ProofGenerator for BtcBlockProofGe Ok(input) } - fn gen_proof(&self, block: &Block) -> ZkVmResult<(Proof, BlockspaceProofOutput)> { + fn gen_proof(&self, block: &Block) -> ZkVmResult { let host = self.get_host(); let input = self.get_input(block)?; BtcBlockspaceProver::prove(&input, &host) diff --git a/provers/tests/src/provers/checkpoint.rs b/provers/tests/src/provers/checkpoint.rs index 5269176a7..02e334cd1 100644 --- a/provers/tests/src/provers/checkpoint.rs +++ b/provers/tests/src/provers/checkpoint.rs @@ -1,9 +1,6 @@ -use strata_proofimpl_checkpoint::{ - prover::{CheckpointProver, CheckpointProverInput}, - CheckpointProofOutput, -}; +use strata_proofimpl_checkpoint::prover::{CheckpointProver, CheckpointProverInput}; use strata_test_utils::l2::gen_params; -use strata_zkvm::{Proof, ZkVmHost, ZkVmProver, ZkVmResult}; +use strata_zkvm::{AggregationInput, ProofReceipt, ZkVmHost, ZkVmProver, ZkVmResult}; use super::{ btc::BtcBlockProofGenerator, cl::ClProofGenerator, el::ElProofGenerator, @@ -45,34 +42,30 @@ impl ProofGenerator let (l1_start_height, l1_end_height) = batch_info.l1_range; let (l2_start_height, l2_end_height) = batch_info.l2_range; - let l1_batch = self + let l1_batch_proof = self .l1_batch_prover .get_proof(&(l1_start_height as u32, l1_end_height as u32)) .unwrap(); + let l1_batch_vk = self.l1_batch_prover.get_host().get_verification_key(); + let l1_batch = AggregationInput::new(l1_batch_proof, l1_batch_vk); - let l2_batch = self + let l2_batch_proof = self .l2_batch_prover .get_proof(&(l2_start_height, l2_end_height)) .unwrap(); - - let l1_batch_vk = self.l1_batch_prover.get_host().get_verification_key(); let l2_batch_vk = self.l2_batch_prover.get_host().get_verification_key(); + let l2_batch = AggregationInput::new(l2_batch_proof, l2_batch_vk); let input = CheckpointProverInput { rollup_params: rollup_params.clone(), l1_batch, l2_batch, - l1_batch_vk, - l2_batch_vk, }; Ok(input) } - fn gen_proof( - &self, - batch_info: &CheckpointBatchInfo, - ) -> ZkVmResult<(Proof, CheckpointProofOutput)> { + fn gen_proof(&self, batch_info: &CheckpointBatchInfo) -> ZkVmResult { let host = self.get_host(); let input = self.get_input(batch_info)?; CheckpointProver::prove(&input, &host) diff --git a/provers/tests/src/provers/cl.rs b/provers/tests/src/provers/cl.rs index 38d500399..357a13bd8 100644 --- a/provers/tests/src/provers/cl.rs +++ b/provers/tests/src/provers/cl.rs @@ -1,9 +1,6 @@ -use strata_proofimpl_cl_stf::{ - prover::{ClStfInput, ClStfProver}, - L2BatchProofOutput, -}; +use strata_proofimpl_cl_stf::prover::{ClStfInput, ClStfProver}; use strata_test_utils::{evm_ee::L2Segment, l2::gen_params}; -use strata_zkvm::{Proof, ZkVmHost, ZkVmProver, ZkVmResult}; +use strata_zkvm::{ProofReceipt, ZkVmHost, ZkVmProver, ZkVmResult}; use super::{el::ElProofGenerator, ProofGenerator}; @@ -24,7 +21,7 @@ impl ClProofGenerator { impl ProofGenerator for ClProofGenerator { fn get_input(&self, block_num: &u64) -> ZkVmResult { // Generate EL proof required for aggregation - let (el_proof, _) = self.el_proof_generator.get_proof(block_num)?; + let el_proof = self.el_proof_generator.get_proof(block_num)?; // Read CL witness data let params = gen_params(); @@ -43,7 +40,7 @@ impl ProofGenerator for ClProofGenerator { }) } - fn gen_proof(&self, block_num: &u64) -> ZkVmResult<(Proof, L2BatchProofOutput)> { + fn gen_proof(&self, block_num: &u64) -> ZkVmResult { let host = self.get_host(); let input = self.get_input(block_num)?; ClStfProver::prove(&input, &host) diff --git a/provers/tests/src/provers/el.rs b/provers/tests/src/provers/el.rs index a435b3b0c..bbc6a1dba 100644 --- a/provers/tests/src/provers/el.rs +++ b/provers/tests/src/provers/el.rs @@ -1,6 +1,6 @@ -use strata_proofimpl_evm_ee_stf::{prover::EvmEeProver, ELProofInput, ELProofPublicParams}; +use strata_proofimpl_evm_ee_stf::{prover::EvmEeProver, ELProofInput}; use strata_test_utils::evm_ee::EvmSegment; -use strata_zkvm::{Proof, ZkVmHost, ZkVmProver, ZkVmResult}; +use strata_zkvm::{ProofReceipt, ZkVmHost, ZkVmProver, ZkVmResult}; use super::ProofGenerator; @@ -22,7 +22,7 @@ impl ProofGenerator for ElProofGenerator { Ok(input) } - fn gen_proof(&self, block_num: &u64) -> ZkVmResult<(Proof, ELProofPublicParams)> { + fn gen_proof(&self, block_num: &u64) -> ZkVmResult { let host = self.get_host(); let input = self.get_input(block_num)?; diff --git a/provers/tests/src/provers/l1_batch.rs b/provers/tests/src/provers/l1_batch.rs index 1d2fa3305..fb7868eed 100644 --- a/provers/tests/src/provers/l1_batch.rs +++ b/provers/tests/src/provers/l1_batch.rs @@ -1,7 +1,7 @@ use bitcoin::params::MAINNET; -use strata_proofimpl_l1_batch::{L1BatchProofInput, L1BatchProofOutput, L1BatchProver}; +use strata_proofimpl_l1_batch::{L1BatchProofInput, L1BatchProver}; use strata_test_utils::bitcoin::get_btc_chain; -use strata_zkvm::{Proof, ZkVmHost, ZkVmProver, ZkVmResult}; +use strata_zkvm::{ProofReceipt, ZkVmHost, ZkVmProver, ZkVmResult}; use super::{btc::BtcBlockProofGenerator, ProofGenerator}; @@ -43,7 +43,7 @@ impl ProofGenerator<(u32, u32), L1BatchProver> for L1BatchProofGene Ok(input) } - fn gen_proof(&self, heights: &(u32, u32)) -> ZkVmResult<(Proof, L1BatchProofOutput)> { + fn gen_proof(&self, heights: &(u32, u32)) -> ZkVmResult { let input = self.get_input(heights)?; let host = self.get_host(); L1BatchProver::prove(&input, &host) diff --git a/provers/tests/src/provers/l2_batch.rs b/provers/tests/src/provers/l2_batch.rs index 032e94cf7..1cc7d3b07 100644 --- a/provers/tests/src/provers/l2_batch.rs +++ b/provers/tests/src/provers/l2_batch.rs @@ -1,6 +1,5 @@ use strata_proofimpl_cl_agg::{ClAggInput, ClAggProver}; -use strata_proofimpl_cl_stf::L2BatchProofOutput; -use strata_zkvm::{Proof, ZkVmHost, ZkVmProver, ZkVmResult}; +use strata_zkvm::{ProofReceipt, ZkVmHost, ZkVmProver, ZkVmResult}; use super::{cl::ClProofGenerator, ProofGenerator}; @@ -32,7 +31,7 @@ impl ProofGenerator<(u64, u64), ClAggProver> for L2BatchProofGenera Ok(ClAggInput { batch, cl_stf_vk }) } - fn gen_proof(&self, heights: &(u64, u64)) -> ZkVmResult<(Proof, L2BatchProofOutput)> { + fn gen_proof(&self, heights: &(u64, u64)) -> ZkVmResult { let input = self.get_input(heights)?; let host = self.get_host(); ClAggProver::prove(&input, &host) diff --git a/provers/tests/src/provers/mod.rs b/provers/tests/src/provers/mod.rs index 1eb0a9cf6..d6257d36c 100644 --- a/provers/tests/src/provers/mod.rs +++ b/provers/tests/src/provers/mod.rs @@ -1,9 +1,7 @@ use std::{fs, path::PathBuf}; use anyhow::Result; -use strata_zkvm::{ - Proof, ProofReceipt, ZkVmError, ZkVmHost, ZkVmProver, ZkVmResult, -}; +use strata_zkvm::{ProofReceipt, ZkVmError, ZkVmHost, ZkVmProver, ZkVmResult}; pub mod btc; mod checkpoint;