diff --git a/core/rawdb/database.go b/core/rawdb/database.go index a03dbafb1f..5be5bff72a 100644 --- a/core/rawdb/database.go +++ b/core/rawdb/database.go @@ -642,7 +642,6 @@ func SafeDeleteRange(db ethdb.KeyValueStore, start, end []byte, hashScheme bool, var ( count, deleted, skipped int - buff = crypto.NewKeccakState() startTime = time.Now() ) @@ -655,7 +654,7 @@ func SafeDeleteRange(db ethdb.KeyValueStore, start, end []byte, hashScheme bool, for it.Next() && bytes.Compare(end, it.Key()) > 0 { // Prevent deletion for trie nodes in hash mode - if len(it.Key()) != 32 || crypto.HashData(buff, it.Value()) != common.BytesToHash(it.Key()) { + if len(it.Key()) != 32 || crypto.Keccak256Hash(it.Value()) != common.BytesToHash(it.Key()) { if err := batch.Delete(it.Key()); err != nil { return err } diff --git a/core/state/reader.go b/core/state/reader.go index 09edf6ab8d..695521a71e 100644 --- a/core/state/reader.go +++ b/core/state/reader.go @@ -204,9 +204,8 @@ func (r *flatReader) Storage(addr common.Address, key common.Hash) (common.Hash, // // trieReader is safe for concurrent read. type trieReader struct { - root common.Hash // State root which uniquely represent a state - db *triedb.Database // Database for loading trie - buff crypto.KeccakState // Buffer for keccak256 hashing + root common.Hash // State root which uniquely represent a state + db *triedb.Database // Database for loading trie // Main trie, resolved in constructor. Note either the Merkle-Patricia-tree // or Verkle-tree is not safe for concurrent read. @@ -235,7 +234,6 @@ func newTrieReader(root common.Hash, db *triedb.Database, cache *utils.PointCach return &trieReader{ root: root, db: db, - buff: crypto.NewKeccakState(), mainTrie: tr, subRoots: make(map[common.Address]common.Hash), subTries: make(map[common.Address]Trie), @@ -298,7 +296,7 @@ func (r *trieReader) Storage(addr common.Address, key common.Hash) (common.Hash, root = r.subRoots[addr] } var err error - tr, err = trie.NewStateTrie(trie.StorageTrieID(r.root, crypto.HashData(r.buff, addr.Bytes()), root), r.db) + tr, err = trie.NewStateTrie(trie.StorageTrieID(r.root, crypto.Keccak256Hash(addr.Bytes()), root), r.db) if err != nil { return common.Hash{}, err } diff --git a/core/state/state_object.go b/core/state/state_object.go index a6979bd361..73a3b5146c 100644 --- a/core/state/state_object.go +++ b/core/state/state_object.go @@ -377,7 +377,6 @@ func (s *stateObject) updateRoot() { // fulfills the storage diffs into the given accountUpdate struct. func (s *stateObject) commitStorage(op *accountUpdate) { var ( - buf = crypto.NewKeccakState() encode = func(val common.Hash) []byte { if val == (common.Hash{}) { return nil @@ -394,7 +393,7 @@ func (s *stateObject) commitStorage(op *accountUpdate) { if val == s.originStorage[key] { continue } - hash := crypto.HashData(buf, key[:]) + hash := crypto.Keccak256Hash(key[:]) if op.storages == nil { op.storages = make(map[common.Hash][]byte) } diff --git a/core/state/statedb.go b/core/state/statedb.go index 2453d67f3e..74e88881ab 100644 --- a/core/state/statedb.go +++ b/core/state/statedb.go @@ -1064,7 +1064,6 @@ func (s *StateDB) deleteStorage(addr common.Address, addrHash common.Hash, root func (s *StateDB) handleDestruction(noStorageWiping bool) (map[common.Hash]*accountDelete, []*trienode.NodeSet, error) { var ( nodes []*trienode.NodeSet - buf = crypto.NewKeccakState() deletes = make(map[common.Hash]*accountDelete) ) for addr, prevObj := range s.stateObjectsDestruct { @@ -1079,7 +1078,7 @@ func (s *StateDB) handleDestruction(noStorageWiping bool) (map[common.Hash]*acco continue } // The account was existent, it can be either case (c) or (d). - addrHash := crypto.HashData(buf, addr.Bytes()) + addrHash := crypto.Keccak256Hash(addr.Bytes()) op := &accountDelete{ address: addr, origin: types.SlimAccountRLP(*prev),