Skip to content
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
4 changes: 4 additions & 0 deletions .github/workflows/apollo_storage_os_input_ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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/**"
Expand All @@ -20,6 +21,7 @@ on:
- "crates/apollo_test_utils/**"
- "crates/blockifier/**"
- "crates/starknet_api/**"
- "crates/starknet_committer/**"

env:
RUSTFLAGS: "-D warnings"
Expand Down Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions Cargo.lock

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

2 changes: 2 additions & 0 deletions crates/apollo_committer_types/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
20 changes: 20 additions & 0 deletions crates/apollo_committer_types/src/committer_types.rs
Original file line number Diff line number Diff line change
@@ -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;
Comment thread
cursor[bot] marked this conversation as resolved.

#[derive(Clone, Debug, Serialize, Deserialize)]
pub struct CommitBlockRequest {
Expand Down Expand Up @@ -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,
}
14 changes: 14 additions & 0 deletions crates/apollo_committer_types/src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<T> = Result<T, CommitterError>;
Expand Down
Original file line number Diff line number Diff line change
@@ -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::{
Expand Down Expand Up @@ -125,6 +126,26 @@ impl StarknetForestProofs {
}
}

impl serde::Serialize for StarknetForestProofs {
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
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<D>(deserializer: D) -> Result<Self, D::Error>
where
D: serde::Deserializer<'de>,
{
let bytes = Vec::<u8>::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))
}
Expand Down
4 changes: 2 additions & 2 deletions crates/starknet_committer/src/patricia_merkle_tree/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,13 @@ pub type ClassesTrie = FilledTreeImpl<CompiledClassHash>;
pub type ContractsTrie = FilledTreeImpl<ContractState>;
pub type StorageTrieMap = HashMap<ContractAddress, StorageTrie>;

#[derive(Debug, PartialEq)]
#[derive(Debug, Clone, PartialEq)]
pub struct ContractsTrieProof {
pub nodes: PreimageMap,
pub leaves: HashMap<ContractAddress, ContractState>,
}

#[derive(Debug, PartialEq)]
#[derive(Debug, Clone, PartialEq)]
pub struct StarknetForestProofs {
pub classes_trie_proof: PreimageMap,
pub contracts_trie_proof: ContractsTrieProof,
Expand Down
Loading