Skip to content

Commit

Permalink
remove legacy function
Browse files Browse the repository at this point in the history
  • Loading branch information
antonis19 committed Jan 15, 2025
1 parent 18ea27e commit 0fe703a
Showing 1 changed file with 1 addition and 34 deletions.
35 changes: 1 addition & 34 deletions erigon-lib/commitment/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,11 @@
package commitment

import (
"bytes"
"errors"
"fmt"

"github.com/erigontech/erigon-lib/common/length"
"github.com/erigontech/erigon-lib/crypto"
"golang.org/x/crypto/sha3"
)

// nibblize a key : e.g. [0xab] => [0x0a, 0x0b]
Expand All @@ -35,32 +33,6 @@ func Nibblize(key []byte) []byte { // nolint:unused
return nibblized
}

func legacyHashAndNibblizeKey(key []byte) []byte {
hashedKey := make([]byte, length.Hash)
keccak := sha3.NewLegacyKeccak256().(keccakState)
keccak.Reset()
fp := length.Addr
if len(key) < length.Addr {
fp = len(key)
}
keccak.Write(key[:fp])
keccak.Read(hashedKey[:length.Hash])

if len(key[fp:]) > 0 {
hashedKey = append(hashedKey, make([]byte, length.Hash)...)
keccak.Reset()
keccak.Write(key[fp:])
keccak.Read(hashedKey[length.Hash:])
}

nibblized := make([]byte, len(hashedKey)*2)
for i, b := range hashedKey {
nibblized[i*2] = (b >> 4) & 0xf
nibblized[i*2+1] = b & 0xf
}
return nibblized
}

// Hash the account or storage key and return the resulting hashed key in the nibblized form
func HashAndNibblizeKey(key []byte) []byte {
keyLen := length.Addr
Expand All @@ -72,12 +44,7 @@ func HashAndNibblizeKey(key []byte) []byte {
storageKeyHash := crypto.Keccak256(key[length.Addr:])
compactedHashKey = append(compactedHashKey, storageKeyHash...)
}
result := Nibblize(compactedHashKey)
legacyResult := legacyHashAndNibblizeKey(key)
if !bytes.Equal(result, legacyResult) {
panic("result not equal with legacy function")
}
return result
return Nibblize(compactedHashKey)
}

func CompactedKeyToHex(compact []byte) []byte {
Expand Down

0 comments on commit 0fe703a

Please sign in to comment.