Skip to content

Commit

Permalink
Remove Simulate proof mode
Browse files Browse the repository at this point in the history
  • Loading branch information
yaziciahmet committed Dec 19, 2024
1 parent 48630e1 commit 93f0557
Show file tree
Hide file tree
Showing 8 changed files with 33 additions and 188 deletions.
33 changes: 5 additions & 28 deletions bin/citrea/src/rollup/bitcoin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -58,11 +56,7 @@ impl RollupBlueprint for BitcoinRollup {
type ZkRuntime = Runtime<Self::ZkContext, Self::DaSpec>;
type NativeRuntime = Runtime<Self::NativeContext, Self::DaSpec>;

type ProverService = ParallelProverService<
Self::DaService,
Self::Vm,
StfBlueprint<Self::ZkContext, Self::DaSpec, Self::ZkRuntime>,
>;
type ProverService = ParallelProverService<Self::DaService, Self::Vm>;

fn new(network: Network) -> Self {
use_network_forks(network);
Expand Down Expand Up @@ -261,38 +255,21 @@ impl RollupBlueprint for BitcoinRollup {
&self,
proving_mode: ProverGuestRunConfig,
da_service: &Arc<Self::DaService>,
da_verifier: Self::DaVerifier,
ledger_db: LedgerDB,
keys: RollupPublicKeys,
) -> Self::ProverService {
let vm = Risc0BonsaiHost::new(ledger_db.clone());
// let vm = SP1Host::new(
// include_bytes!("../guests/sp1/batch-prover-bitcoin/elf/zkvm-elf"),
// 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")
}
}
33 changes: 4 additions & 29 deletions bin/citrea/src/rollup/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -44,11 +41,7 @@ impl RollupBlueprint for MockDemoRollup {
type NativeContext = DefaultContext;
type ZkRuntime = Runtime<Self::ZkContext, Self::DaSpec>;
type NativeRuntime = Runtime<Self::NativeContext, Self::DaSpec>;
type ProverService = ParallelProverService<
Self::DaService,
Self::Vm,
StfBlueprint<Self::ZkContext, Self::DaSpec, Self::ZkRuntime>,
>;
type ProverService = ParallelProverService<Self::DaService, Self::Vm>;

fn new(network: Network) -> Self {
use_network_forks(network);
Expand Down Expand Up @@ -138,36 +131,18 @@ impl RollupBlueprint for MockDemoRollup {
&self,
proving_mode: ProverGuestRunConfig,
da_service: &Arc<Self::DaService>,
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(
Expand Down
19 changes: 2 additions & 17 deletions bin/citrea/src/rollup/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand All @@ -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.
Expand Down Expand Up @@ -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(),
Expand All @@ -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.
Expand Down
8 changes: 2 additions & 6 deletions crates/batch-prover/tests/prover_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -289,7 +288,7 @@ async fn test_multiple_parallel_proof_run() {
}

struct TestProver {
prover_service: Arc<ParallelProverService<MockDaService, MockZkvm, MockStf>>,
prover_service: Arc<ParallelProverService<MockDaService, MockZkvm>>,
vm: MockZkvm,
}

Expand All @@ -305,11 +304,8 @@ fn make_new_prover(thread_pool_size: usize, da_service: Arc<MockDaService>) -> T
da_service,
vm.clone(),
proof_mode,
(),
thread_pool_size,
ledger_db,
vec![],
vec![],
)
.expect("Should be able to instantiate Prover service"),
),
Expand Down Expand Up @@ -346,7 +342,7 @@ fn make_transition_data(
}

async fn spawn_prove(
prover_service: Arc<ParallelProverService<MockDaService, MockZkvm, MockStf>>,
prover_service: Arc<ParallelProverService<MockDaService, MockZkvm>>,
) -> oneshot::Receiver<Vec<Proof>> {
let (tx, rx) = oneshot::channel();
tokio::spawn(async move {
Expand Down
13 changes: 2 additions & 11 deletions crates/prover-services/src/lib.rs
Original file line number Diff line number Diff line change
@@ -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<Da, Stf>
where
Da: DaService,
Stf: StateTransitionFunction<Da::Spec>,
{
#[derive(Debug, Clone, Copy)]
pub enum ProofGenMode {
/// Skips proving.
Skip,
/// The simulator runs the rollup verifier logic without even emulating the zkVM
Simulate(StateTransitionVerifier<Stf, Da::Verifier>),
/// The executor runs the rollup verification logic in the zkVM, but does not actually
/// produce a zk proof
Execute,
Expand Down
Loading

0 comments on commit 93f0557

Please sign in to comment.