From 2a8b53613a7b515e63c826f572111f81b7f598c2 Mon Sep 17 00:00:00 2001 From: awskii Date: Tue, 11 Aug 2026 17:56:28 +0700 Subject: [PATCH 1/2] execution/commitment: drop dead accessors and a vestigial parameter - cell.GetAccountAddr / cell.GetStorageAddr: no reference anywhere, including tests. - CompactKey: no reference anywhere, including tests. - collectDeleteUpdate's evictCache parameter: #21380 removed the hph.cache.EvictBranch call it gated when the trie stopped owning a cache, leaving the parameter unread and its docstring describing eviction that no longer happens. All three call sites passed true. EvictBranch no longer exists in the tree, so nothing moved rather than being lost. --- execution/commitment/hex_patricia_hashed.go | 7 +++--- execution/commitment/keys_nibbles.go | 25 --------------------- execution/commitment/streaming_deep_fold.go | 2 +- execution/commitment/trie_reader.go | 6 ----- 4 files changed, 4 insertions(+), 36 deletions(-) diff --git a/execution/commitment/hex_patricia_hashed.go b/execution/commitment/hex_patricia_hashed.go index f526dc75cbd..e5f674dab19 100644 --- a/execution/commitment/hex_patricia_hashed.go +++ b/execution/commitment/hex_patricia_hashed.go @@ -1914,7 +1914,7 @@ func (hph *HexPatriciaHashed) foldPropagate(row int, nibble, upDepth, depth int1 // propagate cell into parent row upCell.fillFromLowerCell(cell, depth, hph.currentKey[upDepth:hph.currentKeyLen], childNibble) - if err := hph.collectDeleteUpdate(updateKey, row, true); err != nil { + if err := hph.collectDeleteUpdate(updateKey, row); err != nil { return err } if hph.traceW != nil { @@ -1946,12 +1946,11 @@ func (hph *HexPatriciaHashed) foldDelete(row int, nibble, upDepth int16, upCell } upCell.reset() - return hph.collectDeleteUpdate(updateKey, row, true) + return hph.collectDeleteUpdate(updateKey, row) } // collectDeleteUpdate encodes a branch deletion if a branch existed before at this row. -// If evictCache is true, it also evicts the branch from the cache. -func (hph *HexPatriciaHashed) collectDeleteUpdate(updateKey []byte, row int, evictCache bool) error { +func (hph *HexPatriciaHashed) collectDeleteUpdate(updateKey []byte, row int) error { if hph.branchBefore[row] { if err := hph.branchEncoder.CollectUpdate(hph.ctx, updateKey, 0, hph.touchMap[row], 0, nil, false); err != nil { return fmt.Errorf("failed to encode leaf node update: %w", err) diff --git a/execution/commitment/keys_nibbles.go b/execution/commitment/keys_nibbles.go index f6474b14945..5aa2efa3a4f 100644 --- a/execution/commitment/keys_nibbles.go +++ b/execution/commitment/keys_nibbles.go @@ -1,7 +1,6 @@ package commitment import ( - "errors" "fmt" "strconv" "strings" @@ -107,30 +106,6 @@ func NibblesToString(nibbles []byte) string { return b.String() } -// CompactKey takes a slice of nibbles and compacts them into the original byte slice. -// It returns an error if the input contains invalid nibbles (values > 0xF). -func CompactKey(nibbles []byte) ([]byte, error) { - // If the number of nibbles is odd, you might decide to handle it differently. - // For this example, we'll return an error. - if len(nibbles)%2 != 0 { - return nil, errors.New("nibbles slice has an odd length") - } - - key := make([]byte, len(nibbles)/2) - for i := range key { - highNibble := nibbles[i*2] - lowNibble := nibbles[i*2+1] - - // Validate that each nibble is indeed a nibble - if highNibble > 0xF || lowNibble > 0xF { - return nil, fmt.Errorf("invalid nibble at position %d or %d: 0x%X, 0x%X", i*2, i*2+1, highNibble, lowNibble) - } - - key[i] = (highNibble << 4) | (lowNibble & 0x0F) - } - return key, nil -} - // updatedNibs returns a string of nibbles that are set in the given number. func updatedNibs(num uint16) string { var nibbles []string diff --git a/execution/commitment/streaming_deep_fold.go b/execution/commitment/streaming_deep_fold.go index de1cc4ed435..faaba524ddf 100644 --- a/execution/commitment/streaming_deep_fold.go +++ b/execution/commitment/streaming_deep_fold.go @@ -267,7 +267,7 @@ func storageRootFromSingleChild(base *HexPatriciaHashed) (cell, error) { // The prior on-disk branch at the account prefix, if any, is now an extension: no branch record. if base.branchBefore[0] { - if err := base.collectDeleteUpdate(nibbles.HexToCompact(base.currentKey[:base.currentKeyLen]), 0, true); err != nil { + if err := base.collectDeleteUpdate(nibbles.HexToCompact(base.currentKey[:base.currentKeyLen]), 0); err != nil { return cell{}, err } } diff --git a/execution/commitment/trie_reader.go b/execution/commitment/trie_reader.go index 953597e71b3..a63de9f1017 100644 --- a/execution/commitment/trie_reader.go +++ b/execution/commitment/trie_reader.go @@ -47,12 +47,6 @@ func (c *cell) StorageAddrLen() int { return int(c.storageAddrLen) } // HashLen returns the length of the cell hash. func (c *cell) HashLen() int { return int(c.hashLen) } -// AccountAddr returns the account plain key bytes (up to accountAddrLen). -func (c *cell) GetAccountAddr() []byte { return c.accountAddr[:c.accountAddrLen] } - -// StorageAddr returns the storage plain key bytes (up to storageAddrLen). -func (c *cell) GetStorageAddr() []byte { return c.storageAddr[:c.storageAddrLen] } - // CellHash returns the cell hash bytes (up to hashLen). func (c *cell) CellHash() []byte { return c.hash[:c.hashLen] } From 494f6457e70484be5dc2b9f58e505b6112704ad3 Mon Sep 17 00:00:00 2001 From: awskii Date: Tue, 11 Aug 2026 20:35:38 +0700 Subject: [PATCH 2/2] execution/commitment: name the branch deletion in collectDeleteUpdate's error --- execution/commitment/hex_patricia_hashed.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/execution/commitment/hex_patricia_hashed.go b/execution/commitment/hex_patricia_hashed.go index e5f674dab19..2d9c8b6bb05 100644 --- a/execution/commitment/hex_patricia_hashed.go +++ b/execution/commitment/hex_patricia_hashed.go @@ -1953,7 +1953,7 @@ func (hph *HexPatriciaHashed) foldDelete(row int, nibble, upDepth int16, upCell func (hph *HexPatriciaHashed) collectDeleteUpdate(updateKey []byte, row int) error { if hph.branchBefore[row] { if err := hph.branchEncoder.CollectUpdate(hph.ctx, updateKey, 0, hph.touchMap[row], 0, nil, false); err != nil { - return fmt.Errorf("failed to encode leaf node update: %w", err) + return fmt.Errorf("failed to encode branch deletion: %w", err) } } return nil