diff --git a/bin/citrea/src/rollup/bitcoin.rs b/bin/citrea/src/rollup/bitcoin.rs index eee4ca37d..b080bcb75 100644 --- a/bin/citrea/src/rollup/bitcoin.rs +++ b/bin/citrea/src/rollup/bitcoin.rs @@ -8,24 +8,22 @@ use bitcoin_da::spec::{BitcoinSpec, RollupParams}; use bitcoin_da::verifier::BitcoinVerifier; use citrea_common::rpc::register_healthcheck_rpc; use citrea_common::tasks::manager::TaskManager; -use citrea_common::{FullNodeConfig, RollupPublicKeys}; +use citrea_common::FullNodeConfig; use citrea_primitives::forks::use_network_forks; use citrea_primitives::{TO_BATCH_PROOF_PREFIX, TO_LIGHT_CLIENT_PREFIX}; use citrea_risc0_adapter::host::Risc0BonsaiHost; // use citrea_sp1::host::SP1Host; use citrea_stf::genesis_config::StorageConfig; use citrea_stf::runtime::Runtime; -use citrea_stf::verifier::StateTransitionVerifier; use prover_services::{ParallelProverService, ProofGenMode}; use sov_db::ledger_db::LedgerDB; use sov_modules_api::default_context::{DefaultContext, ZkDefaultContext}; use sov_modules_api::{Address, SpecId, Zkvm}; use sov_modules_rollup_blueprint::RollupBlueprint; -use sov_modules_stf_blueprint::StfBlueprint; use sov_prover_storage_manager::{ProverStorageManager, SnapshotManager}; use sov_rollup_interface::da::DaVerifier; use sov_rollup_interface::services::da::SenderWithNotifier; -use sov_state::{ProverStorage, ZkStorage}; +use sov_state::ProverStorage; use sov_stf_runner::ProverGuestRunConfig; use tokio::sync::broadcast; use tokio::sync::mpsc::unbounded_channel; @@ -58,11 +56,7 @@ impl RollupBlueprint for BitcoinRollup { type ZkRuntime = Runtime; type NativeRuntime = Runtime; - type ProverService = ParallelProverService< - Self::DaService, - Self::Vm, - StfBlueprint, - >; + type ProverService = ParallelProverService; fn new(network: Network) -> Self { use_network_forks(network); @@ -261,9 +255,7 @@ impl RollupBlueprint for BitcoinRollup { &self, proving_mode: ProverGuestRunConfig, da_service: &Arc, - da_verifier: Self::DaVerifier, ledger_db: LedgerDB, - keys: RollupPublicKeys, ) -> Self::ProverService { let vm = Risc0BonsaiHost::new(ledger_db.clone()); // let vm = SP1Host::new( @@ -271,28 +263,13 @@ impl RollupBlueprint for BitcoinRollup { // ledger_db.clone(), // ); - let zk_stf = StfBlueprint::new(); - let zk_storage = ZkStorage::new(); - let proof_mode = match proving_mode { ProverGuestRunConfig::Skip => ProofGenMode::Skip, - ProverGuestRunConfig::Simulate => { - let stf_verifier = StateTransitionVerifier::new(zk_stf, da_verifier); - ProofGenMode::Simulate(stf_verifier) - } ProverGuestRunConfig::Execute => ProofGenMode::Execute, ProverGuestRunConfig::Prove => ProofGenMode::Prove, }; - ParallelProverService::new_from_env( - da_service.clone(), - vm, - proof_mode, - zk_storage, - ledger_db, - keys.sequencer_public_key.clone(), - keys.sequencer_da_pub_key, - ) - .expect("Should be able to instantiate prover service") + ParallelProverService::new_from_env(da_service.clone(), vm, proof_mode, ledger_db) + .expect("Should be able to instantiate prover service") } } diff --git a/bin/citrea/src/rollup/mock.rs b/bin/citrea/src/rollup/mock.rs index c01a2452a..f6244a24a 100644 --- a/bin/citrea/src/rollup/mock.rs +++ b/bin/citrea/src/rollup/mock.rs @@ -4,22 +4,19 @@ use std::sync::Arc; use async_trait::async_trait; use citrea_common::rpc::register_healthcheck_rpc; use citrea_common::tasks::manager::TaskManager; -use citrea_common::{FullNodeConfig, RollupPublicKeys}; +use citrea_common::FullNodeConfig; use citrea_primitives::forks::use_network_forks; // use citrea_sp1::host::SP1Host; use citrea_risc0_adapter::host::Risc0BonsaiHost; use citrea_stf::genesis_config::StorageConfig; use citrea_stf::runtime::Runtime; -use citrea_stf::verifier::StateTransitionVerifier; use prover_services::{ParallelProverService, ProofGenMode}; use sov_db::ledger_db::LedgerDB; use sov_mock_da::{MockDaConfig, MockDaService, MockDaSpec, MockDaVerifier}; use sov_modules_api::default_context::{DefaultContext, ZkDefaultContext}; use sov_modules_api::{Address, Spec, SpecId, Zkvm}; use sov_modules_rollup_blueprint::RollupBlueprint; -use sov_modules_stf_blueprint::StfBlueprint; use sov_prover_storage_manager::ProverStorageManager; -use sov_state::ZkStorage; use sov_stf_runner::ProverGuestRunConfig; use tokio::sync::broadcast; @@ -44,11 +41,7 @@ impl RollupBlueprint for MockDemoRollup { type NativeContext = DefaultContext; type ZkRuntime = Runtime; type NativeRuntime = Runtime; - type ProverService = ParallelProverService< - Self::DaService, - Self::Vm, - StfBlueprint, - >; + type ProverService = ParallelProverService; fn new(network: Network) -> Self { use_network_forks(network); @@ -138,36 +131,18 @@ impl RollupBlueprint for MockDemoRollup { &self, proving_mode: ProverGuestRunConfig, da_service: &Arc, - da_verifier: Self::DaVerifier, ledger_db: LedgerDB, - keys: RollupPublicKeys, ) -> Self::ProverService { let vm = Risc0BonsaiHost::new(ledger_db.clone()); - let zk_stf = StfBlueprint::new(); - let zk_storage = ZkStorage::new(); - let proof_mode = match proving_mode { ProverGuestRunConfig::Skip => ProofGenMode::Skip, - ProverGuestRunConfig::Simulate => { - let stf_verifier = StateTransitionVerifier::new(zk_stf, da_verifier); - ProofGenMode::Simulate(stf_verifier) - } ProverGuestRunConfig::Execute => ProofGenMode::Execute, ProverGuestRunConfig::Prove => ProofGenMode::Prove, }; - ParallelProverService::new( - da_service.clone(), - vm, - proof_mode, - zk_storage, - 1, - ledger_db, - keys.sequencer_public_key.clone(), - keys.sequencer_da_pub_key, - ) - .expect("Should be able to instantiate prover service") + ParallelProverService::new(da_service.clone(), vm, proof_mode, 1, ledger_db) + .expect("Should be able to instantiate prover service") } fn create_storage_manager( diff --git a/bin/citrea/src/rollup/mod.rs b/bin/citrea/src/rollup/mod.rs index dbc0ab7b6..9a31b6944 100644 --- a/bin/citrea/src/rollup/mod.rs +++ b/bin/citrea/src/rollup/mod.rs @@ -309,8 +309,6 @@ pub trait CitreaRollupBlueprint: RollupBlueprint { .create_da_service(&rollup_config, true, &mut task_manager) .await?; - let da_verifier = self.create_da_verifier(); - // Migrate before constructing ledger_db instance so that no lock is present. let migrator = LedgerDBMigrator::new( rollup_config.storage.path.as_path(), @@ -326,13 +324,7 @@ pub trait CitreaRollupBlueprint: RollupBlueprint { let ledger_db = self.create_ledger_db(&rocksdb_config); let prover_service = self - .create_prover_service( - prover_config.proving_mode, - &da_service, - da_verifier, - ledger_db.clone(), - rollup_config.public_keys.clone(), - ) + .create_prover_service(prover_config.proving_mode, &da_service, ledger_db.clone()) .await; // TODO: Double check what kind of storage needed here. @@ -446,7 +438,6 @@ pub trait CitreaRollupBlueprint: RollupBlueprint { let da_service = self .create_da_service(&rollup_config, true, &mut task_manager) .await?; - let da_verifier = self.create_da_verifier(); let rocksdb_config = RocksdbConfig::new( rollup_config.storage.path.as_path(), @@ -456,13 +447,7 @@ pub trait CitreaRollupBlueprint: RollupBlueprint { let ledger_db = self.create_ledger_db(&rocksdb_config); let prover_service = self - .create_prover_service( - prover_config.proving_mode, - &da_service, - da_verifier, - ledger_db.clone(), - rollup_config.public_keys.clone(), - ) + .create_prover_service(prover_config.proving_mode, &da_service, ledger_db.clone()) .await; // TODO: Double check what kind of storage needed here. diff --git a/crates/batch-prover/tests/prover_tests.rs b/crates/batch-prover/tests/prover_tests.rs index 01ebc2169..0cc6ff093 100644 --- a/crates/batch-prover/tests/prover_tests.rs +++ b/crates/batch-prover/tests/prover_tests.rs @@ -9,7 +9,6 @@ use sov_mock_da::{MockAddress, MockBlockHeader, MockDaService, MockDaSpec, MockH use sov_mock_zkvm::MockZkvm; use sov_rollup_interface::da::Time; use sov_rollup_interface::zk::{BatchProofCircuitInput, Proof, ZkvmHost}; -use sov_stf_runner::mock::MockStf; use sov_stf_runner::ProverService; use tokio::sync::oneshot; @@ -289,7 +288,7 @@ async fn test_multiple_parallel_proof_run() { } struct TestProver { - prover_service: Arc>, + prover_service: Arc>, vm: MockZkvm, } @@ -305,11 +304,8 @@ fn make_new_prover(thread_pool_size: usize, da_service: Arc) -> T da_service, vm.clone(), proof_mode, - (), thread_pool_size, ledger_db, - vec![], - vec![], ) .expect("Should be able to instantiate Prover service"), ), @@ -346,7 +342,7 @@ fn make_transition_data( } async fn spawn_prove( - prover_service: Arc>, + prover_service: Arc>, ) -> oneshot::Receiver> { let (tx, rx) = oneshot::channel(); tokio::spawn(async move { diff --git a/crates/prover-services/src/lib.rs b/crates/prover-services/src/lib.rs index 047d152ac..9a115f655 100644 --- a/crates/prover-services/src/lib.rs +++ b/crates/prover-services/src/lib.rs @@ -1,19 +1,10 @@ -use citrea_stf::verifier::StateTransitionVerifier; -use sov_rollup_interface::services::da::DaService; -use sov_rollup_interface::stf::StateTransitionFunction; - mod parallel; pub use parallel::*; -pub enum ProofGenMode -where - Da: DaService, - Stf: StateTransitionFunction, -{ +#[derive(Debug, Clone, Copy)] +pub enum ProofGenMode { /// Skips proving. Skip, - /// The simulator runs the rollup verifier logic without even emulating the zkVM - Simulate(StateTransitionVerifier), /// The executor runs the rollup verification logic in the zkVM, but does not actually /// produce a zk proof Execute, diff --git a/crates/prover-services/src/parallel/mod.rs b/crates/prover-services/src/parallel/mod.rs index fd299fd84..d08dc3dd7 100644 --- a/crates/prover-services/src/parallel/mod.rs +++ b/crates/prover-services/src/parallel/mod.rs @@ -1,14 +1,11 @@ -use std::ops::DerefMut; use std::sync::Arc; use async_trait::async_trait; -use citrea_primitives::forks::get_forks; use futures::future; use sov_db::ledger_db::LedgerDB; use sov_rollup_interface::da::DaData; use sov_rollup_interface::services::da::DaService; -use sov_rollup_interface::stf::StateTransitionFunction; -use sov_rollup_interface::zk::{Proof, ZkvmGuest, ZkvmHost}; +use sov_rollup_interface::zk::{Proof, ZkvmHost}; use sov_stf_runner::ProverService; use tokio::sync::{oneshot, Mutex}; use tracing::{info, warn}; @@ -20,45 +17,34 @@ pub(crate) type Assumptions = Vec>; pub(crate) type ProofData = (Input, Assumptions); /// Prover service that generates proofs in parallel. -pub struct ParallelProverService +pub struct ParallelProverService where Da: DaService, Vm: ZkvmHost + 'static, - Stf: StateTransitionFunction + Send + Sync + 'static, - Stf::PreState: Clone + Send + Sync + 'static, { thread_pool: rayon::ThreadPool, - proof_mode: Arc>>, + proof_mode: ProofGenMode, da_service: Arc, vm: Vm, - zk_storage: Stf::PreState, _ledger_db: LedgerDB, proof_queue: Arc>>, - sequencer_public_key: Vec, - sequencer_da_public_key: Vec, } -impl ParallelProverService +impl ParallelProverService where Da: DaService, Vm: ZkvmHost, - Stf: StateTransitionFunction + Send + Sync, - Stf::PreState: Clone + Send + Sync, { /// Creates a new prover. - #[allow(clippy::too_many_arguments)] pub fn new( da_service: Arc, vm: Vm, - proof_mode: ProofGenMode, - zk_storage: Stf::PreState, + proof_mode: ProofGenMode, thread_pool_size: usize, _ledger_db: LedgerDB, - sequencer_public_key: Vec, - sequencer_da_public_key: Vec, ) -> anyhow::Result { assert!( thread_pool_size > 0, @@ -69,9 +55,6 @@ where ProofGenMode::Skip => { tracing::info!("Prover is configured to skip proving"); } - ProofGenMode::Simulate(_) => { - tracing::info!("Prover is configured to simulate proving"); - } ProofGenMode::Execute => { tracing::info!("Prover is configured to execute proving"); } @@ -87,14 +70,11 @@ where Ok(Self { thread_pool, - proof_mode: Arc::new(Mutex::new(proof_mode)), + proof_mode, da_service, vm, - zk_storage, _ledger_db, proof_queue: Arc::new(Mutex::new(vec![])), - sequencer_public_key, - sequencer_da_public_key, }) } @@ -103,27 +83,15 @@ where pub fn new_from_env( da_service: Arc, vm: Vm, - proof_mode: ProofGenMode, - zk_storage: Stf::PreState, + proof_mode: ProofGenMode, _ledger_db: LedgerDB, - sequencer_public_key: Vec, - sequencer_da_public_key: Vec, ) -> anyhow::Result { let thread_pool_size = std::env::var("PARALLEL_PROOF_LIMIT") .expect("PARALLEL_PROOF_LIMIT must be set") .parse::() .expect("PARALLEL_PROOF_LIMIT must be valid unsigned number"); - Self::new( - da_service, - vm, - proof_mode, - zk_storage, - thread_pool_size, - _ledger_db, - sequencer_public_key, - sequencer_da_public_key, - ) + Self::new(da_service, vm, proof_mode, thread_pool_size, _ledger_db) } async fn prove_all(&self, elf: Vec, proof_queue: Vec) -> Vec { @@ -171,10 +139,7 @@ where async fn prove_one(&self, elf: Vec, (input, assumptions): ProofData) -> Proof { let mut vm = self.vm.clone(); - let zk_storage = self.zk_storage.clone(); - let proof_mode = self.proof_mode.clone(); - let sequencer_public_key = self.sequencer_public_key.clone(); - let sequencer_da_public_key = self.sequencer_da_public_key.clone(); + let proof_mode = self.proof_mode; vm.add_hint(input); for assumption in assumptions { @@ -183,15 +148,7 @@ where let (tx, rx) = oneshot::channel(); self.thread_pool.spawn(move || { - let proof = make_proof( - vm, - elf, - zk_storage, - proof_mode, - &sequencer_public_key, - &sequencer_da_public_key, - ) - .expect("Proof creation must not fail"); + let proof = make_proof(vm, elf, proof_mode).expect("Proof creation must not fail"); let _ = tx.send(proof); }); @@ -208,12 +165,10 @@ where } #[async_trait] -impl ProverService for ParallelProverService +impl ProverService for ParallelProverService where Da: DaService, Vm: ZkvmHost, - Stf: StateTransitionFunction + Send + Sync, - Stf::PreState: Clone + Send + Sync, { type DaService = Da; @@ -224,7 +179,7 @@ where async fn prove(&self, elf: Vec) -> anyhow::Result> { let mut proof_queue = self.proof_queue.lock().await; - if let ProofGenMode::Skip = *self.proof_mode.lock().await { + if let ProofGenMode::Skip = self.proof_mode { tracing::debug!("Skipped proving {} proofs", proof_queue.len()); proof_queue.clear(); return Ok(vec![]); @@ -264,47 +219,18 @@ where } } -fn make_proof( +fn make_proof( mut vm: Vm, elf: Vec, - zk_storage: Stf::PreState, - proof_mode: Arc>>, - sequencer_public_key: &[u8], - sequencer_da_public_key: &[u8], + proof_mode: ProofGenMode, ) -> Result where - Da: DaService, Vm: ZkvmHost, - Stf: StateTransitionFunction + Send + Sync, - Stf::PreState: Send + Sync, { - let mut proof_mode = proof_mode.blocking_lock(); - match proof_mode.deref_mut() { + match proof_mode { ProofGenMode::Skip => Ok(Vec::default()), - ProofGenMode::Simulate(ref mut verifier) => { - let guest = vm.simulate_with_hints(); - let data = guest.read_from_host(); - verifier - .run_sequencer_commitments_in_da_slot( - data, - zk_storage, - sequencer_public_key, - sequencer_da_public_key, - get_forks(), - ) - .map(|_| Vec::default()) - .map_err(|e| { - anyhow::anyhow!("Guest execution must succeed but failed with {:?}", e) - }) - } // If not skip or simulate, we have to drop the lock manually to allow parallel proving - ProofGenMode::Execute => { - drop(proof_mode); - vm.run(elf, false) - } - ProofGenMode::Prove => { - drop(proof_mode); - vm.run(elf, true) - } + ProofGenMode::Execute => vm.run(elf, false), + ProofGenMode::Prove => vm.run(elf, true), } } diff --git a/crates/sovereign-sdk/full-node/sov-stf-runner/src/prover_service/mod.rs b/crates/sovereign-sdk/full-node/sov-stf-runner/src/prover_service/mod.rs index 224418904..071198776 100644 --- a/crates/sovereign-sdk/full-node/sov-stf-runner/src/prover_service/mod.rs +++ b/crates/sovereign-sdk/full-node/sov-stf-runner/src/prover_service/mod.rs @@ -10,8 +10,6 @@ use thiserror::Error; pub enum ProverGuestRunConfig { /// Skip proving. Skip, - /// Run the rollup verification logic inside the current process. - Simulate, /// Run the rollup verifier in a zkVM executor. Execute, /// Run the rollup verifier and create a SNARK of execution. @@ -26,7 +24,6 @@ impl<'de> Deserialize<'de> for ProverGuestRunConfig { let s = ::deserialize(deserializer)?; match s.as_str() { "skip" => Ok(ProverGuestRunConfig::Skip), - "simulate" => Ok(ProverGuestRunConfig::Simulate), "execute" => Ok(ProverGuestRunConfig::Execute), "prove" => Ok(ProverGuestRunConfig::Prove), _ => Err(serde::de::Error::custom("invalid prover guest run config")), diff --git a/crates/sovereign-sdk/module-system/sov-modules-rollup-blueprint/src/lib.rs b/crates/sovereign-sdk/module-system/sov-modules-rollup-blueprint/src/lib.rs index 5f019885c..10c244f4f 100644 --- a/crates/sovereign-sdk/module-system/sov-modules-rollup-blueprint/src/lib.rs +++ b/crates/sovereign-sdk/module-system/sov-modules-rollup-blueprint/src/lib.rs @@ -6,7 +6,7 @@ use std::sync::Arc; use async_trait::async_trait; use citrea_common::tasks::manager::TaskManager; -use citrea_common::{FullNodeConfig, RollupPublicKeys}; +use citrea_common::FullNodeConfig; use sov_db::ledger_db::LedgerDB; use sov_db::rocks_db_config::RocksdbConfig; use sov_modules_api::{Context, DaSpec, Spec}; @@ -125,9 +125,7 @@ pub trait RollupBlueprint: Sized + Send + Sync { &self, proving_mode: ProverGuestRunConfig, da_service: &Arc, - da_verifier: Self::DaVerifier, ledger_db: LedgerDB, - keys: RollupPublicKeys, ) -> Self::ProverService; /// Creates instance of [`Self::StorageManager`].