Skip to content

fix: fix bug in tree hash function definition #121

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 19, 2024

Conversation

aner-starkware
Copy link
Contributor

@aner-starkware aner-starkware commented May 16, 2024

This change is Reviewable

@codecov-commenter
Copy link

codecov-commenter commented May 16, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 73.01%. Comparing base (8e24699) to head (b064108).
Report is 2 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #121      +/-   ##
==========================================
+ Coverage   69.98%   73.01%   +3.02%     
==========================================
  Files          27       29       +2     
  Lines        1036     1156     +120     
  Branches     1036     1156     +120     
==========================================
+ Hits          725      844     +119     
- Misses        277      280       +3     
+ Partials       34       32       -2     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@aner-starkware aner-starkware force-pushed the aner/fix_hash_function branch from f674574 to 3724a6a Compare May 16, 2024 21:05
@aner-starkware aner-starkware changed the title WIP: fix tree hash function bug: fix tree hash function May 16, 2024
@aner-starkware aner-starkware marked this pull request as ready for review May 16, 2024 21:06
@aner-starkware aner-starkware force-pushed the aner/fix_hash_function branch 2 times, most recently from fae2d41 to 7ed54e3 Compare May 16, 2024 21:14
@aner-starkware aner-starkware changed the title bug: fix tree hash function fix: fix bug in tree hash function definition May 16, 2024
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.

Reviewed 1 of 3 files at r1, 2 of 2 files at r2, all commit messages.
Reviewable status: all files reviewed, 2 unresolved discussions (waiting on @amosStarkware, @aner-starkware, @nimrod-starkware, and @TzahiTaub)


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

pub const CONTRACT_STATE_HASH_VERSION: Felt = Felt::ZERO;
// The hex string corresponding to b'CONTRACT_CLASS_LEAF_V0' in big-endian.
pub const CONTRACT_CLASS_LEAF_V0: &str = "0x434f4e54524143545f434c4153535f4c4541465f5630";

add a tiny unit test that asserts this is true

Code quote:

// The hex string corresponding to b'CONTRACT_CLASS_LEAF_V0' in big-endian.
pub const CONTRACT_CLASS_LEAF_V0: &str = "0x434f4e54524143545f434c4153535f4c4541465f5630";

crates/committer/src/patricia_merkle_tree/updated_skeleton_tree/hash_function_test.rs line 65 at r2 (raw file):

#[rstest]
// expected hash value was computed independently.

Suggestion:

Exp

@aner-starkware aner-starkware force-pushed the aner/fix_hash_function branch 2 times, most recently from 2599da5 to 74e8936 Compare May 17, 2024 13:48
Copy link
Contributor Author

@aner-starkware aner-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: 2 of 3 files reviewed, 1 unresolved discussion (waiting on @amosStarkware, @dorimedini-starkware, @nimrod-starkware, and @TzahiTaub)


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

Previously, dorimedini-starkware wrote…

add a tiny unit test that asserts this is true

Done.

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.

:lgtm:

Reviewed 1 of 1 files at r3, all commit messages.
Reviewable status: :shipit: complete! all files reviewed, all discussions resolved (waiting on @amosStarkware, @nimrod-starkware, and @TzahiTaub)

@aner-starkware aner-starkware force-pushed the aner/fix_hash_function branch 2 times, most recently from 52f7e47 to cbb2b68 Compare May 19, 2024 05:42
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.

Reviewed 4 of 4 files at r4, all commit messages.
Reviewable status: all files reviewed, 1 unresolved discussion (waiting on @amosStarkware, @aner-starkware, @nimrod-starkware, and @TzahiTaub)


crates/committer/src/patricia_merkle_tree/updated_skeleton_tree/hash_function.rs line 49 at r4 (raw file):

                    "could not parse hex string corresponding to b'CONTRACT_CLASS_LEAF_V0' to Felt",
                );
                PoseidonHashFunction::compute_hash(HashInputPair(

I don't like this... trees need two hash functions now? because the compiled class tree uses pedersen on internal nodes and poseidon on leaves?

Code quote:

PoseidonHashFunction

@aner-starkware
Copy link
Contributor Author

crates/committer/src/patricia_merkle_tree/updated_skeleton_tree/hash_function.rs line 49 at r4 (raw file):

Previously, dorimedini-starkware wrote…

I don't like this... trees need two hash functions now? because the compiled class tree uses pedersen on internal nodes and poseidon on leaves?

That's as far as I understand. Maybe we could leave it as an implementation detail (i.e., without generics) for now - we don't know if the second hash function (which is already Poseidon) will need to be changed.

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, 1 unresolved discussion (waiting on @amosStarkware, @aner-starkware, @nimrod-starkware, and @TzahiTaub)


crates/committer/src/patricia_merkle_tree/updated_skeleton_tree/hash_function.rs line 49 at r4 (raw file):

Previously, aner-starkware wrote…

That's as far as I understand. Maybe we could leave it as an implementation detail (i.e., without generics) for now - we don't know if the second hash function (which is already Poseidon) will need to be changed.

I think we need to get rid of HashFunction and only keep TreeHashFunction, and all implementation details / low-level hash function choices should be in the tree hash function.
Out of scope of this PR anyway;
please add a TODO over this line and I'll unblock

@aner-starkware aner-starkware force-pushed the aner/fix_hash_function branch from cbb2b68 to b064108 Compare May 19, 2024 13:37
@aner-starkware
Copy link
Contributor Author

crates/committer/src/patricia_merkle_tree/updated_skeleton_tree/hash_function.rs line 49 at r4 (raw file):

Previously, dorimedini-starkware wrote…

I think we need to get rid of HashFunction and only keep TreeHashFunction, and all implementation details / low-level hash function choices should be in the tree hash function.
Out of scope of this PR anyway;
please add a TODO over this line and I'll unblock

Done.

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.

Reviewed 1 of 1 files at r5, all commit messages.
Reviewable status: :shipit: complete! all files reviewed, all discussions resolved (waiting on @amosStarkware, @nimrod-starkware, and @TzahiTaub)

@aner-starkware aner-starkware added this pull request to the merge queue May 19, 2024
Merged via the queue into main with commit 6d64546 May 19, 2024
11 checks passed
@aner-starkware aner-starkware deleted the aner/fix_hash_function branch May 20, 2024 06:31
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.

3 participants