From b40624573718fa83d84c5ee2e80932ceef7e95cf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Piotr=20Miko=C5=82ajczyk?= Date: Tue, 18 Nov 2025 11:25:39 +0100 Subject: [PATCH] trie: use stateless keccak --- trie/hasher.go | 24 ++---------------------- 1 file changed, 2 insertions(+), 22 deletions(-) diff --git a/trie/hasher.go b/trie/hasher.go index a2a1f5b662..40e95c7afe 100644 --- a/trie/hasher.go +++ b/trie/hasher.go @@ -28,7 +28,6 @@ import ( // hasher is a type used for the trie Hash operation. A hasher has some // internal preallocated temp space type hasher struct { - sha crypto.KeccakState tmp []byte encbuf rlp.EncoderBuffer parallel bool // Whether to use parallel threads when hashing @@ -39,7 +38,6 @@ var hasherPool = sync.Pool{ New: func() any { return &hasher{ tmp: make([]byte, 0, 550), // cap is as large as a full fullNode. - sha: crypto.NewKeccakState(), encbuf: rlp.NewEncoderBuffer(nil), } }, @@ -74,7 +72,7 @@ func (h *hasher) hash(n node, force bool) []byte { copy(buf, enc) return buf } - hash := h.hashData(enc) + hash := crypto.Keccak256(enc) n.flags.hash = hash return hash @@ -89,7 +87,7 @@ func (h *hasher) hash(n node, force bool) []byte { copy(buf, enc) return buf } - hash := h.hashData(enc) + hash := crypto.Keccak256(enc) n.flags.hash = hash return hash @@ -186,24 +184,6 @@ func (h *hasher) encodedBytes() []byte { return h.tmp } -// hashData hashes the provided data. It is safe to modify the returned slice after -// the function returns. -func (h *hasher) hashData(data []byte) []byte { - n := make([]byte, 32) - h.sha.Reset() - h.sha.Write(data) - h.sha.Read(n) - return n -} - -// hashDataTo hashes the provided data to the given destination buffer. The caller -// must ensure that the dst buffer is of appropriate size. -func (h *hasher) hashDataTo(dst, data []byte) { - h.sha.Reset() - h.sha.Write(data) - h.sha.Read(dst) -} - // proofHash is used to construct trie proofs, returning the rlp-encoded node blobs. // Note, only resolved node (shortNode or fullNode) is expected for proofing. //