sov_stf_runner/
lib.rs

1#![deny(missing_docs)]
2#![doc = include_str!("../README.md")]
3
4#[cfg(feature = "native")]
5mod config;
6
7#[cfg(feature = "native")]
8use std::path::Path;
9
10#[cfg(feature = "native")]
11use anyhow::Context;
12use borsh::{BorshDeserialize, BorshSerialize};
13#[cfg(feature = "native")]
14pub use config::RpcConfig;
15#[cfg(feature = "native")]
16mod runner;
17#[cfg(feature = "native")]
18pub use config::{from_toml_path, RollupConfig, RunnerConfig, StorageConfig};
19#[cfg(feature = "native")]
20pub use runner::*;
21use serde::de::DeserializeOwned;
22use serde::{Deserialize, Serialize};
23use sov_rollup_interface::da::DaSpec;
24
25/// Implements the `StateTransitionVerifier` type for checking the validity of a state transition
26pub mod verifier;
27
28#[derive(Serialize, BorshDeserialize, BorshSerialize, Deserialize)]
29// Prevent serde from generating spurious trait bounds. The correct serde bounds are already enforced by the
30// StateTransitionFunction, DA, and Zkvm traits.
31#[serde(bound = "StateRoot: Serialize + DeserializeOwned, Witness: Serialize + DeserializeOwned")]
32/// Data required to verify a state transition.
33pub struct StateTransitionData<StateRoot, Witness, DA: DaSpec> {
34    /// The state root before the state transition
35    pub pre_state_root: StateRoot,
36    /// The header of the da block that is being processed
37    pub da_block_header: DA::BlockHeader,
38    /// The proof of inclusion for all blobs
39    pub inclusion_proof: DA::InclusionMultiProof,
40    /// The proof that the provided set of blobs is complete
41    pub completeness_proof: DA::CompletenessProof,
42    /// The blobs that are being processed
43    pub blobs: Vec<<DA as DaSpec>::BlobTransaction>,
44    /// The witness for the state transition
45    pub state_transition_witness: Witness,
46}
47
48#[cfg(feature = "native")]
49/// Reads json file.
50pub fn read_json_file<T: DeserializeOwned, P: AsRef<Path>>(path: P) -> anyhow::Result<T> {
51    let path_str = path.as_ref().display();
52
53    let data = std::fs::read_to_string(&path)
54        .with_context(|| format!("Failed to read genesis from {}", path_str))?;
55    let config: T = serde_json::from_str(&data)
56        .with_context(|| format!("Failed to parse genesis from {}", path_str))?;
57
58    Ok(config)
59}