Skip to content

Conversation

@MaksymMalicki
Copy link
Contributor

@MaksymMalicki MaksymMalicki commented Nov 28, 2025

This PR addresses #3282 (comment), and uses more descriptive felt.Hash type for owner fields in all triedb and trie2 packages

@codecov
Copy link

codecov bot commented Nov 28, 2025

Codecov Report

❌ Patch coverage is 72.07207% with 31 lines in your changes missing coverage. Please review.
✅ Project coverage is 76.16%. Comparing base (584e500) to head (96d28a1).

Files with missing lines Patch % Lines
core/trie2/trie.go 28.57% 20 Missing ⚠️
core/trie2/triedb/pathdb/journal.go 37.50% 5 Missing ⚠️
core/trie2/databasetest.go 33.33% 2 Missing ⚠️
core/trie2/trieutils/accessors.go 50.00% 2 Missing ⚠️
core/trie2/triedb/hashdb/database.go 94.11% 1 Missing ⚠️
core/trie2/triedb/rawdb/database.go 0.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #3316      +/-   ##
==========================================
- Coverage   76.20%   76.16%   -0.05%     
==========================================
  Files         346      346              
  Lines       32690    32738      +48     
==========================================
+ Hits        24912    24935      +23     
- Misses       5987     6009      +22     
- Partials     1791     1794       +3     

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

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@MaksymMalicki MaksymMalicki force-pushed the maksym/refactor-triedb-address branch 2 times, most recently from 9210f6f to 090e07a Compare December 3, 2025 17:59
@MaksymMalicki MaksymMalicki force-pushed the maksym/refactor-triedb-hash branch from ad10776 to 6bee396 Compare December 3, 2025 19:19
Base automatically changed from maksym/refactor-triedb-address to main December 4, 2025 05:22
@MaksymMalicki MaksymMalicki force-pushed the maksym/refactor-triedb-hash branch from 6a421db to 886e905 Compare December 5, 2025 11:49
@MaksymMalicki MaksymMalicki force-pushed the maksym/refactor-triedb-hash branch from 886e905 to 96d28a1 Compare December 5, 2025 13:13
stateCommitment := felt.NewFromUint64[felt.Felt](1000)
classRootHash := felt.NewFromUint64[felt.Felt](2000)
contractRootHash := felt.NewFromUint64[felt.Felt](3000)
stateCommitment := felt.NewFromUint64[felt.Hash](uint64(1000))
Copy link
Collaborator

Choose a reason for hiding this comment

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

nitpick -> This uint64(...) seems redundant?

Comment on lines +152 to +154
classNodes map[felt.Hash]map[trieutils.Path]trienode.TrieNode
contractNodes map[felt.Hash]map[trieutils.Path]trienode.TrieNode
contractStorageNodes map[felt.Hash]map[felt.Address]map[trieutils.Path]trienode.TrieNode
Copy link
Collaborator

Choose a reason for hiding this comment

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

felt.Hash is the most general type, but I think it is being miss-used.

felt.Hash means that there is not a good type to define it and it makes sense to be a general type, for example the return type of hashing function.

On the other hand, here we know the semantic meaning each hash has here, so we should use the appropriate types.

As far as I understand, it should be:

  1. classNodes keys should be of type felt.ClassHash
  2. contractNodes should be of type felt.Address since it is a contract address
  3. contractStorageNodes should be of type felt.Address to felt.StorageAddress (or felt.StorageSlot). <- The latter types are to be defined

// Tracks all unique and latest nodes in the layer tree
classPaths map[trieutils.Path]trienode.TrieNode
contractPaths map[trieutils.Path]trienode.TrieNode
contractStoragePaths map[felt.Address]map[trieutils.Path]trienode.TrieNode
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is this Address referencing StorageAddress, if that's the case, then it is being miss-used.

Address strictly refers to a Starknet contract address – this has been discussed both in dailies and slack.


stateComm := id.StateComm()
if stateComm.IsZero() {
if (*felt.Felt)(&stateComm).IsZero() {
Copy link
Collaborator

Choose a reason for hiding this comment

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

let's avoid the use of this casting


stateComm := id.StateComm()
if stateComm.IsZero() {
if (*felt.Felt)(&stateComm).IsZero() {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Here as well please

func (t *layerTracker) trackLayer(root, parent *felt.Felt) {
if root.Equal(parent) {
func (t *layerTracker) trackLayer(root, parent *felt.Hash) {
if (*felt.Felt)(root).Equal((*felt.Felt)(parent)) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Avoid this second conversion


// Child to parent layer relationship
childToParent map[felt.Felt]felt.Felt
childToParent map[felt.Hash]felt.Hash
Copy link
Collaborator

Choose a reason for hiding this comment

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

Similar coment to the previous ones, what would be the right hash here?

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