diff --git a/cmd/devp2p/internal/ethtest/snap.go b/cmd/devp2p/internal/ethtest/snap.go index f4fce0931f..3d4474a77b 100644 --- a/cmd/devp2p/internal/ethtest/snap.go +++ b/cmd/devp2p/internal/ethtest/snap.go @@ -900,16 +900,12 @@ func (s *Suite) snapGetByteCodes(t *utesting.T, tc *byteCodesTest) error { // that the serving node is missing var ( bytecodes = res.Codes - hasher = crypto.NewKeccakState() - hash = make([]byte, 32) codes = make([][]byte, len(req.Hashes)) ) for i, j := 0, 0; i < len(bytecodes); i++ { // Find the next hash that we've been served, leaving misses with nils - hasher.Reset() - hasher.Write(bytecodes[i]) - hasher.Read(hash) + hash := crypto.Keccak256(bytecodes[i]) for j < len(req.Hashes) && !bytes.Equal(hash, req.Hashes[j][:]) { j++ @@ -959,16 +955,12 @@ func (s *Suite) snapGetTrieNodes(t *utesting.T, tc *trieNodesTest) error { // Cross reference the requested trienodes with the response to find gaps // that the serving node is missing - hasher := crypto.NewKeccakState() - hash := make([]byte, 32) trienodes := res.Nodes if got, want := len(trienodes), len(tc.expHashes); got != want { return fmt.Errorf("wrong trienode count, got %d, want %d", got, want) } for i, trienode := range trienodes { - hasher.Reset() - hasher.Write(trienode) - hasher.Read(hash) + hash := crypto.Keccak256(trienode[:]) if got, want := hash, tc.expHashes[i]; !bytes.Equal(got, want[:]) { t.Logf(" hash %d wrong, got %#x, want %#x\n", i, got, want) err = fmt.Errorf("hash %d wrong, got %#x, want %#x", i, got, want) diff --git a/cmd/geth/dbcmd.go b/cmd/geth/dbcmd.go index c57add0656..184a2f654b 100644 --- a/cmd/geth/dbcmd.go +++ b/cmd/geth/dbcmd.go @@ -354,8 +354,6 @@ func checkStateContent(ctx *cli.Context) error { defer db.Close() var ( it = rawdb.NewKeyLengthIterator(db.NewIterator(prefix, start), 32) - hasher = crypto.NewKeccakState() - got = make([]byte, 32) errs int count int startTime = time.Now() @@ -365,9 +363,7 @@ func checkStateContent(ctx *cli.Context) error { count++ k := it.Key() v := it.Value() - hasher.Reset() - hasher.Write(v) - hasher.Read(got) + got := crypto.Keccak256(v) if !bytes.Equal(k, got) { errs++ fmt.Printf("Error at %#x\n", k) diff --git a/cmd/geth/snapshot.go b/cmd/geth/snapshot.go index fc0658a59c..3da79aad2c 100644 --- a/cmd/geth/snapshot.go +++ b/cmd/geth/snapshot.go @@ -430,8 +430,6 @@ func traverseRawState(ctx *cli.Context) error { codes int lastReport time.Time start = time.Now() - hasher = crypto.NewKeccakState() - got = make([]byte, 32) ) accIter, err := t.NodeIterator(nil) if err != nil { @@ -455,9 +453,7 @@ func traverseRawState(ctx *cli.Context) error { log.Error("Missing trie node(account)", "hash", node) return errors.New("missing account") } - hasher.Reset() - hasher.Write(blob) - hasher.Read(got) + got := crypto.Keccak256(blob) if !bytes.Equal(got, node.Bytes()) { log.Error("Invalid trie node(account)", "hash", node.Hex(), "value", blob) return errors.New("invalid account node") @@ -496,9 +492,7 @@ func traverseRawState(ctx *cli.Context) error { log.Error("Missing trie node(storage)", "hash", node) return errors.New("missing storage") } - hasher.Reset() - hasher.Write(blob) - hasher.Read(got) + got := crypto.Keccak256(blob) if !bytes.Equal(got, node.Bytes()) { log.Error("Invalid trie node(storage)", "hash", node.Hex(), "value", blob) return errors.New("invalid storage node") diff --git a/cmd/workload/historytestgen.go b/cmd/workload/historytestgen.go index b88c8208da..121bb989d5 100644 --- a/cmd/workload/historytestgen.go +++ b/cmd/workload/historytestgen.go @@ -132,9 +132,8 @@ func generateHistoryTests(clictx *cli.Context) error { } func calcReceiptsHash(rcpt []*types.Receipt) common.Hash { - h := crypto.NewKeccakState() - rlp.Encode(h, rcpt) - return common.Hash(h.Sum(nil)) + encoded, _ := rlp.EncodeToBytes(rcpt) + return crypto.Keccak256Hash(encoded) } func writeJSON(fileName string, value any) {