diff --git a/adapters/mock-zkvm/src/lib.rs b/adapters/mock-zkvm/src/lib.rs index a67bf20da..89e761e12 100644 --- a/adapters/mock-zkvm/src/lib.rs +++ b/adapters/mock-zkvm/src/lib.rs @@ -1,13 +1,15 @@ #![deny(missing_docs)] #![doc = include_str!("../README.md")] +use std::collections::VecDeque; use std::io::Write; use std::sync::{Arc, Condvar, Mutex}; use anyhow::ensure; use borsh::{BorshDeserialize, BorshSerialize}; use serde::{Deserialize, Serialize}; -use sov_rollup_interface::zk::Matches; +use sov_rollup_interface::da::BlockHeaderTrait; +use sov_rollup_interface::zk::{Matches, StateTransitionData, ValidityCondition}; /// A mock commitment to a particular zkVM program. #[derive(Debug, Clone, PartialEq, Eq, BorshDeserialize, BorshSerialize, Serialize, Deserialize)] @@ -91,12 +93,23 @@ impl Notifier { } /// A mock implementing the zkVM trait. -#[derive(Clone, Default)] -pub struct MockZkvm { +#[derive(Clone)] +pub struct MockZkvm { worker_thread_notifier: Notifier, + committed_data: VecDeque>, + validity_condition: ValidityCond, } -impl MockZkvm { +impl MockZkvm { + /// Creates a new MockZkvm + pub fn new(validity_condition: ValidityCond) -> Self { + Self { + worker_thread_notifier: Default::default(), + committed_data: Default::default(), + validity_condition, + } + } + /// Simulates zk proof generation. pub fn make_proof(&self) { // We notify the worket thread. @@ -104,7 +117,7 @@ impl MockZkvm { } } -impl sov_rollup_interface::zk::Zkvm for MockZkvm { +impl sov_rollup_interface::zk::Zkvm for MockZkvm { type CodeCommitment = MockCodeCommitment; type Error = anyhow::Error; @@ -134,10 +147,21 @@ impl sov_rollup_interface::zk::Zkvm for MockZkvm { } } -impl sov_rollup_interface::zk::ZkvmHost for MockZkvm { +impl sov_rollup_interface::zk::ZkvmHost + for MockZkvm +{ type Guest = MockZkGuest; - fn add_hint(&mut self, _item: T) {} + fn add_hint(&mut self, item: T) { + let hint = bincode::serialize(&item).unwrap(); + let proof_info = ProofInfo { + hint, + validity_condition: self.validity_condition, + }; + + let data = bincode::serialize(&proof_info).unwrap(); + self.committed_data.push_back(data) + } fn simulate_with_hints(&mut self) -> Self::Guest { MockZkGuest {} @@ -145,7 +169,32 @@ impl sov_rollup_interface::zk::ZkvmHost for MockZkvm { fn run(&mut self, _with_proof: bool) -> Result { self.worker_thread_notifier.wait(); - Ok(sov_rollup_interface::zk::Proof::Empty) + let data = self.committed_data.pop_front().unwrap_or_default(); + Ok(sov_rollup_interface::zk::Proof::PublicInput(data)) + } + + fn extract_output< + Da: sov_rollup_interface::da::DaSpec, + Root: Serialize + serde::de::DeserializeOwned, + >( + proof: &sov_rollup_interface::zk::Proof, + ) -> Result, Self::Error> { + match proof { + sov_rollup_interface::zk::Proof::PublicInput(pub_input) => { + let data: ProofInfo = bincode::deserialize(pub_input)?; + let st: StateTransitionData = bincode::deserialize(&data.hint)?; + + Ok(sov_rollup_interface::zk::StateTransition { + initial_state_root: st.initial_state_root, + final_state_root: st.final_state_root, + slot_hash: st.da_block_header.hash(), + validity_condition: data.validity_condition, + }) + } + sov_rollup_interface::zk::Proof::Full(_) => { + panic!("Mock DA doesn't generate real proofs") + } + } } } @@ -185,6 +234,12 @@ impl sov_rollup_interface::zk::ZkvmGuest for MockZkGuest { } } +#[derive(Debug, Serialize, Deserialize)] +struct ProofInfo { + hint: Vec, + validity_condition: ValidityCond, +} + #[test] fn test_mock_proof_round_trip() { let proof = MockProof { diff --git a/adapters/risc0/src/host.rs b/adapters/risc0/src/host.rs index 6622fea8d..cb0e43f30 100644 --- a/adapters/risc0/src/host.rs +++ b/adapters/risc0/src/host.rs @@ -1,6 +1,6 @@ //! This module implements the [`ZkvmHost`] trait for the RISC0 VM. -use risc0_zkvm::{ExecutorEnvBuilder, ExecutorImpl, InnerReceipt, Receipt, Session}; +use risc0_zkvm::{ExecutorEnvBuilder, ExecutorImpl, InnerReceipt, Journal, Receipt, Session}; use serde::de::DeserializeOwned; use serde::Serialize; use sov_rollup_interface::zk::{Proof, Zkvm, ZkvmHost}; @@ -89,10 +89,26 @@ impl<'a> ZkvmHost for Risc0Host<'a> { if with_proof { let receipt = self.run()?; let data = bincode::serialize(&receipt)?; - Ok(Proof::Data(data)) + Ok(Proof::Full(data)) } else { - self.run_without_proving()?; - Ok(Proof::Empty) + let session = self.run_without_proving()?; + let data = bincode::serialize(&session.journal)?; + Ok(Proof::PublicInput(data)) + } + } + + fn extract_output( + proof: &Proof, + ) -> Result, Self::Error> { + match proof { + Proof::PublicInput(journal) => { + let journal: Journal = bincode::deserialize(journal)?; + Ok(journal.decode()?) + } + Proof::Full(data) => { + let receipt: Receipt = bincode::deserialize(data)?; + Ok(receipt.journal.decode()?) + } } } } diff --git a/examples/demo-rollup/stf/src/tests/mod.rs b/examples/demo-rollup/stf/src/tests/mod.rs index ef64c3bcc..34cb7d1ce 100644 --- a/examples/demo-rollup/stf/src/tests/mod.rs +++ b/examples/demo-rollup/stf/src/tests/mod.rs @@ -18,8 +18,13 @@ pub(crate) type C = DefaultContext; pub(crate) type Da = MockDaSpec; pub(crate) type RuntimeTest = Runtime; -pub(crate) type StfBlueprintTest = - StfBlueprint>; +pub(crate) type StfBlueprintTest = StfBlueprint< + DefaultContext, + Da, + sov_mock_zkvm::MockZkvm<::ValidityCondition>, + RuntimeTest, + BasicKernel, +>; pub(crate) fn create_storage_manager_for_tests( path: impl AsRef, diff --git a/examples/demo-simple-stf/tests/stf_test.rs b/examples/demo-simple-stf/tests/stf_test.rs index 6f0e9d76c..8cda4e9ef 100644 --- a/examples/demo-simple-stf/tests/stf_test.rs +++ b/examples/demo-simple-stf/tests/stf_test.rs @@ -9,7 +9,7 @@ fn test_stf_success() { let address = MockAddress::from([1; 32]); let stf = &mut CheckHashPreimageStf::::default(); - StateTransitionFunction::::init_chain(stf, (), ()); + StateTransitionFunction::, MockDaSpec>::init_chain(stf, (), ()); let mut blobs = { let incorrect_preimage = vec![1; 32]; @@ -26,7 +26,7 @@ fn test_stf_success() { blob.data.advance(blob.data.total_len()); } - let result = StateTransitionFunction::::apply_slot( + let result = StateTransitionFunction::, MockDaSpec>::apply_slot( stf, &[], (), diff --git a/full-node/sov-stf-runner/src/lib.rs b/full-node/sov-stf-runner/src/lib.rs index e7dae217b..9941da1e6 100644 --- a/full-node/sov-stf-runner/src/lib.rs +++ b/full-node/sov-stf-runner/src/lib.rs @@ -15,7 +15,6 @@ use std::path::Path; #[cfg(feature = "native")] use anyhow::Context; -use borsh::{BorshDeserialize, BorshSerialize}; #[cfg(feature = "native")] pub use config::RpcConfig; #[cfg(feature = "native")] @@ -26,36 +25,15 @@ mod runner; pub use config::{from_toml_path, ProverServiceConfig, RollupConfig, RunnerConfig, StorageConfig}; #[cfg(feature = "native")] pub use runner::*; -use serde::de::DeserializeOwned; -use serde::{Deserialize, Serialize}; -use sov_rollup_interface::da::DaSpec; /// Implements the `StateTransitionVerifier` type for checking the validity of a state transition pub mod verifier; -#[derive(Serialize, BorshDeserialize, BorshSerialize, Deserialize)] -// Prevent serde from generating spurious trait bounds. The correct serde bounds are already enforced by the -// StateTransitionFunction, DA, and Zkvm traits. -#[serde(bound = "StateRoot: Serialize + DeserializeOwned, Witness: Serialize + DeserializeOwned")] -/// Data required to verify a state transition. -pub struct StateTransitionData { - /// The state root before the state transition - pub initial_state_root: StateRoot, - /// The header of the da block that is being processed - pub da_block_header: Da::BlockHeader, - /// The proof of inclusion for all blobs - pub inclusion_proof: Da::InclusionMultiProof, - /// The proof that the provided set of blobs is complete - pub completeness_proof: Da::CompletenessProof, - /// The blobs that are being processed - pub blobs: Vec<::BlobTransaction>, - /// The witness for the state transition - pub state_transition_witness: Witness, -} - #[cfg(feature = "native")] /// Reads json file. -pub fn read_json_file>(path: P) -> anyhow::Result { +pub fn read_json_file>( + path: P, +) -> anyhow::Result { let path_str = path.as_ref().display(); let data = std::fs::read_to_string(&path) diff --git a/full-node/sov-stf-runner/src/prover_service/mod.rs b/full-node/sov-stf-runner/src/prover_service/mod.rs index 320e5f689..4922d9c8c 100644 --- a/full-node/sov-stf-runner/src/prover_service/mod.rs +++ b/full-node/sov-stf-runner/src/prover_service/mod.rs @@ -4,10 +4,9 @@ pub use parallel::ParallelProverService; use serde::Serialize; use sov_rollup_interface::da::DaSpec; use sov_rollup_interface::services::da::DaService; +use sov_rollup_interface::zk::StateTransitionData; use thiserror::Error; -use crate::StateTransitionData; - /// The possible configurations of the prover. pub enum RollupProverConfig { /// Skip proving. diff --git a/full-node/sov-stf-runner/src/prover_service/parallel/mod.rs b/full-node/sov-stf-runner/src/prover_service/parallel/mod.rs index 849bb3c20..7b5cbc9ed 100644 --- a/full-node/sov-stf-runner/src/prover_service/parallel/mod.rs +++ b/full-node/sov-stf-runner/src/prover_service/parallel/mod.rs @@ -8,14 +8,14 @@ use serde::Serialize; use sov_rollup_interface::da::DaSpec; use sov_rollup_interface::services::da::DaService; use sov_rollup_interface::stf::StateTransitionFunction; -use sov_rollup_interface::zk::ZkvmHost; +use sov_rollup_interface::zk::{StateTransitionData, ZkvmHost}; use super::{ProverService, ProverServiceError}; use crate::config::ProverServiceConfig; use crate::verifier::StateTransitionVerifier; use crate::{ ProofGenConfig, ProofProcessingStatus, ProofSubmissionStatus, RollupProverConfig, - StateTransitionData, WitnessSubmissionStatus, + WitnessSubmissionStatus, }; /// Prover service that generates proofs in parallel. diff --git a/full-node/sov-stf-runner/src/prover_service/parallel/prover.rs b/full-node/sov-stf-runner/src/prover_service/parallel/prover.rs index 704cb0e16..3cf293775 100644 --- a/full-node/sov-stf-runner/src/prover_service/parallel/prover.rs +++ b/full-node/sov-stf-runner/src/prover_service/parallel/prover.rs @@ -8,12 +8,11 @@ use serde::Serialize; use sov_rollup_interface::da::{BlockHeaderTrait, DaSpec}; use sov_rollup_interface::services::da::DaService; use sov_rollup_interface::stf::StateTransitionFunction; -use sov_rollup_interface::zk::{Proof, ZkvmHost}; +use sov_rollup_interface::zk::{Proof, StateTransitionData, ZkvmHost}; use super::ProverServiceError; use crate::{ - ProofGenConfig, ProofProcessingStatus, ProofSubmissionStatus, StateTransitionData, - WitnessSubmissionStatus, + ProofGenConfig, ProofProcessingStatus, ProofSubmissionStatus, WitnessSubmissionStatus, }; enum ProverStatus { @@ -223,10 +222,10 @@ where V::PreState: Send + Sync + 'static, { match config.deref() { - ProofGenConfig::Skip => Ok(Proof::Empty), + ProofGenConfig::Skip => Ok(Proof::PublicInput(Vec::default())), ProofGenConfig::Simulate(verifier) => verifier .run_block(vm.simulate_with_hints(), zk_storage) - .map(|_| Proof::Empty) + .map(|_| Proof::PublicInput(Vec::default())) .map_err(|e| anyhow::anyhow!("Guest execution must succeed but failed with {:?}", e)), ProofGenConfig::Execute => vm.run(false), ProofGenConfig::Prover => vm.run(true), diff --git a/full-node/sov-stf-runner/src/runner.rs b/full-node/sov-stf-runner/src/runner.rs index 19d8b31c6..bb215652f 100644 --- a/full-node/sov-stf-runner/src/runner.rs +++ b/full-node/sov-stf-runner/src/runner.rs @@ -7,12 +7,13 @@ use sov_rollup_interface::da::{BlobReaderTrait, BlockHeaderTrait, DaSpec}; use sov_rollup_interface::services::da::{DaService, SlotData}; use sov_rollup_interface::stf::StateTransitionFunction; use sov_rollup_interface::storage::HierarchicalStorageManager; -use sov_rollup_interface::zk::{Zkvm, ZkvmHost}; +use sov_rollup_interface::zk::{StateTransitionData, Zkvm, ZkvmHost}; use tokio::sync::oneshot; use tracing::{debug, info}; use crate::verifier::StateTransitionVerifier; -use crate::{ProofSubmissionStatus, ProverService, RunnerConfig, StateTransitionData}; +use crate::{ProofSubmissionStatus, ProverService, RunnerConfig}; + type StateRoot = >::StateRoot; type GenesisParams = >::GenesisParams; @@ -237,7 +238,7 @@ where StateTransitionData { // TODO(https://github.com/Sovereign-Labs/sovereign-sdk/issues/1247): incorrect pre-state root in case of re-org initial_state_root: self.state_root.clone(), - + final_state_root: slot_result.state_root.clone(), da_block_header: filtered_block.header().clone(), inclusion_proof, completeness_proof, diff --git a/full-node/sov-stf-runner/src/verifier.rs b/full-node/sov-stf-runner/src/verifier.rs index a680ee0f6..a16b9d781 100644 --- a/full-node/sov-stf-runner/src/verifier.rs +++ b/full-node/sov-stf-runner/src/verifier.rs @@ -2,10 +2,7 @@ use std::marker::PhantomData; use sov_rollup_interface::da::{BlockHeaderTrait, DaVerifier}; use sov_rollup_interface::stf::StateTransitionFunction; -use sov_rollup_interface::zk::{StateTransition, Zkvm, ZkvmGuest}; - -use crate::StateTransitionData; - +use sov_rollup_interface::zk::{StateTransition, StateTransitionData, Zkvm, ZkvmGuest}; /// Verifies a state transition pub struct StateTransitionVerifier where diff --git a/full-node/sov-stf-runner/tests/hash_stf.rs b/full-node/sov-stf-runner/tests/hash_stf.rs index 23890ca20..ae0cea12f 100644 --- a/full-node/sov-stf-runner/tests/hash_stf.rs +++ b/full-node/sov-stf-runner/tests/hash_stf.rs @@ -196,11 +196,10 @@ pub fn get_result_from_blocks( let stf = HashStf::::new(); let (genesis_state_root, mut storage) = - as StateTransitionFunction>::init_chain( - &stf, - storage, - genesis_params.to_vec(), - ); + as StateTransitionFunction< + MockZkvm, + MockDaSpec, + >>::init_chain(&stf, storage, genesis_params.to_vec()); let mut state_root = genesis_state_root; @@ -209,15 +208,18 @@ pub fn get_result_from_blocks( for block in blocks { let mut blobs = block.blobs.clone(); - let result = - as StateTransitionFunction>::apply_slot::<&mut Vec>( - &stf, - &state_root, - storage, - ArrayWitness::default(), - &block.header, - &block.validity_cond, - &mut blobs); + let result = as StateTransitionFunction< + MockZkvm, + MockDaSpec, + >>::apply_slot::<&mut Vec>( + &stf, + &state_root, + storage, + ArrayWitness::default(), + &block.header, + &block.validity_cond, + &mut blobs, + ); state_root = result.state_root; storage = result.change_set; diff --git a/full-node/sov-stf-runner/tests/prover_tests.rs b/full-node/sov-stf-runner/tests/prover_tests.rs index f8459a597..5fd82ac26 100644 --- a/full-node/sov-stf-runner/tests/prover_tests.rs +++ b/full-node/sov-stf-runner/tests/prover_tests.rs @@ -3,11 +3,11 @@ use sov_mock_da::{ }; use sov_mock_zkvm::MockZkvm; use sov_rollup_interface::da::Time; +use sov_rollup_interface::zk::StateTransitionData; use sov_stf_runner::mock::MockStf; use sov_stf_runner::{ ParallelProverService, ProofProcessingStatus, ProofSubmissionStatus, ProverService, - ProverServiceConfig, ProverServiceError, RollupProverConfig, StateTransitionData, - WitnessSubmissionStatus, + ProverServiceConfig, ProverServiceError, RollupProverConfig, WitnessSubmissionStatus, }; #[tokio::test] @@ -163,9 +163,14 @@ async fn test_generate_multiple_proofs_for_the_same_witness() -> Result<(), anyh } struct TestProver { - prover_service: - ParallelProverService<[u8; 0], Vec, MockDaService, MockZkvm, MockStf>, - vm: MockZkvm, + prover_service: ParallelProverService< + [u8; 0], + Vec, + MockDaService, + MockZkvm, + MockStf, + >, + vm: MockZkvm, num_worker_threads: usize, } @@ -175,7 +180,7 @@ async fn wait_for_proof_proof_da_submission( [u8; 0], Vec, MockDaService, - MockZkvm, + MockZkvm, MockStf, >, ) { @@ -190,7 +195,7 @@ async fn wait_for_proof_proof_da_submission( fn make_new_prover() -> TestProver { let num_threads = num_cpus::get(); - let vm = MockZkvm::default(); + let vm = MockZkvm::new(MockValidityCond::default()); let prover_config = RollupProverConfig::Execute; let zk_stf = MockStf::::default(); @@ -217,6 +222,7 @@ fn make_transition_data( ) -> StateTransitionData<[u8; 0], Vec, MockDaSpec> { StateTransitionData { initial_state_root: [], + final_state_root: [], da_block_header: MockBlockHeader { prev_hash: [0; 32].into(), hash: header_hash, diff --git a/full-node/sov-stf-runner/tests/runner_initialization_tests.rs b/full-node/sov-stf-runner/tests/runner_initialization_tests.rs index 9806b4fd5..61aad564e 100644 --- a/full-node/sov-stf-runner/tests/runner_initialization_tests.rs +++ b/full-node/sov-stf-runner/tests/runner_initialization_tests.rs @@ -16,7 +16,8 @@ mod hash_stf; use hash_stf::HashStf; -type MockInitVariant = InitVariant, MockZkvm, MockDaSpec>; +type MockInitVariant = + InitVariant, MockZkvm, MockDaSpec>; type S = DefaultStorageSpec; type StorageManager = ProverStorageManager; @@ -48,7 +49,7 @@ type MockProverService = ParallelProverService< [u8; 32], ArrayWitness, MockDaService, - MockZkvm, + MockZkvm, HashStf, >; fn initialize_runner( @@ -58,7 +59,7 @@ fn initialize_runner( HashStf, StorageManager, MockDaService, - MockZkvm, + MockZkvm, MockProverService, > { let address = MockAddress::new([11u8; 32]); @@ -92,7 +93,7 @@ fn initialize_runner( }; let mut storage_manager = ProverStorageManager::new(storage_config).unwrap(); - let vm = MockZkvm::default(); + let vm = MockZkvm::new(MockValidityCond::default()); let verifier = MockDaVerifier::default(); let prover_config = RollupProverConfig::Prove; diff --git a/full-node/sov-stf-runner/tests/runner_reorg_tests.rs b/full-node/sov-stf-runner/tests/runner_reorg_tests.rs index ce952c1cd..ed1c163fb 100644 --- a/full-node/sov-stf-runner/tests/runner_reorg_tests.rs +++ b/full-node/sov-stf-runner/tests/runner_reorg_tests.rs @@ -18,7 +18,8 @@ use sov_rollup_interface::storage::HierarchicalStorageManager; use sov_state::storage::NativeStorage; use sov_state::{ProverStorage, Storage}; -type MockInitVariant = InitVariant, MockZkvm, MockDaSpec>; +type MockInitVariant = + InitVariant, MockZkvm, MockDaSpec>; #[tokio::test] async fn test_simple_reorg_case() { let tmpdir = tempfile::tempdir().unwrap(); @@ -146,7 +147,7 @@ async fn runner_execution( }; let mut storage_manager = ProverStorageManager::new(storage_config).unwrap(); - let vm = MockZkvm::default(); + let vm = MockZkvm::new(MockValidityCond::default()); let verifier = MockDaVerifier::default(); let prover_config = RollupProverConfig::Skip; diff --git a/module-system/module-implementations/integration-tests/src/chain_state/tests.rs b/module-system/module-implementations/integration-tests/src/chain_state/tests.rs index d7478fc19..6eff4f0e5 100644 --- a/module-system/module-implementations/integration-tests/src/chain_state/tests.rs +++ b/module-system/module-implementations/integration-tests/src/chain_state/tests.rs @@ -26,8 +26,13 @@ fn test_simple_value_setter_with_chain_state() { let tmpdir = tempfile::tempdir().unwrap(); let storage = new_orphan_storage(tmpdir.path()).unwrap(); - let stf = - StfBlueprint::, BasicKernel>::new(); + let stf = StfBlueprint::< + C, + MockDaSpec, + MockZkvm, + TestRuntime, + BasicKernel, + >::new(); let test_runtime = TestRuntime::::default(); let value_setter_messages = ValueSetterMessages::default(); diff --git a/module-system/module-implementations/sov-attester-incentives/src/tests/challenger.rs b/module-system/module-implementations/sov-attester-incentives/src/tests/challenger.rs index 54b75c001..3566e3bbc 100644 --- a/module-system/module-implementations/sov-attester-incentives/src/tests/challenger.rs +++ b/module-system/module-implementations/sov-attester-incentives/src/tests/challenger.rs @@ -137,7 +137,7 @@ fn invalid_proof_helper( challenger_address: sov_modules_api::Address, module: &crate::AttesterIncentives< DefaultContext, - MockZkvm, + MockZkvm, MockDaSpec, MockValidityCondChecker, >, diff --git a/module-system/module-implementations/sov-attester-incentives/src/tests/helpers.rs b/module-system/module-implementations/sov-attester-incentives/src/tests/helpers.rs index a234dcd92..08544bf3f 100644 --- a/module-system/module-implementations/sov-attester-incentives/src/tests/helpers.rs +++ b/module-system/module-implementations/sov-attester-incentives/src/tests/helpers.rs @@ -77,7 +77,12 @@ pub(crate) fn create_bank_config_with_token( pub(crate) fn setup( working_set: &mut WorkingSet, ) -> ( - AttesterIncentives>, + AttesterIncentives< + C, + MockZkvm, + MockDaSpec, + MockValidityCondChecker, + >, Address, Address, Address, @@ -111,7 +116,7 @@ pub(crate) fn setup( // initialize prover incentives let module = AttesterIncentives::< C, - MockZkvm, + MockZkvm, MockDaSpec, MockValidityCondChecker, >::default(); @@ -151,7 +156,7 @@ pub(crate) struct ExecutionSimulationVars { /// with associated bonding proofs, as long as the last state root pub(crate) fn execution_simulation>( rounds: u8, - module: &AttesterIncentives, + module: &AttesterIncentives, MockDaSpec, Checker>, storage: &ProverStorage, attester_address: ::Address, mut working_set: WorkingSet, diff --git a/module-system/module-implementations/sov-prover-incentives/src/tests.rs b/module-system/module-implementations/sov-prover-incentives/src/tests.rs index 186a2909d..64c4c777f 100644 --- a/module-system/module-implementations/sov-prover-incentives/src/tests.rs +++ b/module-system/module-implementations/sov-prover-incentives/src/tests.rs @@ -1,3 +1,4 @@ +use sov_mock_da::MockValidityCond; use sov_mock_zkvm::{MockCodeCommitment, MockProof, MockZkvm}; use sov_modules_api::default_context::DefaultContext; use sov_modules_api::digest::Digest; @@ -42,7 +43,13 @@ fn create_bank_config() -> ( ) } -fn setup(working_set: &mut WorkingSet) -> (ProverIncentives, Address, Address) { +fn setup( + working_set: &mut WorkingSet, +) -> ( + ProverIncentives>, + Address, + Address, +) { // Initialize bank let (bank_config, prover_address, sequencer) = create_bank_config(); let bank = sov_bank::Bank::::default(); @@ -55,7 +62,7 @@ fn setup(working_set: &mut WorkingSet) -> (ProverIncentives, Add ); // initialize prover incentives - let module = ProverIncentives::::default(); + let module = ProverIncentives::>::default(); let config = crate::ProverIncentivesConfig { bonding_token_address: token_address, minimum_bond: BOND_AMOUNT, diff --git a/module-system/module-schemas/build.rs b/module-system/module-schemas/build.rs index b219e3292..6263ac243 100644 --- a/module-system/module-schemas/build.rs +++ b/module-system/module-schemas/build.rs @@ -2,6 +2,7 @@ use std::fs::File; use std::io::{self, Write}; use sov_mock_da::verifier::MockDaSpec; +use sov_mock_da::MockValidityCond; use sov_mock_zkvm::MockZkvm; use sov_modules_api::default_context::DefaultContext as C; use sov_modules_api::ModuleCallJsonSchema; @@ -10,7 +11,7 @@ fn main() -> io::Result<()> { store_json_schema::>("sov-bank.json")?; store_json_schema::>("sov-accounts.json")?; store_json_schema::>("sov-value-setter.json")?; - store_json_schema::>( + store_json_schema::>>( "sov-prover-incentives.json", )?; store_json_schema::>( diff --git a/rollup-interface/src/state_machine/zk/mod.rs b/rollup-interface/src/state_machine/zk/mod.rs index 5df398e96..f8f37a439 100644 --- a/rollup-interface/src/state_machine/zk/mod.rs +++ b/rollup-interface/src/state_machine/zk/mod.rs @@ -19,10 +19,10 @@ use crate::da::DaSpec; /// The ZK proof generated by the [`ZkvmHost::run`] method. #[derive(Clone)] pub enum Proof { - /// Proof generation was skipped. - Empty, + /// Only public input was generated. + PublicInput(Vec), /// The serialized ZK proof. - Data(Vec), + Full(Vec), } /// A trait implemented by the prover ("host") of a zkVM program. @@ -44,6 +44,11 @@ pub trait ZkvmHost: Zkvm + Clone { /// creating a SNARK of correct execution. Running the true guest binary comes /// with some mild performance overhead and is not as easy to debug as [`simulate_with_hints`](ZkvmHost::simulate_with_hints). fn run(&mut self, with_proof: bool) -> Result; + + /// Extracts public input form the proof. + fn extract_output( + proof: &Proof, + ) -> Result, Self::Error>; } /// A Zk proof system capable of proving and verifying arbitrary Rust code @@ -140,3 +145,25 @@ pub trait Matches { /// Check if two items are a match fn matches(&self, other: &T) -> bool; } + +#[derive(Serialize, BorshDeserialize, BorshSerialize, Deserialize)] +// Prevent serde from generating spurious trait bounds. The correct serde bounds are already enforced by the +// StateTransitionFunction, DA, and Zkvm traits. +#[serde(bound = "StateRoot: Serialize + DeserializeOwned, Witness: Serialize + DeserializeOwned")] +/// Data required to verify a state transition. +pub struct StateTransitionData { + /// The state root before the state transition + pub initial_state_root: StateRoot, + /// The state root after the state transition + pub final_state_root: StateRoot, + /// The header of the da block that is being processed + pub da_block_header: Da::BlockHeader, + /// The proof of inclusion for all blobs + pub inclusion_proof: Da::InclusionMultiProof, + /// The proof that the provided set of blobs is complete + pub completeness_proof: Da::CompletenessProof, + /// The blobs that are being processed + pub blobs: Vec<::BlobTransaction>, + /// The witness for the state transition + pub state_transition_witness: Witness, +}