diff options
-rw-r--r-- | core/consensus.go | 2 | ||||
-rw-r--r-- | core/crypto.go | 15 | ||||
-rw-r--r-- | core/crypto_test.go | 14 |
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, |