Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove StateTransitionRunner and StateTransitionVerifier #888

Merged
merged 4 commits into from
Jul 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 15 additions & 9 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 0 additions & 2 deletions bin/citrea/provers/risc0/guest-bitcoin/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 0 additions & 2 deletions bin/citrea/provers/risc0/guest-mock/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion bin/citrea/src/rollup/bitcoin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use bitcoin_da::service::{BitcoinService, DaServiceConfig};
use bitcoin_da::spec::{BitcoinSpec, RollupParams};
use bitcoin_da::verifier::BitcoinVerifier;
use citrea_primitives::{DA_TX_ID_LEADING_ZEROS, ROLLUP_NAME};
use citrea_prover::prover_service::ParallelProverService;
use citrea_risc0_bonsai_adapter::host::Risc0BonsaiHost;
use citrea_risc0_bonsai_adapter::Digest;
use citrea_stf::genesis_config::StorageConfig;
Expand All @@ -16,7 +17,7 @@ use sov_prover_storage_manager::ProverStorageManager;
use sov_rollup_interface::da::DaVerifier;
use sov_rollup_interface::zk::{Zkvm, ZkvmHost};
use sov_state::{DefaultStorageSpec, Storage, ZkStorage};
use sov_stf_runner::{FullNodeConfig, ParallelProverService, ProverConfig};
use sov_stf_runner::{FullNodeConfig, ProverConfig};
use tracing::instrument;

use crate::CitreaRollupBlueprint;
Expand Down
3 changes: 2 additions & 1 deletion bin/citrea/src/rollup/mock.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use async_trait::async_trait;
use citrea_prover::prover_service::ParallelProverService;
use citrea_risc0_bonsai_adapter::host::Risc0BonsaiHost;
use citrea_risc0_bonsai_adapter::Digest;
use citrea_stf::genesis_config::StorageConfig;
Expand All @@ -12,7 +13,7 @@ use sov_modules_stf_blueprint::StfBlueprint;
use sov_prover_storage_manager::ProverStorageManager;
use sov_rollup_interface::zk::{Zkvm, ZkvmHost};
use sov_state::{DefaultStorageSpec, Storage, ZkStorage};
use sov_stf_runner::{FullNodeConfig, ParallelProverService, ProverConfig};
use sov_stf_runner::{FullNodeConfig, ProverConfig};

use crate::CitreaRollupBlueprint;

Expand Down
3 changes: 2 additions & 1 deletion crates/citrea-stf/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
pub mod genesis_config;
mod hooks_impl;
pub mod runtime;
mod verifier;
/// Implements the `StateTransitionVerifier` type for checking the validity of a state transition
pub mod verifier;
use sov_modules_stf_blueprint::StfBlueprint;
use sov_rollup_interface::da::DaVerifier;
use verifier::StateTransitionVerifier;
Expand Down
9 changes: 9 additions & 0 deletions crates/fullnode/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,12 @@ serde = { workspace = true }
serde_json = { workspace = true }
tokio = { workspace = true }
tracing = { workspace = true }

[dev-dependencies]
sha2 = { workspace = true }
tempfile = { workspace = true }

sov-mock-da = { path = "../sovereign-sdk/adapters/mock-da", features = ["native"] }
sov-mock-zkvm = { path = "../sovereign-sdk/adapters/mock-zkvm" }
sov-prover-storage-manager = { path = "../sovereign-sdk/full-node/sov-prover-storage-manager", features = ["test-utils"] }
sov-state = { path = "../sovereign-sdk/module-system/sov-state", features = ["native"] }
5 changes: 5 additions & 0 deletions crates/fullnode/src/runner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -625,6 +625,11 @@ where
});
(sequencer_commitments, zk_proofs)
}

/// Allows to read current state root
pub fn get_state_root(&self) -> &Stf::StateRoot {
&self.state_root
}
}

async fn l1_sync<Da>(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
use citrea_fullnode::CitreaFullnode;
use sov_db::ledger_db::LedgerDB;
use sov_mock_da::{MockAddress, MockDaConfig, MockDaService, MockDaSpec, MockValidityCond};
use sov_mock_zkvm::{MockCodeCommitment, MockZkvm};
use sov_prover_storage_manager::ProverStorageManager;
use sov_state::{ArrayWitness, DefaultStorageSpec};
use sov_state::DefaultStorageSpec;
use sov_stf_runner::{
FullNodeConfig, InitVariant, ParallelProverService, RollupPublicKeys, RpcConfig, RunnerConfig,
StateTransitionRunner, StorageConfig,
FullNodeConfig, InitVariant, RollupPublicKeys, RpcConfig, RunnerConfig, StorageConfig,
};

mod hash_stf;
Expand Down Expand Up @@ -39,22 +39,14 @@ async fn init_and_restart() {
assert_eq!(state_root_after_genesis, state_root_2);
}

type MockProverService = ParallelProverService<
[u8; 32],
ArrayWitness,
MockDaService,
MockZkvm<MockValidityCond>,
HashStf<MockValidityCond>,
>;
fn initialize_runner(
storage_path: &std::path::Path,
init_variant: MockInitVariant,
) -> StateTransitionRunner<
) -> CitreaFullnode<
HashStf<MockValidityCond>,
StorageManager,
MockDaService,
MockZkvm<MockValidityCond>,
MockProverService,
sov_modules_api::default_context::DefaultContext,
> {
let da_storage_path = storage_path.join("da").to_path_buf();
Expand Down Expand Up @@ -111,7 +103,7 @@ fn initialize_runner(
// let vm = MockZkvm::new(MockValidityCond::default());
// let verifier = MockDaVerifier::default();

StateTransitionRunner::new(
CitreaFullnode::new(
rollup_config.runner.unwrap(),
rollup_config.public_keys,
rollup_config.rpc,
Expand All @@ -120,9 +112,8 @@ fn initialize_runner(
stf,
storage_manager,
init_variant,
None,
None,
MockCodeCommitment([1u8; 32]),
10,
)
.unwrap()
}
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
use citrea_fullnode::CitreaFullnode;
use sov_mock_da::{
MockAddress, MockBlob, MockBlock, MockBlockHeader, MockDaConfig, MockDaService, MockDaSpec,
MockDaVerifier, MockValidityCond, PlannedFork,
MockValidityCond, PlannedFork,
};
use sov_mock_zkvm::MockZkvm;
use sov_modules_api::default_context::DefaultContext;
use sov_stf_runner::{
FullNodeConfig, InitVariant, ParallelProverService, ProverGuestRunConfig, RollupPublicKeys,
RpcConfig, RunnerConfig, StateTransitionRunner, StorageConfig,
FullNodeConfig, InitVariant, RollupPublicKeys, RpcConfig, RunnerConfig, StorageConfig,
};

mod hash_stf;
Expand Down Expand Up @@ -154,41 +154,24 @@ async fn runner_execution(
let storage_config = sov_state::config::Config {
path: rollup_storage_path,
};
let mut storage_manager = ProverStorageManager::new(storage_config).unwrap();

let vm = MockZkvm::new(MockValidityCond::default());
let verifier = MockDaVerifier::default();
let prover_config = ProverGuestRunConfig::Skip;

let prover_service = ParallelProverService::new(
vm,
stf.clone(),
verifier,
prover_config,
// Should be ZkStorage, but we don't need it for this test
storage_manager.create_finalized_storage().unwrap(),
1,
let storage_manager = ProverStorageManager::new(storage_config).unwrap();

let mut runner: CitreaFullnode<_, _, _, _, DefaultContext> = CitreaFullnode::new(
rollup_config.runner.unwrap(),
rollup_config.public_keys,
rollup_config.rpc,
da_service,
ledger_db,
stf,
storage_manager,
init_variant,
MockCodeCommitment([1u8; 32]),
10,
)
.expect("Should be able to instiate prover service");

let mut runner: StateTransitionRunner<_, _, _, _, _, DefaultContext> =
StateTransitionRunner::new(
rollup_config.runner.unwrap(),
rollup_config.public_keys,
rollup_config.rpc,
da_service,
ledger_db,
stf,
storage_manager,
init_variant,
Some(prover_service),
None,
MockCodeCommitment([1u8; 32]),
)
.unwrap();
.unwrap();

let before = *runner.get_state_root();
let end = runner.run_in_process().await;
let end = runner.run().await;
assert!(end.is_err());
let after = *runner.get_state_root();

Expand Down
15 changes: 15 additions & 0 deletions crates/prover/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ repository.workspace = true
[dependencies]
# Citrea Deps
citrea-primitives = { path = "../primitives", features = ["native"] }
citrea-stf = { path = "../citrea-stf" }
sequencer-client = { path = "../sequencer-client" }
shared-backup-db = { path = "../shared-backup-db" }

Expand All @@ -24,12 +25,26 @@ sov-stf-runner = { path = "../sovereign-sdk/full-node/sov-stf-runner" }

# 3rd-party deps
anyhow = { workspace = true }
async-trait = { workspace = true }
backoff = { workspace = true }
borsh = { workspace = true }
futures = { workspace = true }
hex = { workspace = true }
jsonrpsee = { workspace = true }
num_cpus = { workspace = true }
rand = { workspace = true }
rayon = { workspace = true }
rs_merkle = { workspace = true }
serde = { workspace = true }
tokio = { workspace = true }
tracing = { workspace = true }

[dev-dependencies]
sha2 = { workspace = true }
tempfile = { workspace = true }

sov-mock-da = { path = "../sovereign-sdk/adapters/mock-da", features = ["native"] }
sov-mock-zkvm = { path = "../sovereign-sdk/adapters/mock-zkvm" }
sov-stf-runner = { path = "../sovereign-sdk/full-node/sov-stf-runner", features = ["mock"] }

citrea-stf = { path = "../citrea-stf", features = ["native"] }
1 change: 1 addition & 0 deletions crates/prover/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use sov_modules_stf_blueprint::StfBlueprint;
use tokio::sync::oneshot;
use tracing::instrument;

pub mod prover_service;
mod runner;
pub use runner::*;

Expand Down
23 changes: 23 additions & 0 deletions crates/prover/src/prover_service/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
use citrea_stf::verifier::StateTransitionVerifier;
use sov_rollup_interface::services::da::DaService;
use sov_rollup_interface::stf::StateTransitionFunction;
use sov_rollup_interface::zk::ZkvmHost;

mod parallel;
pub use parallel::*;

/// Represents the possible modes of execution for a zkVM program
pub enum ProofGenConfig<Stf, Da: DaService, Vm: ZkvmHost>
where
Stf: StateTransitionFunction<Vm::Guest, Da::Spec>,
{
/// Skips proving.
Skip,
/// The simulator runs the rollup verifier logic without even emulating the zkVM
Simulate(StateTransitionVerifier<Stf, Da::Verifier, Vm::Guest>),
/// The executor runs the rollup verification logic in the zkVM, but does not actually
/// produce a zk proof
Execute,
/// The prover runs the rollup verification logic in the zkVM and produces a zk proof
Prover,
}
Loading
Loading