From 6c2363e09e3cf38b156e02162ae635d860c634ba Mon Sep 17 00:00:00 2001 From: Rongjian Lan Date: Fri, 4 Jan 2019 10:54:12 -0800 Subject: [PATCH] Migrate sha3 to golang's sha3 --- consensus/consensus.go | 4 ++-- core/rawdb/accessors_chain_test.go | 8 ++++---- core/types/block.go | 4 ++-- core/vm/instructions.go | 4 ++-- internal/trie/hasher.go | 4 ++-- 5 files changed, 12 insertions(+), 12 deletions(-) diff --git a/consensus/consensus.go b/consensus/consensus.go index c2dcfe1e4..c1a9d0984 100644 --- a/consensus/consensus.go +++ b/consensus/consensus.go @@ -10,7 +10,6 @@ import ( "github.com/dedis/kyber" "github.com/dedis/kyber/sign/schnorr" "github.com/ethereum/go-ethereum/common" - "github.com/ethereum/go-ethereum/crypto/sha3" "github.com/ethereum/go-ethereum/params" "github.com/ethereum/go-ethereum/rlp" "github.com/harmony-one/harmony/core/state" @@ -21,6 +20,7 @@ import ( "github.com/harmony-one/harmony/log" "github.com/harmony-one/harmony/p2p" "github.com/harmony-one/harmony/p2p/host" + "golang.org/x/crypto/sha3" proto_node "github.com/harmony-one/harmony/api/proto/node" ) @@ -436,7 +436,7 @@ func (consensus *Consensus) Finalize(chain ChainReader, header *types.Header, st // SealHash returns the hash of a block prior to it being sealed. func (consensus *Consensus) SealHash(header *types.Header) (hash common.Hash) { - hasher := sha3.NewKeccak256() + hasher := sha3.NewLegacyKeccak256() rlp.Encode(hasher, []interface{}{ header.ParentHash, diff --git a/core/rawdb/accessors_chain_test.go b/core/rawdb/accessors_chain_test.go index 526842d55..f938db0e0 100644 --- a/core/rawdb/accessors_chain_test.go +++ b/core/rawdb/accessors_chain_test.go @@ -22,10 +22,10 @@ import ( "testing" "github.com/ethereum/go-ethereum/common" - "github.com/ethereum/go-ethereum/crypto/sha3" "github.com/ethereum/go-ethereum/ethdb" "github.com/ethereum/go-ethereum/rlp" "github.com/harmony-one/harmony/core/types" + "golang.org/x/crypto/sha3" ) // Tests block header storage and retrieval operations. @@ -47,7 +47,7 @@ func TestHeaderStorage(t *testing.T) { if entry := ReadHeaderRLP(db, header.Hash(), header.Number.Uint64()); entry == nil { t.Fatalf("Stored header RLP not found") } else { - hasher := sha3.NewKeccak256() + hasher := sha3.NewLegacyKeccak256() hasher.Write(entry) if hash := common.BytesToHash(hasher.Sum(nil)); hash != header.Hash() { @@ -68,7 +68,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 := sha3.NewKeccak256() + hasher := sha3.NewLegacyKeccak256() rlp.Encode(hasher, body) hash := common.BytesToHash(hasher.Sum(nil)) @@ -85,7 +85,7 @@ func TestBodyStorage(t *testing.T) { if entry := ReadBodyRLP(db, hash, 0); entry == nil { t.Fatalf("Stored body RLP not found") } else { - hasher := sha3.NewKeccak256() + hasher := sha3.NewLegacyKeccak256() hasher.Write(entry) if calc := common.BytesToHash(hasher.Sum(nil)); calc != hash { diff --git a/core/types/block.go b/core/types/block.go index 8be521322..b533761f7 100644 --- a/core/types/block.go +++ b/core/types/block.go @@ -28,8 +28,8 @@ import ( "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/common/hexutil" - "github.com/ethereum/go-ethereum/crypto/sha3" "github.com/ethereum/go-ethereum/rlp" + "golang.org/x/crypto/sha3" ) // Constants for block. @@ -121,7 +121,7 @@ func (h *Header) Size() common.StorageSize { } func rlpHash(x interface{}) (h common.Hash) { - hw := sha3.NewKeccak256() + hw := sha3.NewLegacyKeccak256() rlp.Encode(hw, x) hw.Sum(h[:0]) return h diff --git a/core/vm/instructions.go b/core/vm/instructions.go index a00107aff..3cfc9fcfb 100644 --- a/core/vm/instructions.go +++ b/core/vm/instructions.go @@ -23,9 +23,9 @@ import ( "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/common/math" - "github.com/ethereum/go-ethereum/crypto/sha3" "github.com/ethereum/go-ethereum/params" "github.com/harmony-one/harmony/core/types" + "golang.org/x/crypto/sha3" ) var ( @@ -387,7 +387,7 @@ func opSha3(pc *uint64, interpreter *EVMInterpreter, contract *Contract, memory data := memory.Get(offset.Int64(), size.Int64()) if interpreter.hasher == nil { - interpreter.hasher = sha3.NewKeccak256().(keccakState) + interpreter.hasher = sha3.NewLegacyKeccak256().(keccakState) } else { interpreter.hasher.Reset() } diff --git a/internal/trie/hasher.go b/internal/trie/hasher.go index 7b1d7793f..9d6756b6f 100644 --- a/internal/trie/hasher.go +++ b/internal/trie/hasher.go @@ -21,8 +21,8 @@ import ( "sync" "github.com/ethereum/go-ethereum/common" - "github.com/ethereum/go-ethereum/crypto/sha3" "github.com/ethereum/go-ethereum/rlp" + "golang.org/x/crypto/sha3" ) type hasher struct { @@ -57,7 +57,7 @@ var hasherPool = sync.Pool{ New: func() interface{} { return &hasher{ tmp: make(sliceBuffer, 0, 550), // cap is as large as a full fullNode. - sha: sha3.NewKeccak256().(keccakState), + sha: sha3.NewLegacyKeccak256().(keccakState), } }, }