Fix validation for PREPARE/COMMIT messages

This commit is contained in:
ChronosX88 2021-06-09 00:39:48 +03:00
parent 4e7294e046
commit ad45e0c554
Signed by: ChronosXYZ
GPG Key ID: 085A69A82C8C511A
2 changed files with 26 additions and 32 deletions

View File

@ -108,20 +108,32 @@ func NewConsensusValidator(miner *Miner) *ConsensusValidator {
//
// return true
//},
//types2.ConsensusMessageTypePrepare: func(msg types2.PrePrepareMessage) bool {
// err := VerifyTaskSignature(msg.Task)
// if err != nil {
// return false
// }
// return true
//},
//types2.ConsensusMessageTypeCommit: func(msg types2.PrePrepareMessage) bool {
// err := VerifyTaskSignature(msg.Task)
// if err != nil {
// return false
// }
// return true
//},
types2.ConsensusMessageTypePrepare: func(msg types2.ConsensusMessage) bool {
pubKey, err := msg.From.ExtractPublicKey()
if err != nil {
// TODO logging
return false
}
ok, err := pubKey.Verify(msg.Blockhash, msg.Signature)
if err != nil {
// TODO logging
return false
}
return ok
},
types2.ConsensusMessageTypeCommit: func(msg types2.ConsensusMessage) bool {
pubKey, err := msg.From.ExtractPublicKey()
if err != nil {
// TODO logging
return false
}
ok, err := pubKey.Verify(msg.Blockhash, msg.Signature)
if err != nil {
// TODO logging
return false
}
return ok
},
}
return cv

View File

@ -9,8 +9,6 @@ import (
types2 "github.com/Secured-Finance/dione/consensus/types"
"github.com/mitchellh/hashstructure/v2"
"github.com/Secured-Finance/dione/sigs"
"github.com/minio/blake2b-simd"
@ -86,22 +84,6 @@ func DrawRandomness(rbase []byte, pers crypto2.DomainSeparationTag, round uint64
return h.Sum(nil), nil
}
func VerifyTaskSignature(task types.DioneTask) error {
cHash, err := hashstructure.Hash(task, hashstructure.FormatV2, nil)
if err != nil {
return err
}
err = sigs.Verify(
&types.Signature{Type: types.SigTypeEd25519, Data: task.Signature},
[]byte(task.Miner),
[]byte(fmt.Sprintf("%v", cHash)),
)
if err != nil {
return err
}
return nil
}
func NewMessage(cmsg types2.ConsensusMessage, typ types2.ConsensusMessageType, privKey crypto.PrivKey) (*pubsub.GenericMessage, error) {
var message pubsub.GenericMessage
switch typ {