From d493f6b8df14a15a87c0d55b4a18620b8ab4a8f0 Mon Sep 17 00:00:00 2001 From: CPerezz Date: Mon, 16 Mar 2026 23:57:23 +0100 Subject: [PATCH] core/state: avoid Bytes() allocation in flatReader hash computations Replace addr.Bytes() and key.Bytes() with addr[:] and key[:] in flatReader's Account and Storage methods. The former allocates a copy while the latter creates a zero-allocation slice header over the existing backing array. --- core/state/reader.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/core/state/reader.go b/core/state/reader.go index 49375c467c..fe0ec71f2d 100644 --- a/core/state/reader.go +++ b/core/state/reader.go @@ -98,7 +98,7 @@ func newFlatReader(reader database.StateReader) *flatReader { // // The returned account might be nil if it's not existent. func (r *flatReader) Account(addr common.Address) (*types.StateAccount, error) { - account, err := r.reader.Account(crypto.Keccak256Hash(addr.Bytes())) + account, err := r.reader.Account(crypto.Keccak256Hash(addr[:])) if err != nil { return nil, err } @@ -128,8 +128,8 @@ func (r *flatReader) Account(addr common.Address) (*types.StateAccount, error) { // // The returned storage slot might be empty if it's not existent. func (r *flatReader) Storage(addr common.Address, key common.Hash) (common.Hash, error) { - addrHash := crypto.Keccak256Hash(addr.Bytes()) - slotHash := crypto.Keccak256Hash(key.Bytes()) + addrHash := crypto.Keccak256Hash(addr[:]) + slotHash := crypto.Keccak256Hash(key[:]) ret, err := r.reader.Storage(addrHash, slotHash) if err != nil { return common.Hash{}, err