diff options
Diffstat (limited to 'core/crypto.go')
-rw-r--r-- | core/crypto.go | 18 |
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) |