Updates All Usages of keccak256 to blake2b (#642)

This commit is contained in:
Ivan Martinez
2018-10-10 16:36:28 -04:00
committed by terence tsao
parent 724ae3c999
commit 7aada81a79
3 changed files with 16 additions and 13 deletions

View File

@@ -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",
],
)

View File

@@ -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
}

View File

@@ -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{})