aboutsummaryrefslogtreecommitdiffstats
path: root/vendor/github.com/dexon-foundation/dexon-consensus/core/utils/crypto.go
diff options
context:
space:
mode:
authorWei-Ning Huang <w@dexon.org>2019-04-12 18:14:18 +0800
committerGitHub <noreply@github.com>2019-04-12 18:14:18 +0800
commit0080d104ecb56bbf658c9d3fea231ba3da669529 (patch)
tree4343e97ae2d62343f988a63653bb20d52460d28b /vendor/github.com/dexon-foundation/dexon-consensus/core/utils/crypto.go
parent976b7ed1734170925299f1c6c05a5e12a518150b (diff)
downloaddexon-0080d104ecb56bbf658c9d3fea231ba3da669529.tar
dexon-0080d104ecb56bbf658c9d3fea231ba3da669529.tar.gz
dexon-0080d104ecb56bbf658c9d3fea231ba3da669529.tar.bz2
dexon-0080d104ecb56bbf658c9d3fea231ba3da669529.tar.lz
dexon-0080d104ecb56bbf658c9d3fea231ba3da669529.tar.xz
dexon-0080d104ecb56bbf658c9d3fea231ba3da669529.tar.zst
dexon-0080d104ecb56bbf658c9d3fea231ba3da669529.zip
dex: implement bad peer detect and disconnect mechanism (#360)
Diffstat (limited to 'vendor/github.com/dexon-foundation/dexon-consensus/core/utils/crypto.go')
-rw-r--r--vendor/github.com/dexon-foundation/dexon-consensus/core/utils/crypto.go23
1 files changed, 15 insertions, 8 deletions
diff --git a/vendor/github.com/dexon-foundation/dexon-consensus/core/utils/crypto.go b/vendor/github.com/dexon-foundation/dexon-consensus/core/utils/crypto.go
index 7fd3a7776..496944dab 100644
--- a/vendor/github.com/dexon-foundation/dexon-consensus/core/utils/crypto.go
+++ b/vendor/github.com/dexon-foundation/dexon-consensus/core/utils/crypto.go
@@ -18,6 +18,7 @@
package utils
import (
+ "bytes"
"encoding/binary"
"github.com/dexon-foundation/dexon-consensus/common"
@@ -122,21 +123,27 @@ func VerifyVoteSignature(vote *types.Vote) (bool, error) {
func hashCRS(block *types.Block, crs common.Hash) common.Hash {
hashPos := HashPosition(block.Position)
+ if block.Position.Round < dkgDelayRound {
+ return crypto.Keccak256Hash(crs[:], hashPos[:], block.ProposerID.Hash[:])
+ }
return crypto.Keccak256Hash(crs[:], hashPos[:])
}
// VerifyCRSSignature verifies the CRS signature of types.Block.
-func VerifyCRSSignature(block *types.Block, crs common.Hash) (
- bool, error) {
+func VerifyCRSSignature(
+ block *types.Block, crs common.Hash, npks *typesDKG.NodePublicKeys) bool {
hash := hashCRS(block, crs)
- pubKey, err := crypto.SigToPub(hash, block.CRSSignature)
- if err != nil {
- return false, err
+ if block.Position.Round < dkgDelayRound {
+ return bytes.Compare(block.CRSSignature.Signature[:], hash[:]) == 0
}
- if block.ProposerID != types.NewNodeID(pubKey) {
- return false, nil
+ if npks == nil {
+ return false
}
- return true, nil
+ pubKey, exist := npks.PublicKeys[block.ProposerID]
+ if !exist {
+ return false
+ }
+ return pubKey.VerifySignature(hash, block.CRSSignature)
}
// HashPosition generates hash of a types.Position.