diff options
author | Jimmy Hu <jimmy.hu@dexon.org> | 2019-04-15 11:44:04 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-04-15 11:44:04 +0800 |
commit | 79be89a6b0b1d24b889e7c9fe0244026af4d49d0 (patch) | |
tree | bacd2dd8a224d2cffbe9965439707df7fa2888de /core/utils/crypto.go | |
parent | 7abe09214fbf04f9f1f7f4f6ec57cd1f924953d6 (diff) | |
download | dexon-consensus-79be89a6b0b1d24b889e7c9fe0244026af4d49d0.tar dexon-consensus-79be89a6b0b1d24b889e7c9fe0244026af4d49d0.tar.gz dexon-consensus-79be89a6b0b1d24b889e7c9fe0244026af4d49d0.tar.bz2 dexon-consensus-79be89a6b0b1d24b889e7c9fe0244026af4d49d0.tar.lz dexon-consensus-79be89a6b0b1d24b889e7c9fe0244026af4d49d0.tar.xz dexon-consensus-79be89a6b0b1d24b889e7c9fe0244026af4d49d0.tar.zst dexon-consensus-79be89a6b0b1d24b889e7c9fe0244026af4d49d0.zip |
core: Add DKGSuccess (#569)
* core: Add DKGSuccess
* core: reset if not enough of dkg success
Diffstat (limited to 'core/utils/crypto.go')
-rw-r--r-- | core/utils/crypto.go | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/core/utils/crypto.go b/core/utils/crypto.go index 496944d..42ee612 100644 --- a/core/utils/crypto.go +++ b/core/utils/crypto.go @@ -325,6 +325,19 @@ func hashDKGFinalize(final *typesDKG.Finalize) common.Hash { ) } +func hashDKGSuccess(success *typesDKG.Success) common.Hash { + binaryRound := make([]byte, 8) + binary.LittleEndian.PutUint64(binaryRound, success.Round) + binaryReset := make([]byte, 8) + binary.LittleEndian.PutUint64(binaryReset, success.Reset) + + return crypto.Keccak256Hash( + success.ProposerID.Hash[:], + binaryRound, + binaryReset, + ) +} + // VerifyDKGFinalizeSignature verifies DKGFinalize signature. func VerifyDKGFinalizeSignature( final *typesDKG.Finalize) (bool, error) { @@ -339,6 +352,20 @@ func VerifyDKGFinalizeSignature( return true, nil } +// VerifyDKGSuccessSignature verifies DKGSuccess signature. +func VerifyDKGSuccessSignature( + success *typesDKG.Success) (bool, error) { + hash := hashDKGSuccess(success) + pubKey, err := crypto.SigToPub(hash, success.Signature) + if err != nil { + return false, err + } + if success.ProposerID != types.NewNodeID(pubKey) { + return false, nil + } + return true, nil +} + // Rehash hashes the hash again and again and again... func Rehash(hash common.Hash, count uint) common.Hash { result := hash |