diff --git a/crates/sdk/src/fs.rs b/crates/sdk/src/fs.rs index 1359adb13..710d282be 100644 --- a/crates/sdk/src/fs.rs +++ b/crates/sdk/src/fs.rs @@ -14,6 +14,7 @@ use crate::{ F, SC, }; +// TODO: remove these type specific functions pub fn read_exe_from_file>(path: P) -> Result> { read_from_file_bitcode(path) } @@ -78,13 +79,13 @@ pub fn write_evm_verifier_to_file>(verifier: EvmVerifier, path: P write_to_file_bytes(path, verifier) } -pub(crate) fn read_from_file_bitcode>(path: P) -> Result { +pub fn read_from_file_bitcode>(path: P) -> Result { let data = std::fs::read(path)?; let ret = bitcode::deserialize(&data)?; Ok(ret) } -pub(crate) fn write_to_file_bitcode>(path: P, data: T) -> Result<()> { +pub fn write_to_file_bitcode>(path: P, data: T) -> Result<()> { let bytes = bitcode::serialize(&data)?; if let Some(parent) = path.as_ref().parent() { create_dir_all(parent)?; @@ -93,15 +94,12 @@ pub(crate) fn write_to_file_bitcode>(path: P, data: Ok(()) } -pub(crate) fn read_from_file_bytes>, P: AsRef>(path: P) -> Result { +pub fn read_from_file_bytes>, P: AsRef>(path: P) -> Result { let bytes = read(path)?; Ok(T::from(bytes)) } -pub(crate) fn write_to_file_bytes>, P: AsRef>( - path: P, - data: T, -) -> Result<()> { +pub fn write_to_file_bytes>, P: AsRef>(path: P, data: T) -> Result<()> { if let Some(parent) = path.as_ref().parent() { create_dir_all(parent)?; } diff --git a/crates/sdk/src/lib.rs b/crates/sdk/src/lib.rs index 67048a003..af9db1902 100644 --- a/crates/sdk/src/lib.rs +++ b/crates/sdk/src/lib.rs @@ -39,6 +39,7 @@ use openvm_transpiler::{ FromElf, }; use prover::vm::ContinuationVmProof; +use verifier::root::types::RootVmVerifierInput; pub mod commit; pub mod config; @@ -54,8 +55,8 @@ pub mod fs; use crate::{ config::AggConfig, - keygen::AggProvingKey, - prover::{AppProver, ContinuationProver}, + keygen::{AggProvingKey, AggStarkProvingKey}, + prover::{AppProver, ContinuationProver, StarkProver}, }; pub type SC = BabyBearPoseidon2Config; @@ -184,6 +185,22 @@ impl Sdk { Ok(agg_pk) } + pub fn generate_root_verifier_input>( + &self, + app_pk: Arc>, + app_exe: Arc, + agg_stark_pk: AggStarkProvingKey, + inputs: StdIn, + ) -> Result> + where + VC::Executor: Chip, + VC::Periphery: Chip, + { + let stark_prover = StarkProver::new(app_pk, app_exe, agg_stark_pk); + let proof = stark_prover.generate_root_verifier_input(inputs); + Ok(proof) + } + pub fn generate_evm_proof>( &self, reader: &impl Halo2ParamsReader, diff --git a/crates/sdk/src/prover/agg.rs b/crates/sdk/src/prover/agg.rs index 69944a8be..4c4b91c8e 100644 --- a/crates/sdk/src/prover/agg.rs +++ b/crates/sdk/src/prover/agg.rs @@ -85,15 +85,23 @@ impl AggStarkProver { /// Generate a proof to aggregate app proofs. pub fn generate_agg_proof(&self, app_proofs: ContinuationVmProof) -> Proof { + let root_verifier_input = self.generate_root_verifier_input(app_proofs); + self.generate_root_proof_impl(root_verifier_input) + } + + pub fn generate_root_verifier_input( + &self, + app_proofs: ContinuationVmProof, + ) -> RootVmVerifierInput { let leaf_proofs = self .leaf_controller .generate_proof(&self.leaf_prover, &app_proofs); let public_values = app_proofs.user_public_values.public_values; let internal_proof = self.generate_internal_proof_impl(leaf_proofs, &public_values); - self.generate_root_proof_impl(RootVmVerifierInput { + RootVmVerifierInput { proofs: vec![internal_proof], public_values, - }) + } } fn generate_internal_proof_impl( diff --git a/crates/sdk/src/prover/mod.rs b/crates/sdk/src/prover/mod.rs index 08c602f03..b14cb9dfe 100644 --- a/crates/sdk/src/prover/mod.rs +++ b/crates/sdk/src/prover/mod.rs @@ -23,10 +23,7 @@ pub mod vm; #[allow(unused_imports)] pub use stark::*; -use crate::{ - keygen::AggProvingKey, - prover::{halo2::Halo2Prover, stark::StarkProver}, -}; +use crate::{keygen::AggProvingKey, prover::halo2::Halo2Prover}; pub struct ContinuationProver { stark_prover: StarkProver, diff --git a/crates/sdk/src/prover/stark.rs b/crates/sdk/src/prover/stark.rs index 87f5aa2cd..4d2b94c47 100644 --- a/crates/sdk/src/prover/stark.rs +++ b/crates/sdk/src/prover/stark.rs @@ -6,6 +6,7 @@ use openvm_stark_backend::{prover::types::Proof, Chip}; use crate::{ keygen::{AggStarkProvingKey, AppProvingKey}, prover::{agg::AggStarkProver, app::AppProver}, + verifier::root::types::RootVmVerifierInput, NonRootCommittedExe, RootSC, StdIn, F, SC, }; @@ -50,4 +51,14 @@ impl StarkProver { let app_proof = self.app_prover.generate_app_proof(input); self.agg_prover.generate_agg_proof(app_proof) } + + pub fn generate_root_verifier_input(&self, input: StdIn) -> RootVmVerifierInput + where + VC: VmConfig, + VC::Executor: Chip, + VC::Periphery: Chip, + { + let app_proof = self.app_prover.generate_app_proof(input); + self.agg_prover.generate_root_verifier_input(app_proof) + } }