mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-25 06:06:44 +00:00
delete Keccak256RLP and Keccak256RLPHash
This commit is contained in:
parent
35394489e5
commit
14e2d1c751
5 changed files with 14 additions and 23 deletions
|
|
@ -436,7 +436,8 @@ func MakePreState(db ethdb.Database, accounts types.GenesisAlloc) *state.StateDB
|
||||||
}
|
}
|
||||||
|
|
||||||
func rlpHash(x interface{}) (h common.Hash) {
|
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
|
// calcDifficulty is based on ethash.CalcDifficulty. This method is used in case
|
||||||
|
|
|
||||||
|
|
@ -27,6 +27,7 @@ import (
|
||||||
"github.com/ethereum/go-ethereum/core/types"
|
"github.com/ethereum/go-ethereum/core/types"
|
||||||
"github.com/ethereum/go-ethereum/crypto"
|
"github.com/ethereum/go-ethereum/crypto"
|
||||||
"github.com/ethereum/go-ethereum/internal/flags"
|
"github.com/ethereum/go-ethereum/internal/flags"
|
||||||
|
"github.com/ethereum/go-ethereum/rlp"
|
||||||
"github.com/urfave/cli/v2"
|
"github.com/urfave/cli/v2"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
@ -130,7 +131,8 @@ func generateHistoryTests(clictx *cli.Context) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
func calcReceiptsHash(rcpt []*types.Receipt) common.Hash {
|
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) {
|
func writeJSON(fileName string, value any) {
|
||||||
|
|
|
||||||
|
|
@ -19,6 +19,7 @@ package ethash
|
||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"github.com/ethereum/go-ethereum/rlp"
|
||||||
"math/big"
|
"math/big"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
|
@ -556,7 +557,8 @@ func (ethash *Ethash) SealHash(header *types.Header) (hash common.Hash) {
|
||||||
if header.ParentBeaconRoot != nil {
|
if header.ParentBeaconRoot != nil {
|
||||||
panic("parent beacon root set on ethash")
|
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
|
// accumulateRewards credits the coinbase of the given block with the mining
|
||||||
|
|
|
||||||
|
|
@ -94,12 +94,6 @@ func Keccak256(data ...[]byte) []byte {
|
||||||
return b[:]
|
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,
|
// Keccak256Hash calculates and returns the Keccak256 hash of the input data,
|
||||||
// converting it to an internal Hash data structure.
|
// converting it to an internal Hash data structure.
|
||||||
func Keccak256Hash(data ...[]byte) (h common.Hash) {
|
func Keccak256Hash(data ...[]byte) (h common.Hash) {
|
||||||
|
|
@ -113,17 +107,6 @@ func Keccak256Hash(data ...[]byte) (h common.Hash) {
|
||||||
return h
|
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.
|
// Keccak512 calculates and returns the Keccak512 hash of the input data.
|
||||||
func Keccak512(data ...[]byte) []byte {
|
func Keccak512(data ...[]byte) []byte {
|
||||||
d := sha3.NewLegacyKeccak512()
|
d := sha3.NewLegacyKeccak512()
|
||||||
|
|
@ -135,7 +118,8 @@ func Keccak512(data ...[]byte) []byte {
|
||||||
|
|
||||||
// CreateAddress creates an ethereum address given the bytes and the nonce
|
// CreateAddress creates an ethereum address given the bytes and the nonce
|
||||||
func CreateAddress(b common.Address, nonce uint64) common.Address {
|
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
|
// CreateAddress2 creates an ethereum address given the address bytes, initial
|
||||||
|
|
|
||||||
|
|
@ -48,7 +48,8 @@ func SignV4(r *enr.Record, privkey *ecdsa.PrivateKey) error {
|
||||||
cpy.Set(enr.ID("v4"))
|
cpy.Set(enr.ID("v4"))
|
||||||
cpy.Set(Secp256k1(privkey.PublicKey))
|
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)
|
sig, err := crypto.Sign(digestHash, privkey)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
|
@ -68,7 +69,8 @@ func (V4ID) Verify(r *enr.Record, sig []byte) error {
|
||||||
return errors.New("invalid public key")
|
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) {
|
if !crypto.VerifySignature(entry, digestHash, sig) {
|
||||||
return enr.ErrInvalidSig
|
return enr.ErrInvalidSig
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue