From cb08c7e2bbf2985d166048fa02f2cf89a7c47379 Mon Sep 17 00:00:00 2001 From: Sahil-4555 Date: Tue, 24 Feb 2026 20:42:59 +0530 Subject: [PATCH] @lightclient feedbacks --- accounts/accounts.go | 2 +- cmd/evm/internal/t8ntool/execution.go | 2 +- common/types.go | 2 +- consensus/ethash/consensus.go | 2 +- core/rawdb/accessors_chain_test.go | 2 +- core/rlp_test.go | 2 +- core/state_processor_test.go | 2 +- crypto/keccak.go | 2 +- crypto/keccak/keccak.go | 2 +- eth/protocols/snap/sync_test.go | 4 ++-- internal/blocktest/test_hash.go | 2 +- p2p/dnsdisc/tree.go | 4 ++-- p2p/enode/idscheme.go | 4 ++-- p2p/rlpx/rlpx.go | 4 ++-- tests/state_test_util.go | 2 +- trie/trie_test.go | 8 ++++---- 16 files changed, 23 insertions(+), 23 deletions(-) diff --git a/accounts/accounts.go b/accounts/accounts.go index 375470b7ae..6249beed0d 100644 --- a/accounts/accounts.go +++ b/accounts/accounts.go @@ -196,7 +196,7 @@ func TextHash(data []byte) []byte { // This gives context to the signed message and prevents signing of transactions. func TextAndHash(data []byte) ([]byte, string) { msg := fmt.Sprintf("\x19Ethereum Signed Message:\n%d%s", len(data), data) - hasher := keccak.NewFastKeccak() + hasher := keccak.NewLegacyKeccak256() hasher.Write([]byte(msg)) return hasher.Sum(nil), msg } diff --git a/cmd/evm/internal/t8ntool/execution.go b/cmd/evm/internal/t8ntool/execution.go index 58c06ffa51..532d6e6b94 100644 --- a/cmd/evm/internal/t8ntool/execution.go +++ b/cmd/evm/internal/t8ntool/execution.go @@ -418,7 +418,7 @@ func MakePreState(db ethdb.Database, accounts types.GenesisAlloc, isBintrie bool } func rlpHash(x any) (h common.Hash) { - hw := keccak.NewFastKeccak() + hw := keccak.NewLegacyKeccak256() rlp.Encode(hw, x) hw.Sum(h[:0]) return h diff --git a/common/types.go b/common/types.go index 6200a82ab2..308b8ed879 100644 --- a/common/types.go +++ b/common/types.go @@ -271,7 +271,7 @@ func (a *Address) checksumHex() []byte { buf := a.hex() // compute checksum - sha := keccak.NewFastKeccak() + sha := keccak.NewLegacyKeccak256() sha.Write(buf[2:]) hash := sha.Sum(nil) for i := 2; i < len(buf); i++ { diff --git a/consensus/ethash/consensus.go b/consensus/ethash/consensus.go index 737d2079f3..f90001fc1a 100644 --- a/consensus/ethash/consensus.go +++ b/consensus/ethash/consensus.go @@ -527,7 +527,7 @@ func (ethash *Ethash) FinalizeAndAssemble(chain consensus.ChainHeaderReader, hea // SealHash returns the hash of a block prior to it being sealed. func (ethash *Ethash) SealHash(header *types.Header) (hash common.Hash) { - hasher := keccak.NewFastKeccak() + hasher := keccak.NewLegacyKeccak256() enc := []interface{}{ header.ParentHash, diff --git a/core/rawdb/accessors_chain_test.go b/core/rawdb/accessors_chain_test.go index 751b7e353a..280fc21e8f 100644 --- a/core/rawdb/accessors_chain_test.go +++ b/core/rawdb/accessors_chain_test.go @@ -69,7 +69,7 @@ func TestBodyStorage(t *testing.T) { // Create a test body to move around the database and make sure it's really new body := &types.Body{Uncles: []*types.Header{{Extra: []byte("test header")}}} - hasher := keccak.NewFastKeccak() + hasher := keccak.NewLegacyKeccak256() rlp.Encode(hasher, body) hash := common.BytesToHash(hasher.Sum(nil)) diff --git a/core/rlp_test.go b/core/rlp_test.go index 5cf774044a..f3655bf533 100644 --- a/core/rlp_test.go +++ b/core/rlp_test.go @@ -147,7 +147,7 @@ func BenchmarkHashing(b *testing.B) { blockRlp, _ = rlp.EncodeToBytes(block) } var got common.Hash - var hasher = keccak.NewFastKeccak() + var hasher = keccak.NewLegacyKeccak256() b.Run("iteratorhashing", func(b *testing.B) { for b.Loop() { var hash common.Hash diff --git a/core/state_processor_test.go b/core/state_processor_test.go index bcf2ece73d..3bf372800b 100644 --- a/core/state_processor_test.go +++ b/core/state_processor_test.go @@ -398,7 +398,7 @@ func GenerateBadBlock(parent *types.Block, engine consensus.Engine, txs types.Tr var receipts []*types.Receipt // The post-state result doesn't need to be correct (this is a bad block), but we do need something there // Preferably something unique. So let's use a combo of blocknum + txhash - hasher := keccak.NewFastKeccak() + hasher := keccak.NewLegacyKeccak256() hasher.Write(header.Number.Bytes()) var cumulativeGas uint64 var nBlobs int diff --git a/crypto/keccak.go b/crypto/keccak.go index 97aefa4ede..22298d334a 100644 --- a/crypto/keccak.go +++ b/crypto/keccak.go @@ -36,7 +36,7 @@ func ReturnToPool(h keccak.KeccakState) { hasherPool.Put(h) } var hasherPool = sync.Pool{ New: func() any { - return keccak.NewFastKeccak() + return keccak.NewLegacyKeccak256() }, } diff --git a/crypto/keccak/keccak.go b/crypto/keccak/keccak.go index 4372790d07..97cd077312 100644 --- a/crypto/keccak/keccak.go +++ b/crypto/keccak/keccak.go @@ -15,6 +15,6 @@ const rate = 136 // sponge rate for Keccak-256: (1600 - 2*256) / 8 var _ KeccakState = (*Hasher)(nil) -func NewFastKeccak() *Hasher { +func NewLegacyKeccak256() *Hasher { return &Hasher{} } diff --git a/eth/protocols/snap/sync_test.go b/eth/protocols/snap/sync_test.go index 4fdc681b00..b11ad4e78a 100644 --- a/eth/protocols/snap/sync_test.go +++ b/eth/protocols/snap/sync_test.go @@ -55,7 +55,7 @@ func TestHashing(t *testing.T) { } var want, got string var old = func() { - hasher := keccak.NewFastKeccak() + hasher := keccak.NewLegacyKeccak256() for i := 0; i < len(bytecodes); i++ { hasher.Reset() hasher.Write(bytecodes[i]) @@ -88,7 +88,7 @@ func BenchmarkHashing(b *testing.B) { bytecodes[i] = buf } var old = func() { - hasher := keccak.NewFastKeccak() + hasher := keccak.NewLegacyKeccak256() for i := 0; i < len(bytecodes); i++ { hasher.Reset() hasher.Write(bytecodes[i]) diff --git a/internal/blocktest/test_hash.go b/internal/blocktest/test_hash.go index e3f04f35fe..5e5b1202de 100644 --- a/internal/blocktest/test_hash.go +++ b/internal/blocktest/test_hash.go @@ -39,7 +39,7 @@ type testHasher struct { // NewHasher returns a new testHasher instance. func NewHasher() *testHasher { - return &testHasher{hasher: keccak.NewFastKeccak()} + return &testHasher{hasher: keccak.NewLegacyKeccak256()} } // Reset resets the hash state. diff --git a/p2p/dnsdisc/tree.go b/p2p/dnsdisc/tree.go index 70e32b841d..a629d6291f 100644 --- a/p2p/dnsdisc/tree.go +++ b/p2p/dnsdisc/tree.go @@ -262,7 +262,7 @@ const ( ) func subdomain(e entry) string { - h := keccak.NewFastKeccak() + h := keccak.NewLegacyKeccak256() io.WriteString(h, e.String()) return b32format.EncodeToString(h.Sum(nil)[:16]) } @@ -272,7 +272,7 @@ func (e *rootEntry) String() string { } func (e *rootEntry) sigHash() []byte { - h := keccak.NewFastKeccak() + h := keccak.NewLegacyKeccak256() fmt.Fprintf(h, rootPrefix+" e=%s l=%s seq=%d", e.eroot, e.lroot, e.seq) return h.Sum(nil) } diff --git a/p2p/enode/idscheme.go b/p2p/enode/idscheme.go index 5e33f7d1ac..313815c465 100644 --- a/p2p/enode/idscheme.go +++ b/p2p/enode/idscheme.go @@ -49,7 +49,7 @@ func SignV4(r *enr.Record, privkey *ecdsa.PrivateKey) error { cpy.Set(enr.ID("v4")) cpy.Set(Secp256k1(privkey.PublicKey)) - h := keccak.NewFastKeccak() + h := keccak.NewLegacyKeccak256() rlp.Encode(h, cpy.AppendElements(nil)) sig, err := crypto.Sign(h.Sum(nil), privkey) if err != nil { @@ -70,7 +70,7 @@ func (V4ID) Verify(r *enr.Record, sig []byte) error { return errors.New("invalid public key") } - h := keccak.NewFastKeccak() + h := keccak.NewLegacyKeccak256() rlp.Encode(h, r.AppendElements(nil)) if !crypto.VerifySignature(entry, h.Sum(nil), sig) { return enr.ErrInvalidSig diff --git a/p2p/rlpx/rlpx.go b/p2p/rlpx/rlpx.go index 8da40cdcbe..40a5c38fcb 100644 --- a/p2p/rlpx/rlpx.go +++ b/p2p/rlpx/rlpx.go @@ -486,10 +486,10 @@ func (h *handshakeState) secrets(auth, authResp []byte) (Secrets, error) { } // setup sha3 instances for the MACs - mac1 := keccak.NewFastKeccak() + mac1 := keccak.NewLegacyKeccak256() mac1.Write(xor(s.MAC, h.respNonce)) mac1.Write(auth) - mac2 := keccak.NewFastKeccak() + mac2 := keccak.NewLegacyKeccak256() mac2.Write(xor(s.MAC, h.initNonce)) mac2.Write(authResp) if h.initiator { diff --git a/tests/state_test_util.go b/tests/state_test_util.go index ea89a23f29..7525081f84 100644 --- a/tests/state_test_util.go +++ b/tests/state_test_util.go @@ -496,7 +496,7 @@ func (tx *stTransaction) toMessage(ps stPostState, baseFee *big.Int) (*core.Mess } func rlpHash(x interface{}) (h common.Hash) { - hw := keccak.NewFastKeccak() + hw := keccak.NewLegacyKeccak256() rlp.Encode(hw, x) hw.Sum(h[:0]) return h diff --git a/trie/trie_test.go b/trie/trie_test.go index a18b351d13..3423cde59c 100644 --- a/trie/trie_test.go +++ b/trie/trie_test.go @@ -968,7 +968,7 @@ func TestCommitSequenceStackTrie(t *testing.T) { prng := rand.New(rand.NewSource(int64(count))) // This spongeDb is used to check the sequence of disk-db-writes s := &spongeDb{ - sponge: keccak.NewFastKeccak(), + sponge: keccak.NewLegacyKeccak256(), id: "a", values: make(map[string]string), } @@ -977,7 +977,7 @@ func TestCommitSequenceStackTrie(t *testing.T) { // Another sponge is used for the stacktrie commits stackTrieSponge := &spongeDb{ - sponge: keccak.NewFastKeccak(), + sponge: keccak.NewLegacyKeccak256(), id: "b", values: make(map[string]string), } @@ -1040,7 +1040,7 @@ func TestCommitSequenceStackTrie(t *testing.T) { // not fit into 32 bytes, rlp-encoded. However, it's still the correct thing to do. func TestCommitSequenceSmallRoot(t *testing.T) { s := &spongeDb{ - sponge: keccak.NewFastKeccak(), + sponge: keccak.NewLegacyKeccak256(), id: "a", values: make(map[string]string), } @@ -1049,7 +1049,7 @@ func TestCommitSequenceSmallRoot(t *testing.T) { // Another sponge is used for the stacktrie commits stackTrieSponge := &spongeDb{ - sponge: keccak.NewFastKeccak(), + sponge: keccak.NewLegacyKeccak256(), id: "b", values: make(map[string]string), }