From 14e2d1c7511de11e28ea3252878834c06c85931b Mon Sep 17 00:00:00 2001 From: maskpp Date: Thu, 19 Jun 2025 07:42:04 +0800 Subject: [PATCH] delete Keccak256RLP and Keccak256RLPHash --- cmd/evm/internal/t8ntool/execution.go | 3 ++- cmd/workload/historytestgen.go | 4 +++- consensus/ethash/consensus.go | 4 +++- crypto/crypto.go | 20 ++------------------ p2p/enode/idscheme.go | 6 ++++-- 5 files changed, 14 insertions(+), 23 deletions(-) diff --git a/cmd/evm/internal/t8ntool/execution.go b/cmd/evm/internal/t8ntool/execution.go index da492b355c..dc9983bc9c 100644 --- a/cmd/evm/internal/t8ntool/execution.go +++ b/cmd/evm/internal/t8ntool/execution.go @@ -436,7 +436,8 @@ func MakePreState(db ethdb.Database, accounts types.GenesisAlloc) *state.StateDB } func rlpHash(x interface{}) (h common.Hash) { - return crypto.Keccak256RLPHash(x) + bytes, _ := rlp.EncodeToBytes(x) + return crypto.Keccak256Hash(bytes) } // calcDifficulty is based on ethash.CalcDifficulty. This method is used in case diff --git a/cmd/workload/historytestgen.go b/cmd/workload/historytestgen.go index 84b3d7c194..04a827118c 100644 --- a/cmd/workload/historytestgen.go +++ b/cmd/workload/historytestgen.go @@ -27,6 +27,7 @@ import ( "github.com/ethereum/go-ethereum/core/types" "github.com/ethereum/go-ethereum/crypto" "github.com/ethereum/go-ethereum/internal/flags" + "github.com/ethereum/go-ethereum/rlp" "github.com/urfave/cli/v2" ) @@ -130,7 +131,8 @@ func generateHistoryTests(clictx *cli.Context) error { } func calcReceiptsHash(rcpt []*types.Receipt) common.Hash { - return crypto.Keccak256RLPHash(rcpt) + bytes, _ := rlp.EncodeToBytes(rcpt) + return crypto.Keccak256Hash(bytes) } func writeJSON(fileName string, value any) { diff --git a/consensus/ethash/consensus.go b/consensus/ethash/consensus.go index fc5522c012..202d1350b4 100644 --- a/consensus/ethash/consensus.go +++ b/consensus/ethash/consensus.go @@ -19,6 +19,7 @@ package ethash import ( "errors" "fmt" + "github.com/ethereum/go-ethereum/rlp" "math/big" "time" @@ -556,7 +557,8 @@ func (ethash *Ethash) SealHash(header *types.Header) (hash common.Hash) { if header.ParentBeaconRoot != nil { panic("parent beacon root set on ethash") } - return crypto.Keccak256RLPHash(enc) + bytes, _ := rlp.EncodeToBytes(enc) + return crypto.Keccak256Hash(bytes) } // accumulateRewards credits the coinbase of the given block with the mining diff --git a/crypto/crypto.go b/crypto/crypto.go index 6af96f74cc..43a4062efc 100644 --- a/crypto/crypto.go +++ b/crypto/crypto.go @@ -94,12 +94,6 @@ func Keccak256(data ...[]byte) []byte { return b[:] } -// Keccak256RLP calculates and returns the Keccak256 hash of the input interface. -func Keccak256RLP(x interface{}) []byte { - b := Keccak256RLPHash(x) - return b[:] -} - // Keccak256Hash calculates and returns the Keccak256 hash of the input data, // converting it to an internal Hash data structure. func Keccak256Hash(data ...[]byte) (h common.Hash) { @@ -113,17 +107,6 @@ func Keccak256Hash(data ...[]byte) (h common.Hash) { return h } -// Keccak256RLPHash calculates and returns the Keccak256 hash of the input interface, -// converting it to an internal Hash data structure. -func Keccak256RLPHash(x interface{}) (h common.Hash) { - d := hasherPool.Get().(KeccakState) - d.Reset() - rlp.Encode(d, x) - d.Read(h[:]) - hasherPool.Put(d) - return h -} - // Keccak512 calculates and returns the Keccak512 hash of the input data. func Keccak512(data ...[]byte) []byte { d := sha3.NewLegacyKeccak512() @@ -135,7 +118,8 @@ func Keccak512(data ...[]byte) []byte { // CreateAddress creates an ethereum address given the bytes and the nonce func CreateAddress(b common.Address, nonce uint64) common.Address { - return common.BytesToAddress(Keccak256RLP([]interface{}{b, nonce})[12:]) + data, _ := rlp.EncodeToBytes([]interface{}{b, nonce}) + return common.BytesToAddress(Keccak256(data)[12:]) } // CreateAddress2 creates an ethereum address given the address bytes, initial diff --git a/p2p/enode/idscheme.go b/p2p/enode/idscheme.go index 8061eea968..09746a2a99 100644 --- a/p2p/enode/idscheme.go +++ b/p2p/enode/idscheme.go @@ -48,7 +48,8 @@ func SignV4(r *enr.Record, privkey *ecdsa.PrivateKey) error { cpy.Set(enr.ID("v4")) cpy.Set(Secp256k1(privkey.PublicKey)) - digestHash := crypto.Keccak256RLP(cpy.AppendElements(nil)) + bytes, _ := rlp.EncodeToBytes(cpy.AppendElements(nil)) + digestHash := crypto.Keccak256(bytes) sig, err := crypto.Sign(digestHash, privkey) if err != nil { return err @@ -68,7 +69,8 @@ func (V4ID) Verify(r *enr.Record, sig []byte) error { return errors.New("invalid public key") } - digestHash := crypto.Keccak256RLP(r.AppendElements(nil)) + bytes, _ := rlp.EncodeToBytes(r.AppendElements(nil)) + digestHash := crypto.Keccak256(bytes) if !crypto.VerifySignature(entry, digestHash, sig) { return enr.ErrInvalidSig }