diff --git a/validator/types/BUILD.bazel b/validator/types/BUILD.bazel index a0d6a78ed3..8aa1728314 100644 --- a/validator/types/BUILD.bazel +++ b/validator/types/BUILD.bazel @@ -15,12 +15,12 @@ go_library( "//validator/params:go_default_library", "@com_github_ethereum_go_ethereum//common:go_default_library", "@com_github_ethereum_go_ethereum//core/types:go_default_library", - "@com_github_ethereum_go_ethereum//crypto/sha3:go_default_library", "@com_github_ethereum_go_ethereum//ethdb:go_default_library", "@com_github_ethereum_go_ethereum//rlp:go_default_library", "@com_github_sirupsen_logrus//:go_default_library", "@com_github_syndtr_goleveldb//leveldb/errors:go_default_library", "@com_github_urfave_cli//:go_default_library", + "@org_golang_x_crypto//blake2b:go_default_library", ], ) @@ -36,8 +36,8 @@ go_test( "//shared/shardutil:go_default_library", "@com_github_ethereum_go_ethereum//common:go_default_library", "@com_github_ethereum_go_ethereum//core/types:go_default_library", - "@com_github_ethereum_go_ethereum//crypto/sha3:go_default_library", "@com_github_ethereum_go_ethereum//ethdb:go_default_library", "@com_github_ethereum_go_ethereum//rlp:go_default_library", + "@org_golang_x_crypto//blake2b:go_default_library", ], ) diff --git a/validator/types/collation.go b/validator/types/collation.go index 8da02ce6df..00fedb7c1a 100644 --- a/validator/types/collation.go +++ b/validator/types/collation.go @@ -7,10 +7,10 @@ import ( "github.com/ethereum/go-ethereum/common" gethTypes "github.com/ethereum/go-ethereum/core/types" - "github.com/ethereum/go-ethereum/crypto/sha3" "github.com/ethereum/go-ethereum/rlp" "github.com/prysmaticlabs/prysm/shared/shardutil" "github.com/prysmaticlabs/prysm/validator/params" + "golang.org/x/crypto/blake2b" ) // Collation defines a base struct that serves as a primitive equivalent of a "block" @@ -65,15 +65,14 @@ func NewCollationHeader(shardID *big.Int, chunkRoot *common.Hash, period *big.In return &CollationHeader{data: data} } -// Hash takes the keccak256 of the collation header's data contents. +// Hash takes the blake2b of the collation header's data contents. func (h *CollationHeader) Hash() (hash common.Hash) { - hw := sha3.NewKeccak256() - - if err := rlp.Encode(hw, h.data); err != nil { + encoded, err := rlp.EncodeToBytes(h.data) + if err != nil { log.Errorf("Failed to RLP encode data: %v", err) } - - hw.Sum(hash[:0]) + blakeHash := blake2b.Sum512(encoded) + copy(hash[:], blakeHash[:32]) return hash } diff --git a/validator/types/shard_test.go b/validator/types/shard_test.go index cddf007fed..285087eb77 100644 --- a/validator/types/shard_test.go +++ b/validator/types/shard_test.go @@ -8,10 +8,10 @@ import ( "github.com/ethereum/go-ethereum/common" gethTypes "github.com/ethereum/go-ethereum/core/types" - "github.com/ethereum/go-ethereum/crypto/sha3" "github.com/ethereum/go-ethereum/ethdb" "github.com/ethereum/go-ethereum/rlp" sharedDB "github.com/prysmaticlabs/prysm/shared/database" + "golang.org/x/crypto/blake2b" ) type mockShardDB struct { @@ -43,11 +43,15 @@ func (m *mockShardDB) NewBatch() ethdb.Batch { // Hash returns the hash of a collation's entire contents. Useful for comparison tests. func (c *Collation) Hash() (hash common.Hash) { - hw := sha3.NewKeccak256() - rlp.Encode(hw, c) - hw.Sum(hash[:0]) + encoded, err := rlp.EncodeToBytes(c) + if err != nil { + log.Errorf("Failed to RLP encode data: %v", err) + } + blakeHash := blake2b.Sum512(encoded) + copy(hash[:], blakeHash[:32]) return hash } + func TestShard_ValidateShardID(t *testing.T) { emptyHash := common.BytesToHash([]byte{}) emptyAddr := common.BytesToAddress([]byte{})