Skip to content

starknet_committer: compute and store accessed keys digest#13993

Open
ArielElp wants to merge 1 commit into
ariel/get_leaf_indicies_utilityfrom
ariel/accessed_keys_digest
Open

starknet_committer: compute and store accessed keys digest#13993
ArielElp wants to merge 1 commit into
ariel/get_leaf_indicies_utilityfrom
ariel/accessed_keys_digest

Conversation

@ArielElp
Copy link
Copy Markdown
Contributor

@ArielElp ArielElp commented May 7, 2026

No description provided.

@reviewable-StarkWare
Copy link
Copy Markdown

This change is Reviewable

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.

@cursor
Copy link
Copy Markdown

cursor Bot commented May 14, 2026

PR Summary

Low Risk
Additive, feature-gated hashing helper with no changes to default builds or existing serialization paths.

Overview
Adds an os_input Cargo feature on starknet_committer that pulls in optional blake2 / digest and exposes accessed_keys_digest in serde_db_utils.

That function builds a canonical, length-prefixed byte encoding of a SortedLeavesRequest (classes trie, contracts trie, then per-contract storage leaves with sorted contract keys) and returns a BLAKE2s-256 32-byte digest. This gives a stable fingerprint of accessed Patricia leaf indices for OS-input / witness-related flows without changing default builds (everything is behind cfg(feature = "os_input")).

Reviewed by Cursor Bugbot for commit 5a5ff22. 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 2 files and all commit messages, and made 1 comment.
Reviewable status: all files reviewed, 1 unresolved discussion (waiting on ArielElp).


crates/starknet_committer/src/db/serde_db_utils.rs line 60 at r1 (raw file):

) -> [u8; 32] {
    let mut class_hashes: Vec<ClassHash> = class_hashes.iter().copied().collect();
    class_hashes.sort();

In the previous PR you sort it. Define a "sorted" struct?

Code quote:

class_hashes.sort();

@ArielElp ArielElp force-pushed the ariel/accessed_keys_digest branch from 7768006 to 88273cc Compare May 18, 2026 11:56
@ArielElp ArielElp force-pushed the ariel/get_leaf_indicies_utility branch 2 times, most recently from 13ea978 to d58523d Compare May 18, 2026 13:52
@ArielElp ArielElp force-pushed the ariel/accessed_keys_digest branch from 88273cc to 482d5eb Compare May 18, 2026 13:52
@ArielElp ArielElp force-pushed the ariel/get_leaf_indicies_utility branch from 6ee8f1d to 0efaf0c Compare May 19, 2026 07:52
@ArielElp ArielElp force-pushed the ariel/accessed_keys_digest branch from 40dd29b to 26ed95b Compare May 19, 2026 08:02
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 partially reviewed 2 files and made 2 comments.
Reviewable status: 0 of 3 files reviewed, 2 unresolved discussions (waiting on yoavGrs).


crates/starknet_committer/src/db/serde_db_utils.rs line 39 at r2 (raw file):

Previously, yoavGrs wrote…

Document the structure of the payload

Done.


crates/starknet_committer/src/db/serde_db_utils.rs line 72 at r2 (raw file):

Previously, yoavGrs wrote…

Avoid using as.

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 2 files and all commit messages, made 1 comment, and resolved 2 discussions.
Reviewable status: 2 of 3 files reviewed, all discussions resolved (waiting on ArielElp).

@ArielElp ArielElp force-pushed the ariel/accessed_keys_digest branch from 26ed95b to e4503a6 Compare May 19, 2026 12:37
@ArielElp ArielElp force-pushed the ariel/get_leaf_indicies_utility branch 2 times, most recently from b757ad2 to 70039f0 Compare May 20, 2026 09:03
@ArielElp ArielElp force-pushed the ariel/accessed_keys_digest branch 2 times, most recently from 31307c5 to f3ae5b0 Compare May 20, 2026 09:25
@ArielElp ArielElp force-pushed the ariel/get_leaf_indicies_utility branch from 70039f0 to c579a4b Compare May 20, 2026 09:25
@ArielElp ArielElp force-pushed the ariel/accessed_keys_digest branch from f3ae5b0 to 959f1cf Compare May 25, 2026 13:32
@ArielElp ArielElp force-pushed the ariel/get_leaf_indicies_utility branch 2 times, most recently from 869a81f to 96c5bcb Compare May 25, 2026 13:45
@ArielElp ArielElp force-pushed the ariel/accessed_keys_digest branch from 959f1cf to 7f4f979 Compare May 25, 2026 13:45
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 3 files and all commit messages, and made 4 comments.
Reviewable status: all files reviewed, 4 unresolved discussions (waiting on ArielElp).


crates/starknet_committer/Cargo.toml line 15 at r4 (raw file):

[dependencies]
blake2 = { workspace = true, optional = true }
digest = { workspace = true, optional = true }

excuse me ser we sort dependencies here

Code quote:

blake2 = { workspace = true, optional = true }
digest = { workspace = true, optional = true }

crates/starknet_committer/src/db/serde_db_utils.rs line 47 at r4 (raw file):

///    (already sorted within the contract).
#[cfg(feature = "os_input")]
pub fn accessed_keys_digest(sorted: &SortedLeavesRequest<'_>) -> [u8; 32] {

consider making this a method of SortedLeavesRequest

Code quote:

pub fn accessed_keys_digest(sorted: &SortedLeavesRequest<'_>) -> [u8; 32] {

crates/starknet_committer/src/db/serde_db_utils.rs line 63 at r4 (raw file):

    let mut contract_indices: Vec<NodeIndex> = sorted.storage_sorted.keys().copied().collect();
    contract_indices.sort_unstable();

unstable? why?
also, why do you need to sort at all? isn't that what SortedLeavesRequest is for?
if it's because of the HashMap field, consider using a BTreeMap field to get well-defined key order in the struct itself

Code quote:

contract_indices.sort_unstable();

crates/starknet_committer/src/db/serde_db_utils.rs line 81 at r4 (raw file):

#[cfg(feature = "os_input")]
fn encode_usize(n: usize) -> [u8; 4] {
    u32::try_from(n).expect("accessed leaf count exceeds u32::MAX").to_be_bytes()

mmmmmm why not u64? and return [u8; 8]? it doesn't matter much, and we won't have to answer the question "will we ever read 4B leaves"?

Code quote:

u32::try_from(n).expect("accessed leaf count exceeds u32::MAX").to_be_bytes()

@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/accessed_keys_digest branch from 7f4f979 to 22efed7 Compare May 25, 2026 13:58
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 all commit messages and made 4 comments.
Reviewable status: all files reviewed, 4 unresolved discussions (waiting on dorimedini-starkware).


crates/starknet_committer/Cargo.toml line 15 at r4 (raw file):

Previously, dorimedini-starkware wrote…

excuse me ser we sort dependencies here

Done.


crates/starknet_committer/src/db/serde_db_utils.rs line 47 at r4 (raw file):

Previously, dorimedini-starkware wrote…

consider making this a method of SortedLeavesRequest

IMO given that it's db-serialization related, it's slightly better placed here, but won't insist if you prefer moving.


crates/starknet_committer/src/db/serde_db_utils.rs line 63 at r4 (raw file):

Previously, dorimedini-starkware wrote…

unstable? why?
also, why do you need to sort at all? isn't that what SortedLeavesRequest is for?
if it's because of the HashMap field, consider using a BTreeMap field to get well-defined key order in the struct itself

AI decision, it's supposed to be marginally faster, and you know there are no duplications here (it's the keys from a HashMap).


crates/starknet_committer/src/db/serde_db_utils.rs line 81 at r4 (raw file):

Previously, dorimedini-starkware wrote…

mmmmmm why not u64? and return [u8; 8]? it doesn't matter much, and we won't have to answer the question "will we ever read 4B leaves"?

Done.

@ArielElp ArielElp force-pushed the ariel/accessed_keys_digest branch from 22efed7 to 093fc19 Compare May 25, 2026 14:13
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 2 files and all commit messages, made 1 comment, and resolved 3 discussions.
Reviewable status: all files reviewed, 1 unresolved discussion (waiting on ArielElp).


crates/starknet_committer/src/db/serde_db_utils.rs line 63 at r4 (raw file):

Previously, ArielElp wrote…

AI decision, it's supposed to be marginally faster, and you know there are no duplications here (it's the keys from a HashMap).

but with a HashMap, order is not well defined, and you could get different digests for the same input. right?

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 1 comment.
Reviewable status: all files reviewed, 1 unresolved discussion (waiting on dorimedini-starkware).


crates/starknet_committer/src/db/serde_db_utils.rs line 63 at r4 (raw file):

Previously, dorimedini-starkware wrote…

but with a HashMap, order is not well defined, and you could get different digests for the same input. right?

Hence the sort, sort unstable is just about ordering of equal elements

@ArielElp ArielElp force-pushed the ariel/get_leaf_indicies_utility branch from 2e17706 to 300a545 Compare May 26, 2026 10:08
@ArielElp ArielElp force-pushed the ariel/accessed_keys_digest branch 2 times, most recently from 11d186a to c9ac657 Compare May 26, 2026 13:03
@ArielElp ArielElp force-pushed the ariel/get_leaf_indicies_utility branch from 300a545 to c381bc4 Compare May 26, 2026 13:03
@ArielElp ArielElp force-pushed the ariel/accessed_keys_digest branch from c9ac657 to 5a5ff22 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