Skip to content

starknet_committer,starknet_os,starknet_patricia: make node data generic#10679

Merged
ArielElp merged 1 commit intomain-v0.14.1-committerfrom
abstract_node_data
Dec 16, 2025
Merged

starknet_committer,starknet_os,starknet_patricia: make node data generic#10679
ArielElp merged 1 commit intomain-v0.14.1-committerfrom
abstract_node_data

Conversation

@ArielElp
Copy link
Contributor

No description provided.

@reviewable-StarkWare
Copy link

This change is Reviewable

Copy link
Contributor Author

ArielElp commented Dec 10, 2025

This stack of pull requests is managed by Graphite. Learn more about stacking.

@ArielElp ArielElp marked this pull request as ready for review December 10, 2025 13:18
@ArielElp ArielElp changed the base branch from ariel/db_keys to graphite-base/10679 December 10, 2025 15:06
@ArielElp ArielElp force-pushed the graphite-base/10679 branch from de081a6 to 6d13cf1 Compare December 10, 2025 15:06
@ArielElp ArielElp changed the base branch from graphite-base/10679 to ariel/add_deserialization_context December 10, 2025 15:07
Copy link
Contributor

@yoavGrs yoavGrs left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@yoavGrs reviewed 16 of 16 files at r1, all commit messages.
Reviewable status: all files reviewed, 8 unresolved discussions (waiting on @ArielElp)


crates/starknet_patricia/src/patricia_merkle_tree/filled_tree/node.rs line 8 at r1 (raw file):

#[derive(Clone, Debug, PartialEq, Eq)]
/// A node in a Patricia-Merkle tree, complete with its hash and data.
pub struct FilledNode<L: Leaf> {

I'm guessing that this will be the next step here, right?

Suggestion:

pub struct FilledNode<L: Leaf, HashOutput>

crates/starknet_patricia/src/patricia_merkle_tree/updated_skeleton_tree/hash_function.rs line 23 at r1 (raw file):

    /// Computes the hash for the given node data.
    fn compute_node_hash(node_data: &NodeData<L, HashOutput>) -> HashOutput;

Same question in this file.

Suggestion:

 fn compute_node_hash<T>(node_data: &NodeData<L, T>) -> HashOutput;

crates/starknet_patricia/src/patricia_merkle_tree/internal_test_utils.rs line 27 at r1 (raw file):

    }

    fn compute_node_hash(node_data: &NodeData<MockLeaf, HashOutput>) -> HashOutput {

Same question

Suggestion:

 fn compute_node_hash<T>(node_data: &NodeData<MockLeaf, T>) -> HashOutput {

crates/starknet_committer/src/hash_function/hash.rs line 54 at r1 (raw file):

        ))
    }
    fn compute_node_hash(node_data: &NodeData<ContractState, HashOutput>) -> HashOutput {

Why does it work only for HashOutput type?
Same question below.

Suggestion:

fn compute_node_hash<T>(node_data: &NodeData<ContractState, T>) -> HashOutput

crates/starknet_patricia/src/patricia_merkle_tree/node_data/inner_node.rs line 22 at r1 (raw file):

#[cfg_attr(any(test, feature = "testing"), derive(strum_macros::EnumDiscriminants))]
#[cfg_attr(any(test, feature = "testing"), strum_discriminants(derive(strum_macros::EnumIter)))]
// A Patricia-Merkle tree node's data, i.e., the pre-image of its hash.

Is it correct?

Code quote:

// A Patricia-Merkle tree node's data, i.e., the pre-image of its hash.

crates/starknet_patricia/src/patricia_merkle_tree/node_data/inner_node.rs line 39 at r1 (raw file):

        vec![self.left_data.0, self.right_data.0]
    }
}

Are you going to move it under facts_db?
If it is not in the next PR, please add TODO.

Code quote:

impl BinaryData<HashOutput> {
    pub fn flatten(&self) -> Vec<Felt> {
        vec![self.left_data.0, self.right_data.0]
    }
}

crates/starknet_patricia/src/patricia_merkle_tree/node_data/inner_node.rs line 157 at r1 (raw file):

        ]
    }
}

Same question.

Code quote:

impl EdgeData<HashOutput> {
    pub fn flatten(&self) -> Vec<Felt> {
        vec![
            self.path_to_bottom.length.into(),
            (&self.path_to_bottom.path).into(),
            self.bottom_data.0,
        ]
    }
}

crates/starknet_patricia/src/patricia_merkle_tree/node_data/inner_node.rs line 204 at r1 (raw file):

#[derive(Clone, Debug, PartialEq)]
pub enum Preimage {

Is it relevant for both layers?
If not, please add a TODO for moving it under facts_db.

Code quote:

pub enum Preimage {

@ArielElp ArielElp force-pushed the ariel/add_deserialization_context branch from 6d13cf1 to a185e9a Compare December 10, 2025 15:35
@ArielElp ArielElp force-pushed the abstract_node_data branch 2 times, most recently from 00cd7a5 to 560776a Compare December 10, 2025 15:41
@ArielElp ArielElp force-pushed the ariel/add_deserialization_context branch from a185e9a to 743c49b Compare December 10, 2025 15:41
@ArielElp ArielElp force-pushed the abstract_node_data branch 2 times, most recently from e1719c0 to 1470e1e Compare December 10, 2025 19:46
@ArielElp ArielElp force-pushed the ariel/add_deserialization_context branch 2 times, most recently from 1efd903 to c231394 Compare December 14, 2025 15:23
@ArielElp ArielElp force-pushed the abstract_node_data branch 2 times, most recently from b32fd55 to bf3d482 Compare December 14, 2025 15:45
@ArielElp ArielElp force-pushed the ariel/add_deserialization_context branch from c231394 to 38a0f23 Compare December 14, 2025 15:45
@ArielElp ArielElp force-pushed the ariel/add_deserialization_context branch from 38a0f23 to 1645dcb Compare December 14, 2025 16:00
Copy link
Contributor

@nimrod-starkware nimrod-starkware left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:lgtm:

@nimrod-starkware reviewed 2 of 3 files at r4, 1 of 1 files at r5, all commit messages.
Reviewable status: :shipit: complete! all files reviewed, all discussions resolved (waiting on @ArielElp)

@ArielElp ArielElp force-pushed the ariel/add_deserialization_context branch from 1645dcb to cb4f9c2 Compare December 15, 2025 08:57
Copy link
Collaborator

@dorimedini-starkware dorimedini-starkware left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dorimedini-starkware reviewed 11 of 16 files at r1, 1 of 1 files at r2, 1 of 5 files at r3, 1 of 3 files at r4, 1 of 1 files at r5, 2 of 2 files at r6, all commit messages.
Reviewable status: all files reviewed, 4 unresolved discussions (waiting on @ArielElp)


crates/starknet_committer/src/db/facts_db/traversal.rs line 124 at r6 (raw file):

                    if !right_subtree.is_unmodified() {
                        next_subtrees.push(right_subtree);
                    }

what is this change?
we really do want to only conditionally add these subtrees!

Code quote:

                    if !left_subtree.is_unmodified() {
                        next_subtrees.push(left_subtree);
                    }
                    if !right_subtree.is_unmodified() {
                        next_subtrees.push(right_subtree);
                    }

crates/starknet_patricia/src/patricia_merkle_tree/updated_skeleton_tree/hash_function.rs line 29 at r6 (raw file):

    fn compute_node_hash_with_inner_hash_function<H: HashFunction>(
        node_data: &NodeData<L, HashOutput>,
    ) -> HashOutput {

will you be changing the signatures here?
how will we compute that hash of NodeData instances in index layout?

Code quote:

    fn compute_node_hash(node_data: &NodeData<L, HashOutput>) -> HashOutput;

    /// The default implementation for internal nodes is based on the following reference:
    /// <https://docs.starknet.io/documentation/architecture_and_concepts/Network_Architecture/starknet-state/#trie_construction>
    fn compute_node_hash_with_inner_hash_function<H: HashFunction>(
        node_data: &NodeData<L, HashOutput>,
    ) -> HashOutput {

crates/starknet_patricia/src/patricia_merkle_tree/node_data/inner_node.rs line 39 at r6 (raw file):

        vec![self.left_data.0, self.right_data.0]
    }
}

WDYT of this type of thing?
will it be useful for other ChildData implementations?

Suggestion:

pub trait Flatten {
    fn flatten(&self) -> Vec<Felt>;
}

#[derive(Clone, Debug, PartialEq, Eq)]
#[cfg_attr(any(test, feature = "testing"), derive(strum_macros::EnumDiscriminants))]
#[cfg_attr(any(test, feature = "testing"), strum_discriminants(derive(strum_macros::EnumIter)))]
// A Patricia-Merkle tree node's data.
pub enum NodeData<L: Leaf, ChildData: Flatten> {
    Binary(BinaryData<ChildData>),
    Edge(EdgeData<ChildData>),
    Leaf(L),
}

#[derive(Clone, Debug, Default, PartialEq, Eq)]
pub struct BinaryData<ChildData: Flatten> {
    pub left_data: ChildData,
    pub right_data: ChildData,
}

impl<C: ChildData> Flatten for BinaryData<C> {
    pub fn flatten(&self) -> Vec<Felt> {
        [self.left_data.flatten(), self.right_data.flatten()].concat()
    }
}

crates/starknet_committer/src/db/facts_db/create_facts_tree.rs line 64 at r6 (raw file):

            match filled_root.data {
                // Binary node.
                NodeData::<L, HashOutput>::Binary(BinaryData { left_data, right_data }) => {

is the turbofish required (here and below)? can't the compiler infer the ChildData type?

Code quote:

NodeData::<L, HashOutput>::Binary

Copy link
Contributor Author

@ArielElp ArielElp left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewable status: all files reviewed, 4 unresolved discussions (waiting on @dorimedini-starkware)


crates/starknet_committer/src/db/facts_db/create_facts_tree.rs line 64 at r6 (raw file):

Previously, dorimedini-starkware wrote…

is the turbofish required (here and below)? can't the compiler infer the ChildData type?

Not needed indeed, removed.


crates/starknet_committer/src/db/facts_db/traversal.rs line 124 at r6 (raw file):

Previously, dorimedini-starkware wrote…

what is this change?
we really do want to only conditionally add these subtrees!

Good catch. Not intentional, best guess is that at one point I thought I was editing fetch_nodes but was actually editing this function instead.


crates/starknet_patricia/src/patricia_merkle_tree/node_data/inner_node.rs line 39 at r6 (raw file):

Previously, dorimedini-starkware wrote…

WDYT of this type of thing?
will it be useful for other ChildData implementations?

Probably won't be useful for other child data, it's used in preimage which needs children hashes.

Note this related todo on preimage:

// TODO(Ariel): Move Preimage to the fact_db module in starknet\committer (add a flatten
// trait to be implemented in starknet_committer for BinaryData and EdgeData).

(in the TODO, the trait is only introduced so that I can implement it in starknet_committer on the foreign NodeData type)


crates/starknet_patricia/src/patricia_merkle_tree/updated_skeleton_tree/hash_function.rs line 29 at r6 (raw file):

Previously, dorimedini-starkware wrote…

will you be changing the signatures here?
how will we compute that hash of NodeData instances in index layout?

The signature works for index layout too. The trickery going on is that NodeData is used with a layout-dependent ChildData during the construction of the original skeleton, but when computing the filled tree, we always use HashOutput. You compute the node data there, get hash output of right and left, and construct the node data of the current node before feeding it to the hasher.

Copy link
Collaborator

@dorimedini-starkware dorimedini-starkware left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewable status: all files reviewed, 4 unresolved discussions (waiting on @ArielElp)


crates/starknet_committer/src/db/facts_db/traversal.rs line 124 at r6 (raw file):

Previously, ArielElp wrote…

Good catch. Not intentional, best guess is that at one point I thought I was editing fetch_nodes but was actually editing this function instead.

please apply the change in the correct PR (here, not here :) )

Copy link
Collaborator

@dorimedini-starkware dorimedini-starkware left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewable status: all files reviewed, 2 unresolved discussions (waiting on @ArielElp)


crates/starknet_committer/src/db/facts_db/create_facts_tree.rs line 64 at r6 (raw file):

Previously, ArielElp wrote…

Not needed indeed, removed.

the fix is in the next PR but nvm, not a problem (just style)


crates/starknet_patricia/src/patricia_merkle_tree/updated_skeleton_tree/hash_function.rs line 29 at r6 (raw file):

Previously, ArielElp wrote…

The signature works for index layout too. The trickery going on is that NodeData is used with a layout-dependent ChildData during the construction of the original skeleton, but when computing the filled tree, we always use HashOutput. You compute the node data there, get hash output of right and left, and construct the node data of the current node before feeding it to the hasher.

can you add a remark in the docstring about this? it's confusing that this case is layout-independent

@ArielElp ArielElp changed the base branch from ariel/add_deserialization_context to graphite-base/10679 December 16, 2025 09:39
@ArielElp ArielElp force-pushed the graphite-base/10679 branch from cb4f9c2 to f259a2a Compare December 16, 2025 09:39
@ArielElp ArielElp changed the base branch from graphite-base/10679 to main-v0.14.1-committer December 16, 2025 09:39
Copy link
Contributor Author

@ArielElp ArielElp left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewable status: all files reviewed, 2 unresolved discussions (waiting on @dorimedini-starkware)


crates/starknet_committer/src/db/facts_db/traversal.rs line 124 at r6 (raw file):

Previously, dorimedini-starkware wrote…

please apply the change in the correct PR (here, not here :) )

ups, done


crates/starknet_patricia/src/patricia_merkle_tree/updated_skeleton_tree/hash_function.rs line 29 at r6 (raw file):

Previously, dorimedini-starkware wrote…

can you add a remark in the docstring about this? it's confusing that this case is layout-independent

Added, WDYT?

Copy link
Collaborator

@dorimedini-starkware dorimedini-starkware left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dorimedini-starkware reviewed 3 of 3 files at r7, all commit messages.
Reviewable status: all files reviewed, 1 unresolved discussion (waiting on @ArielElp)


crates/starknet_patricia/src/patricia_merkle_tree/updated_skeleton_tree/hash_function.rs line 28 at r7 (raw file):

    /// <https://docs.starknet.io/documentation/architecture_and_concepts/Network_Architecture/starknet-state/#trie_construction>
    /// This code is layout independent. After computing the children hashes, NodeData can be
    /// insantiated with the concrete HashOutput for ChildData, regardless of what's stored in the

typo
looks good otherwise

Suggestion:

instantiated

Copy link
Collaborator

@dorimedini-starkware dorimedini-starkware left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dorimedini-starkware reviewed 1 of 1 files at r8, all commit messages.
Reviewable status: all files reviewed, 1 unresolved discussion (waiting on @ArielElp)

Copy link
Collaborator

@dorimedini-starkware dorimedini-starkware left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dorimedini-starkware reviewed 1 of 1 files at r9, all commit messages.
Reviewable status: :shipit: complete! all files reviewed, all discussions resolved (waiting on @ArielElp)

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants