Skip to content

starknet_committer: add utility that returns sorted leaf indices#13992

Open
ArielElp wants to merge 1 commit into
ariel/abstract_fetch_all_patricia_pathsfrom
ariel/get_leaf_indicies_utility
Open

starknet_committer: add utility that returns sorted leaf indices#13992
ArielElp wants to merge 1 commit into
ariel/abstract_fetch_all_patricia_pathsfrom
ariel/get_leaf_indicies_utility

Conversation

@ArielElp
Copy link
Copy Markdown
Contributor

@ArielElp ArielElp commented May 7, 2026

No description provided.

Copy link
Copy Markdown
Contributor Author

ArielElp commented May 7, 2026

Warning

This pull request is not mergeable via GitHub because a downstack PR is open. Once all requirements are satisfied, merge this PR as a stack on Graphite.
Learn more

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

@reviewable-StarkWare
Copy link
Copy Markdown

This change is Reviewable

@cursor
Copy link
Copy Markdown

cursor Bot commented May 14, 2026

PR Summary

Low Risk
Mechanical refactor with the same index-building and sorting logic; no change to trie traversal or proof semantics beyond clearer structure.

Overview
Introduces LeavesRequest and SortedLeavesRequest in tree.rs so class, contract, and per-contract storage leaf indices are built once from accessed leaves and then wrapped in SortedLeafIndices for Patricia path fetching.

fetch_previous_and_new_patricia_paths is refactored to call LeavesRequest::from_accessed_leaves and SortedLeavesRequest::from instead of duplicating index construction and sorting inline; the same sorted views are reused for both previous- and new-root fetch_all_patricia_paths calls. SortedLeafIndices is re-exported from starknet_patricia, and the contracts/storage assumption comment is clarified slightly.

Reviewed by Cursor Bugbot for commit 1b083d2. Bugbot is set up for automated code reviews on this repo. Configure here.

Copy link
Copy Markdown
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 1 file and all commit messages, and made 3 comments.
Reviewable status: all files reviewed, 3 unresolved discussions (waiting on ArielElp).


crates/starknet_committer/src/patricia_merkle_tree/tree.rs line 28 at r1 (raw file):

    StarknetForestProofs,
};

Restore the new line.


crates/starknet_committer/src/patricia_merkle_tree/tree.rs line 85 at r1 (raw file):

    contract_addresses: &[ContractAddress],
    contract_storage_keys: &HashMap<ContractAddress, Vec<StarknetStorageKey>>,
) -> LeavesRequest {

Move it into impl LeavesRequest?

Suggestion:

pub fn from...(
    class_hashes: &[ClassHash],
    contract_addresses: &[ContractAddress],
    contract_storage_keys: &HashMap<ContractAddress, Vec<StarknetStorageKey>>,
) -> Self {

crates/starknet_committer/src/patricia_merkle_tree/tree.rs line 247 at r1 (raw file):

    .await?;

    let (class_sorted, contract_sorted, storage_sorted) = leaves_request.get_sorted();

WDYT?
It’s logically equivalent, but I think this way makes it clearer that the code isn't doing any unnecessary work.

Suggestion:

    let prev_proofs = fetch_all_patricia_paths::<FactsNodeLayout>(
        storage,
        classes_trie_root_hashes.previous_root_hash,
        contracts_trie_root_hashes.previous_root_hash,
        class_sorted.clone(),
        contract_sorted.clone(),
        &storage_sorted.clone(),
    )
    .await?;

@ArielElp ArielElp changed the base branch from ariel/abstract_fetch_all_patricia_paths to graphite-base/13992 May 18, 2026 11:36
@ArielElp ArielElp force-pushed the graphite-base/13992 branch from 526b5f0 to b6e6d57 Compare May 18, 2026 11:56
@ArielElp ArielElp force-pushed the ariel/get_leaf_indicies_utility branch from b925279 to 13ea978 Compare May 18, 2026 11:56
@ArielElp ArielElp changed the base branch from graphite-base/13992 to ariel/abstract_fetch_all_patricia_paths May 18, 2026 11:56
Copy link
Copy Markdown
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.

@ArielElp reviewed 1 file, made 3 comments, and resolved 2 discussions.
Reviewable status: all files reviewed, 1 unresolved discussion (waiting on yoavGrs).


crates/starknet_committer/src/patricia_merkle_tree/tree.rs line 28 at r1 (raw file):

Previously, yoavGrs wrote…

Restore the new line.

Done.


crates/starknet_committer/src/patricia_merkle_tree/tree.rs line 85 at r1 (raw file):

Previously, yoavGrs wrote…

Move it into impl LeavesRequest?

Done


crates/starknet_committer/src/patricia_merkle_tree/tree.rs line 247 at r1 (raw file):

Previously, yoavGrs wrote…

WDYT?
It’s logically equivalent, but I think this way makes it clearer that the code isn't doing any unnecessary work.

Done (deleted the second unnecessary sorting)

@ArielElp ArielElp force-pushed the ariel/get_leaf_indicies_utility branch from 13ea978 to d58523d Compare May 18, 2026 13:52
@ArielElp ArielElp force-pushed the ariel/get_leaf_indicies_utility branch from d58523d to 6ee8f1d Compare May 19, 2026 06:55
Copy link
Copy Markdown
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.

@ArielElp resolved 1 discussion.
Reviewable status: 0 of 1 files reviewed, 1 unresolved discussion (waiting on yoavGrs).

Copy link
Copy Markdown
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 1 file, made 3 comments, and resolved 1 discussion.
Reviewable status: all files reviewed (commit messages unreviewed), 3 unresolved discussions (waiting on ArielElp).


crates/starknet_committer/src/patricia_merkle_tree/tree.rs line 71 at r3 (raw file):

impl LeavesRequest {
    /// Builds index buffers expected by [`fetch_all_patricia_paths`].
    pub fn from(

Sorry for misleading you about the "..." I mentioned

Suggestion:

fn from_index_buffers(

crates/starknet_committer/src/patricia_merkle_tree/tree.rs line 96 at r3 (raw file):

    /// Sorts class, contract, and per-contract storage leaf index buffers in place, then returns
    /// a single [`SortedLeavesRequest`].
    pub fn get_sorted(&mut self) -> SortedLeavesRequest<'_> {

Use impl From please.


crates/starknet_committer/src/patricia_merkle_tree/tree.rs line 241 at r3 (raw file):

        LeavesRequest::from(class_hashes, contract_addresses, contract_storage_keys);

    let sorted_leaves = leaves_request.get_sorted();

Destruct here?

Suggestion:

SortedLeavesRequest{ ... } = leaves_request.get_sorted();

@ArielElp ArielElp force-pushed the ariel/get_leaf_indicies_utility branch from 6ee8f1d to 0efaf0c Compare May 19, 2026 07:52
Copy link
Copy Markdown
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.

@ArielElp reviewed 1 file and all commit messages, and made 3 comments.
Reviewable status: all files reviewed, 3 unresolved discussions (waiting on yoavGrs).


crates/starknet_committer/src/patricia_merkle_tree/tree.rs line 71 at r3 (raw file):

Previously, yoavGrs wrote…

Sorry for misleading you about the "..." I mentioned

Done.


crates/starknet_committer/src/patricia_merkle_tree/tree.rs line 96 at r3 (raw file):

Previously, yoavGrs wrote…

Use impl From please.

Done.


crates/starknet_committer/src/patricia_merkle_tree/tree.rs line 241 at r3 (raw file):

Previously, yoavGrs wrote…

Destruct here?

Done.

Copy link
Copy Markdown
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.

:lgtm:

@yoavGrs reviewed 1 file and all commit messages, made 1 comment, and resolved 3 discussions.
Reviewable status: :shipit: complete! all files reviewed, all discussions resolved (waiting on ArielElp).

@ArielElp ArielElp force-pushed the ariel/abstract_fetch_all_patricia_paths branch from 815bf53 to 8acac5f Compare May 19, 2026 12:37
@ArielElp ArielElp force-pushed the ariel/get_leaf_indicies_utility branch from 0efaf0c to b757ad2 Compare May 19, 2026 12:37
@ArielElp ArielElp force-pushed the ariel/abstract_fetch_all_patricia_paths branch from 8acac5f to 9cc1634 Compare May 20, 2026 09:03
@ArielElp ArielElp force-pushed the ariel/get_leaf_indicies_utility branch 2 times, most recently from 70039f0 to c579a4b Compare May 20, 2026 09:25
@ArielElp ArielElp force-pushed the ariel/abstract_fetch_all_patricia_paths branch from 9cc1634 to 56288b6 Compare May 20, 2026 09:25
Copy link
Copy Markdown
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 file and all commit messages, and made 2 comments.
Reviewable status: all files reviewed, 2 unresolved discussions (waiting on ArielElp).


crates/starknet_committer/src/patricia_merkle_tree/tree.rs line 57 at r4 (raw file):

/// per-contract storage leaves). Built via [`LeavesRequest::from_accessed_leaves`].
#[derive(Clone)]
pub struct LeavesRequest {

we had an equivalent concept on the py side called StateSelector. consider renaming, for SN OGs to feel at home (non-blocking)

Code quote:

pub struct LeavesRequest {

crates/starknet_committer/src/patricia_merkle_tree/tree.rs line 137 at r4 (raw file):

        "contract_sorted_leaf_indices is missing an address with requested storage witnesses. \
         contract_sorted_leaf_indices: {:?}, storage addresses: {:?}",
        contract_sorted_leaf_indices,

why the diff here? seems like it didn't have to change

Code quote:

         contract_sorted_leaf_indices: {:?}, storage addresses: {:?}",
        contract_sorted_leaf_indices,

@ArielElp ArielElp force-pushed the ariel/abstract_fetch_all_patricia_paths branch from 56288b6 to d8a881d Compare May 25, 2026 13:32
@ArielElp ArielElp force-pushed the ariel/get_leaf_indicies_utility branch from c579a4b to 869a81f Compare May 25, 2026 13:32
@ArielElp ArielElp force-pushed the ariel/abstract_fetch_all_patricia_paths branch from d8a881d to da84e37 Compare May 25, 2026 13:45
@ArielElp ArielElp force-pushed the ariel/get_leaf_indicies_utility branch from 869a81f to 96c5bcb Compare May 25, 2026 13:45
Copy link
Copy Markdown
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.

@ArielElp made 2 comments.
Reviewable status: 0 of 1 files reviewed, 2 unresolved discussions (waiting on dorimedini-starkware and yoavGrs).


crates/starknet_committer/src/patricia_merkle_tree/tree.rs line 57 at r4 (raw file):

Previously, dorimedini-starkware wrote…

we had an equivalent concept on the py side called StateSelector. consider renaming, for SN OGs to feel at home (non-blocking)

I'm not sure if they fill the same role:

class StateSelector(StateSelectorBase):

"""
A class that contains a set of StarkNet contract addresses (sub-commitment tree root IDs)
and a set of hashes of relevant contract classes
affected by one/many transaction(s).
Used for fetching those sub-trees and classes from storage before transaction(s) processing.
"""

In any case, I'm for independence from our pythonic chains


crates/starknet_committer/src/patricia_merkle_tree/tree.rs line 137 at r4 (raw file):

Previously, dorimedini-starkware wrote…

why the diff here? seems like it didn't have to change

It didn't, reverted

Copy link
Copy Markdown
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 file and all commit messages, and resolved 2 discussions.
Reviewable status: :shipit: complete! all files reviewed, all discussions resolved (waiting on ArielElp).

@ArielElp ArielElp force-pushed the ariel/abstract_fetch_all_patricia_paths branch from da84e37 to d962c4f Compare May 25, 2026 13:58
@ArielElp ArielElp force-pushed the ariel/get_leaf_indicies_utility branch from 96c5bcb to 2e17706 Compare May 25, 2026 13:58
@ArielElp ArielElp force-pushed the ariel/abstract_fetch_all_patricia_paths branch from d962c4f to b25db53 Compare May 26, 2026 10:08
@ArielElp ArielElp force-pushed the ariel/get_leaf_indicies_utility branch 2 times, most recently from 300a545 to c381bc4 Compare May 26, 2026 13:03
@ArielElp ArielElp force-pushed the ariel/abstract_fetch_all_patricia_paths branch from b25db53 to bbe1511 Compare May 26, 2026 13:03
@ArielElp ArielElp force-pushed the ariel/abstract_fetch_all_patricia_paths branch from bbe1511 to 823105d Compare May 26, 2026 13:11
@ArielElp ArielElp force-pushed the ariel/get_leaf_indicies_utility branch from c381bc4 to 1b083d2 Compare May 26, 2026 13:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants