mirror of
https://github.com/OffchainLabs/prysm.git
synced 2026-01-09 15:37:56 -05:00
Make blake2b hash util in shared/ (#649)
This commit is contained in:
committed by
Raul Jordan
parent
dc8d40d10d
commit
6d46dda33c
@@ -10,9 +10,9 @@ go_library(
|
||||
"//proto/beacon/rpc/v1:go_default_library",
|
||||
"//shared/bitutil:go_default_library",
|
||||
"//shared/event:go_default_library",
|
||||
"//shared/hashutil:go_default_library",
|
||||
"@com_github_gogo_protobuf//proto:go_default_library",
|
||||
"@com_github_sirupsen_logrus//:go_default_library",
|
||||
"@org_golang_x_crypto//blake2b:go_default_library",
|
||||
],
|
||||
)
|
||||
|
||||
|
||||
@@ -10,8 +10,8 @@ import (
|
||||
pb "github.com/prysmaticlabs/prysm/proto/beacon/rpc/v1"
|
||||
"github.com/prysmaticlabs/prysm/shared/bitutil"
|
||||
"github.com/prysmaticlabs/prysm/shared/event"
|
||||
"github.com/prysmaticlabs/prysm/shared/hashutil"
|
||||
"github.com/sirupsen/logrus"
|
||||
"golang.org/x/crypto/blake2b"
|
||||
)
|
||||
|
||||
var log = logrus.WithField("prefix", "attester")
|
||||
@@ -91,7 +91,7 @@ func (a *Attester) run(attester pb.AttesterServiceClient, validator pb.Validator
|
||||
log.Errorf("could not marshal latest beacon block: %v", err)
|
||||
continue
|
||||
}
|
||||
latestBlockHash := blake2b.Sum512(data)
|
||||
latestBlockHash := hashutil.Hash(data)
|
||||
|
||||
pubKeyReq := &pb.PublicKey{
|
||||
PublicKey: a.beaconService.PublicKey(),
|
||||
|
||||
@@ -9,10 +9,10 @@ go_library(
|
||||
"//proto/beacon/p2p/v1:go_default_library",
|
||||
"//proto/beacon/rpc/v1:go_default_library",
|
||||
"//shared/event:go_default_library",
|
||||
"//shared/hashutil:go_default_library",
|
||||
"@com_github_golang_protobuf//proto:go_default_library",
|
||||
"@com_github_golang_protobuf//ptypes:go_default_library_gen",
|
||||
"@com_github_sirupsen_logrus//:go_default_library",
|
||||
"@org_golang_x_crypto//blake2b:go_default_library",
|
||||
],
|
||||
)
|
||||
|
||||
|
||||
@@ -12,8 +12,8 @@ import (
|
||||
pbp2p "github.com/prysmaticlabs/prysm/proto/beacon/p2p/v1"
|
||||
pb "github.com/prysmaticlabs/prysm/proto/beacon/rpc/v1"
|
||||
"github.com/prysmaticlabs/prysm/shared/event"
|
||||
"github.com/prysmaticlabs/prysm/shared/hashutil"
|
||||
"github.com/sirupsen/logrus"
|
||||
blake2b "golang.org/x/crypto/blake2b"
|
||||
)
|
||||
|
||||
var log = logrus.WithField("prefix", "proposer")
|
||||
@@ -162,7 +162,7 @@ func (p *Proposer) run(done <-chan struct{}, client pb.ProposerServiceClient) {
|
||||
log.Errorf("Could not marshal latest beacon block: %v", err)
|
||||
continue
|
||||
}
|
||||
latestBlockHash := blake2b.Sum512(data)
|
||||
latestBlockHash := hashutil.Hash(data)
|
||||
|
||||
// To prevent any unaccounted attestations from being added.
|
||||
p.lock.Lock()
|
||||
|
||||
@@ -11,6 +11,7 @@ go_library(
|
||||
importpath = "github.com/prysmaticlabs/prysm/validator/types",
|
||||
visibility = ["//validator:__subpackages__"],
|
||||
deps = [
|
||||
"//shared/hashutil:go_default_library",
|
||||
"//shared/shardutil:go_default_library",
|
||||
"//validator/params:go_default_library",
|
||||
"@com_github_ethereum_go_ethereum//common:go_default_library",
|
||||
@@ -20,7 +21,6 @@ go_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",
|
||||
],
|
||||
)
|
||||
|
||||
@@ -33,11 +33,11 @@ go_test(
|
||||
embed = [":go_default_library"],
|
||||
deps = [
|
||||
"//shared/database:go_default_library",
|
||||
"//shared/hashutil:go_default_library",
|
||||
"//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//ethdb:go_default_library",
|
||||
"@com_github_ethereum_go_ethereum//rlp:go_default_library",
|
||||
"@org_golang_x_crypto//blake2b:go_default_library",
|
||||
],
|
||||
)
|
||||
|
||||
@@ -8,9 +8,9 @@ import (
|
||||
"github.com/ethereum/go-ethereum/common"
|
||||
gethTypes "github.com/ethereum/go-ethereum/core/types"
|
||||
"github.com/ethereum/go-ethereum/rlp"
|
||||
"github.com/prysmaticlabs/prysm/shared/hashutil"
|
||||
"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"
|
||||
@@ -71,9 +71,7 @@ func (h *CollationHeader) Hash() (hash common.Hash) {
|
||||
if err != nil {
|
||||
log.Errorf("Failed to RLP encode data: %v", err)
|
||||
}
|
||||
blakeHash := blake2b.Sum512(encoded)
|
||||
copy(hash[:], blakeHash[:32])
|
||||
return hash
|
||||
return hashutil.Hash(encoded)
|
||||
}
|
||||
|
||||
// AddSig adds the signature of proposer after collationHeader gets signed.
|
||||
|
||||
@@ -11,7 +11,7 @@ import (
|
||||
"github.com/ethereum/go-ethereum/ethdb"
|
||||
"github.com/ethereum/go-ethereum/rlp"
|
||||
sharedDB "github.com/prysmaticlabs/prysm/shared/database"
|
||||
"golang.org/x/crypto/blake2b"
|
||||
"github.com/prysmaticlabs/prysm/shared/hashutil"
|
||||
)
|
||||
|
||||
type mockShardDB struct {
|
||||
@@ -42,14 +42,12 @@ 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) {
|
||||
func (c *Collation) Hash() common.Hash {
|
||||
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
|
||||
return hashutil.Hash(encoded)
|
||||
}
|
||||
|
||||
func TestShard_ValidateShardID(t *testing.T) {
|
||||
|
||||
Reference in New Issue
Block a user