From 2be9832d96d53d487c0a36c8295a30c27d31d4a4 Mon Sep 17 00:00:00 2001 From: Ariel Elperin Date: Thu, 7 May 2026 13:45:19 +0300 Subject: [PATCH] apollo_committer_types: add patricia proofs request and response types --- .../workflows/apollo_storage_os_input_ci.yml | 4 ++++ Cargo.lock | 1 + crates/apollo_committer_types/Cargo.toml | 2 ++ .../src/committer_types.rs | 20 ++++++++++++++++++ crates/apollo_committer_types/src/errors.rs | 14 +++++++++++++ .../starknet_forest_proofs_serde.rs | 21 +++++++++++++++++++ .../src/patricia_merkle_tree/types.rs | 4 ++-- 7 files changed, 64 insertions(+), 2 deletions(-) diff --git a/.github/workflows/apollo_storage_os_input_ci.yml b/.github/workflows/apollo_storage_os_input_ci.yml index 62d53a43507..51b48ae8968 100644 --- a/.github/workflows/apollo_storage_os_input_ci.yml +++ b/.github/workflows/apollo_storage_os_input_ci.yml @@ -12,6 +12,7 @@ on: - ".github/workflows/apollo_storage_os_input_ci.yml" - "Cargo.lock" - "Cargo.toml" + - "crates/apollo_committer_types/**" - "crates/apollo_storage/**" - "crates/apollo_config/**" - "crates/apollo_infra_utils/**" @@ -20,6 +21,7 @@ on: - "crates/apollo_test_utils/**" - "crates/blockifier/**" - "crates/starknet_api/**" + - "crates/starknet_committer/**" env: RUSTFLAGS: "-D warnings" @@ -57,6 +59,8 @@ jobs: - uses: ./.github/actions/bootstrap with: github_token: ${{ secrets.GITHUB_TOKEN }} + - run: cargo test -p starknet_committer --features os_input + - run: cargo test -p apollo_committer_types --features os_input - run: cargo build -p apollo_batcher --features os_input - run: cargo test -p apollo_batcher --features os_input - run: cargo test -p apollo_reverts --features os_input diff --git a/Cargo.lock b/Cargo.lock index 18b2be42cee..3be382d4205 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1119,6 +1119,7 @@ dependencies = [ "apollo_infra", "apollo_metrics", "async-trait", + "blockifier", "mockall", "serde", "starknet_api", diff --git a/crates/apollo_committer_types/Cargo.toml b/crates/apollo_committer_types/Cargo.toml index 08010cd1578..2fbbe8d44d5 100644 --- a/crates/apollo_committer_types/Cargo.toml +++ b/crates/apollo_committer_types/Cargo.toml @@ -7,12 +7,14 @@ license.workspace = true description = "Type definitions and interfaces for the Apollo committer component." [features] +os_input = ["dep:blockifier", "starknet_committer/os_input"] testing = ["mockall", "tokio"] [dependencies] apollo_infra.workspace = true apollo_metrics.workspace = true async-trait.workspace = true +blockifier = { workspace = true, features = ["transaction_serde"], optional = true } mockall = { workspace = true, optional = true } serde.workspace = true starknet_api.workspace = true diff --git a/crates/apollo_committer_types/src/committer_types.rs b/crates/apollo_committer_types/src/committer_types.rs index ba17c250a05..f43ef92e161 100644 --- a/crates/apollo_committer_types/src/committer_types.rs +++ b/crates/apollo_committer_types/src/committer_types.rs @@ -1,7 +1,11 @@ +#[cfg(feature = "os_input")] +pub use blockifier::state::accessed_keys::AccessedKeys; use serde::{Deserialize, Serialize}; use starknet_api::block::BlockNumber; use starknet_api::core::{GlobalRoot, StateDiffCommitment}; use starknet_api::state::ThinStateDiff; +#[cfg(feature = "os_input")] +use starknet_committer::patricia_merkle_tree::types::StarknetForestProofs; #[derive(Clone, Debug, Serialize, Deserialize)] pub struct CommitBlockRequest { @@ -32,3 +36,19 @@ pub enum RevertBlockResponse { // Nothing to revert. A future block that has not been committed. Uncommitted, } + +/// Commit a block and return merged Patricia witness proofs for OS input (pre- and post-commit +/// paths). +#[cfg(feature = "os_input")] +#[derive(Clone, Debug, Serialize, Deserialize)] +pub struct ReadPathsAndCommitBlockRequest { + pub commit: CommitBlockRequest, + pub accessed_keys: AccessedKeys, +} + +#[cfg(feature = "os_input")] +#[derive(Clone, Debug, Serialize, Deserialize)] +pub struct ReadPathsAndCommitBlockResponse { + pub global_root: GlobalRoot, + pub patricia_proofs: StarknetForestProofs, +} diff --git a/crates/apollo_committer_types/src/errors.rs b/crates/apollo_committer_types/src/errors.rs index d0cb28dd63c..5142d86cf4c 100644 --- a/crates/apollo_committer_types/src/errors.rs +++ b/crates/apollo_committer_types/src/errors.rs @@ -48,6 +48,20 @@ pub enum CommitterError { calculated_commitment: StateDiffCommitment, height: BlockNumber, }, + /// Patricia trie path collection for OS input failed. + #[cfg(feature = "os_input")] + #[error("Failed Patricia paths collection at block {height}: {message}")] + PatriciaPathsCollectionFailed { height: BlockNumber, message: String }, + /// Stored accessed-keys digest does not match the request (or no digest was stored). + #[cfg(feature = "os_input")] + #[error( + "Accessed-keys digest mismatch at block {height}: expected {expected:?}, stored {stored:?}" + )] + AccessedKeysDigestMismatch { height: BlockNumber, stored: Option<[u8; 32]>, expected: [u8; 32] }, + /// Merged Patricia witness paths are missing for replay. + #[cfg(feature = "os_input")] + #[error("Missing Patricia paths for block {height}")] + MissingPatriciaPaths { height: BlockNumber }, } pub type CommitterResult = Result; diff --git a/crates/starknet_committer/src/patricia_merkle_tree/starknet_forest_proofs_serde.rs b/crates/starknet_committer/src/patricia_merkle_tree/starknet_forest_proofs_serde.rs index 9b1997af6ea..63a398d72dc 100644 --- a/crates/starknet_committer/src/patricia_merkle_tree/starknet_forest_proofs_serde.rs +++ b/crates/starknet_committer/src/patricia_merkle_tree/starknet_forest_proofs_serde.rs @@ -1,5 +1,6 @@ use std::collections::HashMap; +use serde::de::Error as DeError; use starknet_api::core::{ClassHash, ContractAddress, Nonce}; use starknet_api::hash::HashOutput; use starknet_patricia::patricia_merkle_tree::node_data::inner_node::{ @@ -125,6 +126,26 @@ impl StarknetForestProofs { } } +impl serde::Serialize for StarknetForestProofs { + fn serialize(&self, serializer: S) -> Result + where + S: serde::Serializer, + { + let encoded = Self::serialize(self).map_err(serde::ser::Error::custom)?; + encoded.0.serialize(serializer) + } +} + +impl<'de> serde::Deserialize<'de> for StarknetForestProofs { + fn deserialize(deserializer: D) -> Result + where + D: serde::Deserializer<'de>, + { + let bytes = Vec::::deserialize(deserializer)?; + Self::deserialize(&DbValue(bytes)).map_err(DeError::custom) + } +} + fn bincode_ser_err(error: bincode::Error) -> SerializationError { SerializationError::IOSerialize(std::io::Error::other(error)) } diff --git a/crates/starknet_committer/src/patricia_merkle_tree/types.rs b/crates/starknet_committer/src/patricia_merkle_tree/types.rs index a515d914800..275c3696ce0 100644 --- a/crates/starknet_committer/src/patricia_merkle_tree/types.rs +++ b/crates/starknet_committer/src/patricia_merkle_tree/types.rs @@ -36,13 +36,13 @@ pub type ClassesTrie = FilledTreeImpl; pub type ContractsTrie = FilledTreeImpl; pub type StorageTrieMap = HashMap; -#[derive(Debug, PartialEq)] +#[derive(Debug, Clone, PartialEq)] pub struct ContractsTrieProof { pub nodes: PreimageMap, pub leaves: HashMap, } -#[derive(Debug, PartialEq)] +#[derive(Debug, Clone, PartialEq)] pub struct StarknetForestProofs { pub classes_trie_proof: PreimageMap, pub contracts_trie_proof: ContractsTrieProof,