Skip to content

starknet_committer: define StarknetForestProofs serde#13994

Open
ArielElp wants to merge 1 commit into
ariel/accessed_keys_digestfrom
ariel/patricia_paths_storage_serialization
Open

starknet_committer: define StarknetForestProofs serde#13994
ArielElp wants to merge 1 commit into
ariel/accessed_keys_digestfrom
ariel/patricia_paths_storage_serialization

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.

@ArielElp ArielElp force-pushed the ariel/patricia_paths_storage_serialization branch from 2092a49 to f0e3f55 Compare May 7, 2026 12:40
@ArielElp ArielElp force-pushed the ariel/accessed_keys_digest branch from 19be0db to 7768006 Compare May 14, 2026 08:43
@ArielElp ArielElp force-pushed the ariel/patricia_paths_storage_serialization branch 2 times, most recently from 6d8fca8 to f34a751 Compare May 18, 2026 11:56
@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/patricia_paths_storage_serialization branch from f34a751 to 540e432 Compare May 18, 2026 13:52
@ArielElp ArielElp force-pushed the ariel/accessed_keys_digest branch from 482d5eb to 8149407 Compare May 19, 2026 06:55
@ArielElp ArielElp force-pushed the ariel/patricia_paths_storage_serialization branch 2 times, most recently from 48f73db to 40a2552 Compare May 19, 2026 07:08
@ArielElp ArielElp requested a review from yoavGrs May 19, 2026 07:09
@ArielElp ArielElp marked this pull request as ready for review May 19, 2026 07:09
@cursor
Copy link
Copy Markdown

cursor Bot commented May 19, 2026

PR Summary

Medium Risk
Touches state-commitment witness encoding for the OS; wire-format mistakes could break prover input, though scope is feature-gated and covered by round-trip tests.

Overview
Adds bincode serialization for StarknetForestProofs behind the os_input feature so Patricia Merkle witnesses can be written to and read from DbValue for OS-input flows.

serialize / deserialize flatten classes trie nodes, contract trie nodes and leaves, and per-contract storage trie preimages into a fixed four-part bincode tuple, using the same binary/edge Felt encodings as existing commitment facts and OS Patricia hints. Deserialization rebuilds PreimageMaps and rejects duplicate node hashes, contract leaves, or storage witnesses.

ContractsTrieProof and StarknetForestProofs gain Debug and PartialEq; extend is now public. Round-trip tests cover several witness shapes when os_input is enabled in tests.

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

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: 0 of 5 files reviewed, 1 unresolved discussion (waiting on yoavGrs).


a discussion (no related file):

Previously, yoavGrs wrote…

For each object, test that deser(ser(object)) == object.

Done.

@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/patricia_paths_storage_serialization branch from 0ac92db to 111d357 Compare May 19, 2026 12:37
@ArielElp ArielElp force-pushed the ariel/accessed_keys_digest branch from e4503a6 to 31307c5 Compare May 20, 2026 09:03
@ArielElp ArielElp force-pushed the ariel/patricia_paths_storage_serialization branch from 111d357 to 063f6b4 Compare May 20, 2026 09:03
@ArielElp ArielElp force-pushed the ariel/accessed_keys_digest branch from 31307c5 to f3ae5b0 Compare May 20, 2026 09:25
@ArielElp ArielElp force-pushed the ariel/patricia_paths_storage_serialization branch from 063f6b4 to e9e5c4e Compare May 20, 2026 09:25
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 5 files and all commit messages, made 6 comments, and resolved 1 discussion.
Reviewable status: all files reviewed, 6 unresolved discussions (waiting on ArielElp).


crates/starknet_committer/src/patricia_merkle_tree/starknet_forest_proofs_serialization_test.rs line 128 at r2 (raw file):

}

#[template]

Why do you need the template?


crates/starknet_committer/src/patricia_merkle_tree/types.rs line 97 at r2 (raw file):

    /// 3. Contract trie leaves — `Vec<(ContractAddress, (Nonce, HashOutput, ClassHash))>`, sorted
    ///    by contract address.
    /// 4. Storage trie inner nodes — `Vec<(ContractAddress, Vec<(HashOutput, encoded_preimage)>)>`,

?

Suggestion:

tries

crates/starknet_committer/src/patricia_merkle_tree/types.rs line 113 at r2 (raw file):

            .leaves
            .iter()
            .map(|(addr, s)| (*addr, (s.nonce, s.storage_root_hash, s.class_hash)))

Full names, please

Suggestion:

addr, state)

crates/starknet_committer/src/patricia_merkle_tree/types.rs line 120 at r2 (raw file):

        for (addr, m) in &self.contracts_trie_storage_proofs {
            storage.push((*addr, sorted_encoded_preimage_map(m)?));
        }

In Rust, it's idiomatic to create a vector by iter().map().collect().

Code quote:

        let mut storage: Vec<(ContractAddress, Vec<(HashOutput, Vec<u8>)>)> = Vec::new();
        for (addr, m) in &self.contracts_trie_storage_proofs {
            storage.push((*addr, sorted_encoded_preimage_map(m)?));
        }

crates/starknet_committer/src/patricia_merkle_tree/types.rs line 167 at r2 (raw file):

            {
                return Err(DeserializationError::KeyDuplicate(format!(
                    "duplicate storage trie witness key {addr:?}"

Suggestion:

address

crates/starknet_committer/src/patricia_merkle_tree/types.rs line 270 at r2 (raw file):

) -> Result<Vec<(HashOutput, Vec<u8>)>, SerializationError> {
    let mut v = Vec::with_capacity(m.len());
    for (h, p) in m {

Give full names, please

Suggestion:

for (hash, preimage) in m

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 6 comments.
Reviewable status: all files reviewed, 6 unresolved discussions (waiting on yoavGrs).


crates/starknet_committer/src/patricia_merkle_tree/starknet_forest_proofs_serialization_test.rs line 128 at r2 (raw file):

Previously, yoavGrs wrote…

Why do you need the template?

Removed


crates/starknet_committer/src/patricia_merkle_tree/types.rs line 97 at r2 (raw file):

Previously, yoavGrs wrote…

?

Done.


crates/starknet_committer/src/patricia_merkle_tree/types.rs line 113 at r2 (raw file):

Previously, yoavGrs wrote…

Full names, please

Done.


crates/starknet_committer/src/patricia_merkle_tree/types.rs line 120 at r2 (raw file):

Previously, yoavGrs wrote…

In Rust, it's idiomatic to create a vector by iter().map().collect().

Done.


crates/starknet_committer/src/patricia_merkle_tree/types.rs line 270 at r2 (raw file):

Previously, yoavGrs wrote…

Give full names, please

Done.


crates/starknet_committer/src/patricia_merkle_tree/types.rs line 167 at r2 (raw file):

            {
                return Err(DeserializationError::KeyDuplicate(format!(
                    "duplicate storage trie witness key {addr:?}"

Done.

@ArielElp ArielElp force-pushed the ariel/patricia_paths_storage_serialization branch from e9e5c4e to bfe1119 Compare May 25, 2026 08:57
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 resolved 6 discussions.
Reviewable status: :shipit: complete! all files reviewed, all discussions resolved (waiting on ArielElp).

@ArielElp ArielElp force-pushed the ariel/patricia_paths_storage_serialization branch from bfe1119 to f0b03b9 Compare May 25, 2026 13:32
@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/patricia_paths_storage_serialization branch from f0b03b9 to cfe6585 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
@ArielElp ArielElp force-pushed the ariel/patricia_paths_storage_serialization branch from cfe6585 to 8e92e61 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
@ArielElp ArielElp force-pushed the ariel/patricia_paths_storage_serialization branch from 8e92e61 to fcb80de 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 3 files and all commit messages, and made 4 comments.
Reviewable status: all files reviewed, 4 unresolved discussions (waiting on ArielElp).


crates/starknet_committer/src/patricia_merkle_tree/starknet_forest_proofs_serialization_test.rs line 52 at r5 (raw file):

        class_hash: ClassHash(Felt::from(class_hash)),
    }
}

can you ask claude if similar test utils exist in the patricia/committer crates? seems like duplication to me, I vaguely recall similar stuff

Code quote:

fn binary_preimage(node_hash: u128, left: u128, right: u128) -> (HashOutput, Preimage) {
    (
        HashOutput(Felt::from(node_hash)),
        Preimage::Binary(BinaryData {
            left_data: HashOutput(Felt::from(left)),
            right_data: HashOutput(Felt::from(right)),
        }),
    )
}

fn edge_preimage(node_hash: u128, bottom: u128, path: u128, length: u8) -> (HashOutput, Preimage) {
    (
        HashOutput(Felt::from(node_hash)),
        Preimage::Edge(EdgeData {
            bottom_data: HashOutput(Felt::from(bottom)),
            path_to_bottom: PathToBottom::new(
                EdgePath(U256::from(path)),
                EdgePathLength::new(length).unwrap(),
            )
            .unwrap(),
        }),
    )
}

fn contract_state(nonce: u128, storage_root: u128, class_hash: u128) -> ContractState {
    ContractState {
        nonce: Nonce(Felt::from(nonce)),
        storage_root_hash: HashOutput(Felt::from(storage_root)),
        class_hash: ClassHash(Felt::from(class_hash)),
    }
}

crates/starknet_committer/src/patricia_merkle_tree/types.rs at r5 (raw file):
can you move the additions here to a separate module gated by os_input?
there shouldn't be a problem, adding another impl block.
I ask because of all the gated-imports - generally a sign that a new module is a good choice


crates/starknet_committer/src/patricia_merkle_tree/types.rs line 78 at r5 (raw file):

}

impl StarknetForestProofs {

why are the (de)serialize functions here needed?
we already have serde logic for facts layout, or at least we have deserialization logic for facts layout. this logic is used by the py-side ambassador to encode commitment infos for OS runs. can't you reuse it?


crates/starknet_committer/src/patricia_merkle_tree/types.rs line 88 at r5 (raw file):

    }

    /// Bincode payload for the OS-input witness KV (structured proofs, round-trips with

KV?

Code quote:

KV

@ArielElp ArielElp force-pushed the ariel/patricia_paths_storage_serialization branch 3 times, most recently from a6fd9aa to c39b0f2 Compare May 26, 2026 11:42
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 4 comments.
Reviewable status: 3 of 6 files reviewed, 4 unresolved discussions (waiting on dorimedini-starkware and yoavGrs).


crates/starknet_committer/src/patricia_merkle_tree/starknet_forest_proofs_serialization_test.rs line 52 at r5 (raw file):

Previously, dorimedini-starkware wrote…

can you ask claude if similar test utils exist in the patricia/committer crates? seems like duplication to me, I vaguely recall similar stuff

Doesn't look like it, existing tests also explicitly construct ContractState and I don't see (or Cursor) something for Preimage


crates/starknet_committer/src/patricia_merkle_tree/types.rs line 78 at r5 (raw file):

Previously, dorimedini-starkware wrote…

why are the (de)serialize functions here needed?
we already have serde logic for facts layout, or at least we have deserialization logic for facts layout. this logic is used by the py-side ambassador to encode commitment infos for OS runs. can't you reuse it?

For the OsBlockInput constructed in tests we use deserialization of CommitmentInfo, which is a bit more raw compared to StarknetForestProofs.

I kept the structure of StarknetForestProofs, but now reusing the existing encoding/decoding of Preimage, so most of the new code is gone.


crates/starknet_committer/src/patricia_merkle_tree/types.rs line 88 at r5 (raw file):

Previously, dorimedini-starkware wrote…

KV?

AI for the key value preimage map, changed to OS input witnesses


crates/starknet_committer/src/patricia_merkle_tree/types.rs at r5 (raw file):

Previously, dorimedini-starkware wrote…

can you move the additions here to a separate module gated by os_input?
there shouldn't be a problem, adding another impl block.
I ask because of all the gated-imports - generally a sign that a new module is a good choice

Done.

@ArielElp ArielElp force-pushed the ariel/accessed_keys_digest branch from 11d186a to c9ac657 Compare May 26, 2026 13:03
@ArielElp ArielElp force-pushed the ariel/patricia_paths_storage_serialization branch from c39b0f2 to a5cc604 Compare May 26, 2026 13:03
@ArielElp ArielElp force-pushed the ariel/patricia_paths_storage_serialization branch from a5cc604 to 7b294f1 Compare May 26, 2026 13:11
@ArielElp ArielElp force-pushed the ariel/accessed_keys_digest branch from c9ac657 to 5a5ff22 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