Skip to content

Commit 00a8555

Browse files
committed
apollo_committer_types: add patricia proofs request and response types
1 parent 398ddb7 commit 00a8555

7 files changed

Lines changed: 69 additions & 2 deletions

File tree

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/apollo_committer_types/Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ license.workspace = true
77
description = "Type definitions and interfaces for the Apollo committer component."
88

99
[features]
10+
os_input = ["starknet_committer/os_input"]
1011
testing = ["mockall", "tokio"]
1112

1213
[dependencies]
@@ -17,6 +18,7 @@ mockall = { workspace = true, optional = true }
1718
serde.workspace = true
1819
starknet_api.workspace = true
1920
starknet_committer.workspace = true
21+
starknet-types-core = { workspace = true, features = ["serde"] }
2022
strum = { workspace = true, features = ["derive"] }
2123
thiserror.workspace = true
2224
tokio = { workspace = true, optional = true }

crates/apollo_committer_types/src/committer_types.rs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@ use serde::{Deserialize, Serialize};
22
use starknet_api::block::BlockNumber;
33
use starknet_api::core::{GlobalRoot, StateDiffCommitment};
44
use starknet_api::state::ThinStateDiff;
5+
#[cfg(feature = "os_input")]
6+
pub use starknet_committer::block_committer::input::AccessedKeys;
7+
#[cfg(feature = "os_input")]
8+
use starknet_committer::patricia_merkle_tree::types::StarknetForestProofs;
59

610
#[derive(Clone, Debug, Serialize, Deserialize)]
711
pub struct CommitBlockRequest {
@@ -32,3 +36,19 @@ pub enum RevertBlockResponse {
3236
// Nothing to revert. A future block that has not been committed.
3337
Uncommitted,
3438
}
39+
40+
/// Commit a block and return merged Patricia witness proofs for OS input (pre- and post-commit
41+
/// paths).
42+
#[cfg(feature = "os_input")]
43+
#[derive(Clone, Debug, Serialize, Deserialize)]
44+
pub struct ReadPathsAndCommitBlockRequest {
45+
pub commit: CommitBlockRequest,
46+
pub accessed_keys: AccessedKeys,
47+
}
48+
49+
#[cfg(feature = "os_input")]
50+
#[derive(Clone, Debug, Serialize, Deserialize)]
51+
pub struct ReadPathsAndCommitBlockResponse {
52+
pub global_root: GlobalRoot,
53+
pub patricia_proofs: StarknetForestProofs,
54+
}

crates/apollo_committer_types/src/errors.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,20 @@ pub enum CommitterError {
4848
calculated_commitment: StateDiffCommitment,
4949
height: BlockNumber,
5050
},
51+
/// Patricia trie path collection for OS input failed.
52+
#[cfg(feature = "os_input")]
53+
#[error("Failed Patricia paths collection at block {height}: {message}")]
54+
PatriciaPathsCollectionFailed { height: BlockNumber, message: String },
55+
/// Stored accessed-keys digest does not match the request (or no digest was stored).
56+
#[cfg(feature = "os_input")]
57+
#[error(
58+
"Accessed-keys digest mismatch at block {height}: expected {expected:?}, stored {stored:?}"
59+
)]
60+
AccessedKeysDigestMismatch { height: BlockNumber, stored: Option<[u8; 32]>, expected: [u8; 32] },
61+
/// Merged Patricia witness paths are missing for replay.
62+
#[cfg(feature = "os_input")]
63+
#[error("Missing Patricia paths for block {height}")]
64+
MissingPatriciaPaths { height: BlockNumber },
5165
}
5266

5367
pub type CommitterResult<T> = Result<T, CommitterError>;

crates/starknet_committer/src/block_committer/input.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,15 @@ impl From<u128> for StarknetStorageKey {
7474
#[derive(Clone, Copy, Default, Debug, Deserialize, Eq, PartialEq, Serialize)]
7575
pub struct StarknetStorageValue(pub Felt);
7676

77+
/// Trie leaves read during block execution (classes, contracts, and per-contract storage slots).
78+
#[derive(Clone, Debug, Default, Deserialize, Eq, PartialEq, Serialize)]
79+
#[cfg(feature = "os_input")]
80+
pub struct AccessedKeys {
81+
pub class_hashes: Vec<ClassHash>,
82+
pub contract_addresses: Vec<ContractAddress>,
83+
pub contract_storage_keys: HashMap<ContractAddress, Vec<StarknetStorageKey>>,
84+
}
85+
7786
#[derive(Clone, Debug, Default, Deserialize, Eq, PartialEq, Serialize)]
7887
pub struct StateDiff {
7988
pub address_to_class_hash: HashMap<ContractAddress, ClassHash>,

crates/starknet_committer/src/patricia_merkle_tree/starknet_forest_proofs_serde.rs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,27 @@ impl StarknetForestProofs {
117117
}
118118
}
119119

120+
impl serde::Serialize for StarknetForestProofs {
121+
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
122+
where
123+
S: serde::Serializer,
124+
{
125+
let encoded = Self::serialize(self).map_err(serde::ser::Error::custom)?;
126+
encoded.0.serialize(serializer)
127+
}
128+
}
129+
130+
impl<'de> serde::Deserialize<'de> for StarknetForestProofs {
131+
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
132+
where
133+
D: serde::Deserializer<'de>,
134+
{
135+
use serde::de::Error;
136+
let bytes = Vec::<u8>::deserialize(deserializer)?;
137+
Self::deserialize(&DbValue(bytes)).map_err(Error::custom)
138+
}
139+
}
140+
120141
fn bincode_ser_err(error: bincode::Error) -> SerializationError {
121142
SerializationError::IOSerialize(std::io::Error::other(error))
122143
}

crates/starknet_committer/src/patricia_merkle_tree/types.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,13 +36,13 @@ pub type ClassesTrie = FilledTreeImpl<CompiledClassHash>;
3636
pub type ContractsTrie = FilledTreeImpl<ContractState>;
3737
pub type StorageTrieMap = HashMap<ContractAddress, StorageTrie>;
3838

39-
#[derive(Debug, PartialEq)]
39+
#[derive(Debug, Clone, PartialEq)]
4040
pub struct ContractsTrieProof {
4141
pub nodes: PreimageMap,
4242
pub leaves: HashMap<ContractAddress, ContractState>,
4343
}
4444

45-
#[derive(Debug, PartialEq)]
45+
#[derive(Debug, Clone, PartialEq)]
4646
pub struct StarknetForestProofs {
4747
pub classes_trie_proof: PreimageMap,
4848
pub contracts_trie_proof: ContractsTrieProof,

0 commit comments

Comments
 (0)