Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 4 additions & 5 deletions execution/commitment/hex_patricia_hashed.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -1946,15 +1946,14 @@ 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)
return fmt.Errorf("failed to encode branch deletion: %w", err)
}
}
return nil
Expand Down
25 changes: 0 additions & 25 deletions execution/commitment/keys_nibbles.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package commitment

import (
"errors"
"fmt"
"strconv"
"strings"
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion execution/commitment/streaming_deep_fold.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
Expand Down
Loading