aboutsummaryrefslogtreecommitdiffstats
path: root/core/crypto.go
diff options
context:
space:
mode:
authorJimmy Hu <jimmy.hu@dexon.org>2018-08-30 10:45:06 +0800
committerGitHub <noreply@github.com>2018-08-30 10:45:06 +0800
commit2681e011bd48ec107dedae9c7dcbc0810673298c (patch)
tree11dbe2b7ff285d3fa57d983e1103ccb61bfe122c /core/crypto.go
parentca3b30a62ff85090c1a721602e8b202e6ae9a2bd (diff)
downloadtangerine-consensus-2681e011bd48ec107dedae9c7dcbc0810673298c.tar
tangerine-consensus-2681e011bd48ec107dedae9c7dcbc0810673298c.tar.gz
tangerine-consensus-2681e011bd48ec107dedae9c7dcbc0810673298c.tar.bz2
tangerine-consensus-2681e011bd48ec107dedae9c7dcbc0810673298c.tar.lz
tangerine-consensus-2681e011bd48ec107dedae9c7dcbc0810673298c.tar.xz
tangerine-consensus-2681e011bd48ec107dedae9c7dcbc0810673298c.tar.zst
tangerine-consensus-2681e011bd48ec107dedae9c7dcbc0810673298c.zip
core: Leader Selector. (#80)
Diffstat (limited to 'core/crypto.go')
-rw-r--r--core/crypto.go18
1 files changed, 18 insertions, 0 deletions
diff --git a/core/crypto.go b/core/crypto.go
index 17426f7..57aae92 100644
--- a/core/crypto.go
+++ b/core/crypto.go
@@ -126,6 +126,24 @@ func verifyVoteSignature(vote *types.Vote, sigToPub SigToPubFn) (bool, error) {
return true, nil
}
+func hashCRS(block *types.Block, crs common.Hash) common.Hash {
+ hashPos := hashPosition(block.ShardID, block.ChainID, block.Height)
+ return crypto.Keccak256Hash(crs[:], hashPos[:])
+}
+
+func verifyCRSSignature(block *types.Block, crs common.Hash, sigToPub SigToPubFn) (
+ bool, error) {
+ hash := hashCRS(block, crs)
+ pubKey, err := sigToPub(hash, block.CRSSignature)
+ if err != nil {
+ return false, err
+ }
+ if block.ProposerID != types.NewValidatorID(pubKey) {
+ return false, nil
+ }
+ return true, nil
+}
+
func hashPosition(shardID, chainID, height uint64) common.Hash {
binaryShardID := make([]byte, 8)
binary.LittleEndian.PutUint64(binaryShardID, shardID)