Skip to content

Commit 62c30ea

Browse files
starknet_committer,starknet_os: relocate commitment infos to starknet_committer (#14447)
1 parent 66e6f67 commit 62c30ea

2 files changed

Lines changed: 43 additions & 37 deletions

File tree

crates/starknet_committer/src/patricia_merkle_tree/types.rs

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use starknet_patricia::impl_from_hex_for_felt_wrapper;
77
use starknet_patricia::patricia_merkle_tree::filled_tree::tree::FilledTreeImpl;
88
use starknet_patricia::patricia_merkle_tree::node_data::inner_node::PreimageMap;
99
use starknet_patricia::patricia_merkle_tree::node_data::leaf::SkeletonLeaf;
10-
use starknet_patricia::patricia_merkle_tree::types::NodeIndex;
10+
use starknet_patricia::patricia_merkle_tree::types::{NodeIndex, SubTreeHeight};
1111
use starknet_types_core::felt::{Felt, FromStrError};
1212

1313
use crate::block_committer::input::{try_node_index_into_contract_address, StarknetStorageValue};
@@ -57,6 +57,40 @@ pub struct StarknetForestProofs {
5757
pub contracts_trie_storage_proofs: HashMap<ContractAddress, PreimageMap>,
5858
}
5959

60+
#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)]
61+
#[serde(deny_unknown_fields)]
62+
pub struct CommitmentInfo {
63+
pub previous_root: HashOutput,
64+
pub updated_root: HashOutput,
65+
pub tree_height: SubTreeHeight,
66+
// TODO(Dori, 1/8/2025): The value type here should probably be more specific (NodeData<L> for
67+
// L: Leaf). This poses a problem in deserialization, as a serialized edge node and a
68+
// serialized contract state leaf are both currently vectors of 3 field elements; as the
69+
// semantics of the values are unimportant for the OS commitments, we make do with a vector
70+
// of field elements as values for now.
71+
pub commitment_facts: HashMap<HashOutput, Vec<Felt>>,
72+
}
73+
74+
#[cfg(any(feature = "testing", test))]
75+
impl Default for CommitmentInfo {
76+
fn default() -> CommitmentInfo {
77+
CommitmentInfo {
78+
previous_root: HashOutput::default(),
79+
updated_root: HashOutput::default(),
80+
tree_height: SubTreeHeight::ACTUAL_HEIGHT,
81+
commitment_facts: HashMap::default(),
82+
}
83+
}
84+
}
85+
86+
/// Contains all commitment information for a block's state trees.
87+
#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)]
88+
pub struct StateCommitmentInfos {
89+
pub contracts_trie_commitment_info: CommitmentInfo,
90+
pub classes_trie_commitment_info: CommitmentInfo,
91+
pub storage_tries_commitment_infos: HashMap<ContractAddress, CommitmentInfo>,
92+
}
93+
6094
impl StarknetForestProofs {
6195
pub fn build<Layout>(
6296
classes_trie_proof: PreimageMap,

crates/starknet_os/src/commitment_infos.rs

Lines changed: 8 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -11,50 +11,18 @@ use starknet_committer::db::facts_db::create_facts_tree::get_leaves;
1111
use starknet_committer::patricia_merkle_tree::leaf::leaf_impl::ContractState;
1212
use starknet_committer::patricia_merkle_tree::tree::fetch_previous_and_new_patricia_paths;
1313
use starknet_committer::patricia_merkle_tree::types::RootHashes;
14+
// `CommitmentInfo` and `StateCommitmentInfos` were relocated to `starknet_committer` so that
15+
// lower layers (e.g. `apollo_storage`) can store them without depending on `starknet_os`. They
16+
// are re-exported here to keep this module's public API stable for OS consumers.
17+
pub use starknet_committer::patricia_merkle_tree::types::{CommitmentInfo, StateCommitmentInfos};
1418
use starknet_patricia::patricia_merkle_tree::node_data::inner_node::flatten_preimages;
1519
use starknet_patricia::patricia_merkle_tree::original_skeleton_tree::errors::OriginalSkeletonTreeError;
1620
use starknet_patricia::patricia_merkle_tree::traversal::TraversalError;
1721
use starknet_patricia::patricia_merkle_tree::types::{NodeIndex, SortedLeafIndices, SubTreeHeight};
1822
use starknet_patricia_storage::db_object::EmptyKeyContext;
1923
use starknet_patricia_storage::map_storage::MapStorage;
20-
use starknet_types_core::felt::Felt;
2124
use thiserror::Error;
2225

23-
#[cfg_attr(feature = "deserialize", derive(serde::Deserialize))]
24-
#[cfg_attr(feature = "deserialize", serde(deny_unknown_fields))]
25-
#[derive(Debug)]
26-
pub struct CommitmentInfo {
27-
pub previous_root: HashOutput,
28-
pub updated_root: HashOutput,
29-
pub tree_height: SubTreeHeight,
30-
// TODO(Dori, 1/8/2025): The value type here should probably be more specific (NodeData<L> for
31-
// L: Leaf). This poses a problem in deserialization, as a serialized edge node and a
32-
// serialized contract state leaf are both currently vectors of 3 field elements; as the
33-
// semantics of the values are unimportant for the OS commitments, we make do with a vector
34-
// of field elements as values for now.
35-
pub commitment_facts: HashMap<HashOutput, Vec<Felt>>,
36-
}
37-
38-
#[cfg(any(feature = "testing", test))]
39-
impl Default for CommitmentInfo {
40-
fn default() -> CommitmentInfo {
41-
CommitmentInfo {
42-
previous_root: HashOutput::default(),
43-
updated_root: HashOutput::default(),
44-
tree_height: SubTreeHeight::ACTUAL_HEIGHT,
45-
commitment_facts: HashMap::default(),
46-
}
47-
}
48-
}
49-
50-
// TODO(Aviv): Use this struct in `OsBlockInput`
51-
/// Contains all commitment information for a block's state trees.
52-
pub struct StateCommitmentInfos {
53-
pub contracts_trie_commitment_info: CommitmentInfo,
54-
pub classes_trie_commitment_info: CommitmentInfo,
55-
pub storage_tries_commitment_infos: HashMap<ContractAddress, CommitmentInfo>,
56-
}
57-
5826
/// Error type for commitment infos creation.
5927
#[derive(Debug, Error)]
6028
pub enum CommitmentInfosError {
@@ -68,6 +36,10 @@ pub enum CommitmentInfosError {
6836

6937
/// Creates the commitment infos for the OS from previous and new state roots and the
7038
/// keys that were read during execution.
39+
// TODO(ItamarS): Temporary — to be deleted once the committer builds `StateCommitmentInfos` from
40+
// its own storage; tests against that new committer API will be added then. Kept here (as a free
41+
// function rather than an inherent method) because the struct now lives in `starknet_committer`
42+
// and the orphan rule forbids an inherent impl on a foreign type.
7143
pub async fn build_state_commitment_infos(
7244
previous_state_roots: &StateRoots,
7345
new_state_roots: &StateRoots,

0 commit comments

Comments
 (0)