aboutsummaryrefslogtreecommitdiffstats
path: root/core
diff options
context:
space:
mode:
authorJimmy Hu <jimmy.hu@dexon.org>2018-12-20 16:54:11 +0800
committerGitHub <noreply@github.com>2018-12-20 16:54:11 +0800
commit24783a4b3d4a23256e1e16c9f35191c7de4bb7ee (patch)
tree75d78bed2b2c5cc69129dec7af2808fdcbe3645f /core
parent45609b1dbfba5d7083826e27f2c5862fcca24106 (diff)
downloaddexon-consensus-24783a4b3d4a23256e1e16c9f35191c7de4bb7ee.tar
dexon-consensus-24783a4b3d4a23256e1e16c9f35191c7de4bb7ee.tar.gz
dexon-consensus-24783a4b3d4a23256e1e16c9f35191c7de4bb7ee.tar.bz2
dexon-consensus-24783a4b3d4a23256e1e16c9f35191c7de4bb7ee.tar.lz
dexon-consensus-24783a4b3d4a23256e1e16c9f35191c7de4bb7ee.tar.xz
dexon-consensus-24783a4b3d4a23256e1e16c9f35191c7de4bb7ee.tar.zst
dexon-consensus-24783a4b3d4a23256e1e16c9f35191c7de4bb7ee.zip
core: Add VerifyDKGMPKReadySignature (#377)
* core: Add VerifyDKGMPKReadySignature * Fix typo
Diffstat (limited to 'core')
-rw-r--r--core/consensus.go2
-rw-r--r--core/crypto.go15
-rw-r--r--core/crypto_test.go14
3 files changed, 30 insertions, 1 deletions
diff --git a/core/consensus.go b/core/consensus.go
index cc4b9e2..03d2c2f 100644
--- a/core/consensus.go
+++ b/core/consensus.go
@@ -335,7 +335,7 @@ func (recv *consensusDKGReceiver) ProposeDKGMPKReady(ready *typesDKG.MPKReady) {
recv.logger.Error("Failed to sign DKG ready", "error", err)
return
}
- recv.logger.Debug("Calling Governance.AddDKGFinalize", "ready", ready)
+ recv.logger.Debug("Calling Governance.AddDKGMPKReady", "ready", ready)
recv.gov.AddDKGMPKReady(ready.Round, ready)
}
diff --git a/core/crypto.go b/core/crypto.go
index 96ea54f..d4a7f0e 100644
--- a/core/crypto.go
+++ b/core/crypto.go
@@ -252,6 +252,21 @@ func hashDKGMPKReady(ready *typesDKG.MPKReady) common.Hash {
binaryRound,
)
}
+
+// VerifyDKGMPKReadySignature verifies DKGMPKReady signature.
+func VerifyDKGMPKReadySignature(
+ ready *typesDKG.MPKReady) (bool, error) {
+ hash := hashDKGMPKReady(ready)
+ pubKey, err := crypto.SigToPub(hash, ready.Signature)
+ if err != nil {
+ return false, err
+ }
+ if ready.ProposerID != types.NewNodeID(pubKey) {
+ return false, nil
+ }
+ return true, nil
+}
+
func hashDKGFinalize(final *typesDKG.Finalize) common.Hash {
binaryRound := make([]byte, 8)
binary.LittleEndian.PutUint64(binaryRound, final.Round)
diff --git a/core/crypto_test.go b/core/crypto_test.go
index 5aefec5..17a52b7 100644
--- a/core/crypto_test.go
+++ b/core/crypto_test.go
@@ -251,6 +251,20 @@ func (s *CryptoTestSuite) TestDKGSignature() {
s.Require().NoError(err)
s.False(ok)
+ ready := &typesDKG.MPKReady{
+ ProposerID: nID,
+ Round: 5,
+ }
+ ready.Signature, err = prv.Sign(hashDKGMPKReady(ready))
+ s.Require().NoError(err)
+ ok, err = VerifyDKGMPKReadySignature(ready)
+ s.Require().NoError(err)
+ s.True(ok)
+ ready.Round++
+ ok, err = VerifyDKGMPKReadySignature(ready)
+ s.Require().NoError(err)
+ s.False(ok)
+
final := &typesDKG.Finalize{
ProposerID: nID,
Round: 5,