From 24783a4b3d4a23256e1e16c9f35191c7de4bb7ee Mon Sep 17 00:00:00 2001 From: Jimmy Hu Date: Thu, 20 Dec 2018 16:54:11 +0800 Subject: core: Add VerifyDKGMPKReadySignature (#377) * core: Add VerifyDKGMPKReadySignature * Fix typo --- core/consensus.go | 2 +- core/crypto.go | 15 +++++++++++++++ core/crypto_test.go | 14 ++++++++++++++ 3 files changed, 30 insertions(+), 1 deletion(-) (limited to 'core') 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, -- cgit v1.2.3