aboutsummaryrefslogtreecommitdiffstats
path: root/core/utils.go
diff options
context:
space:
mode:
Diffstat (limited to 'core/utils.go')
-rw-r--r--core/utils.go21
1 files changed, 21 insertions, 0 deletions
diff --git a/core/utils.go b/core/utils.go
index ac95678..38e8746 100644
--- a/core/utils.go
+++ b/core/utils.go
@@ -131,6 +131,27 @@ func HashConfigurationBlock(
)
}
+// VerifyBlock verifies the signature of types.Block.
+func VerifyBlock(b *types.Block) (err error) {
+ hash, err := hashBlock(b)
+ if err != nil {
+ return
+ }
+ if hash != b.Hash {
+ err = ErrIncorrectHash
+ return
+ }
+ pubKey, err := crypto.SigToPub(b.Hash, b.Signature)
+ if err != nil {
+ return
+ }
+ if !b.ProposerID.Equal(types.NewNodeID(pubKey)) {
+ err = ErrIncorrectSignature
+ return
+ }
+ return
+}
+
// DiffUint64 calculates difference between two uint64.
func DiffUint64(a, b uint64) uint64 {
if a > b {