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 // return true
//}, //},
//types2.ConsensusMessageTypePrepare: func(msg types2.PrePrepareMessage) bool { types2.ConsensusMessageTypePrepare: func(msg types2.ConsensusMessage) bool {
// err := VerifyTaskSignature(msg.Task) pubKey, err := msg.From.ExtractPublicKey()
// if err != nil { if err != nil {
// return false // TODO logging
// } return false
// return true }
//}, ok, err := pubKey.Verify(msg.Blockhash, msg.Signature)
//types2.ConsensusMessageTypeCommit: func(msg types2.PrePrepareMessage) bool { if err != nil {
// err := VerifyTaskSignature(msg.Task) // TODO logging
// if err != nil { return false
// return false }
// } return ok
// return true },
//}, 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 return cv

View File

@ -9,8 +9,6 @@ import (
types2 "github.com/Secured-Finance/dione/consensus/types" types2 "github.com/Secured-Finance/dione/consensus/types"
"github.com/mitchellh/hashstructure/v2"
"github.com/Secured-Finance/dione/sigs" "github.com/Secured-Finance/dione/sigs"
"github.com/minio/blake2b-simd" "github.com/minio/blake2b-simd"
@ -86,22 +84,6 @@ func DrawRandomness(rbase []byte, pers crypto2.DomainSeparationTag, round uint64
return h.Sum(nil), nil 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) { func NewMessage(cmsg types2.ConsensusMessage, typ types2.ConsensusMessageType, privKey crypto.PrivKey) (*pubsub.GenericMessage, error) {
var message pubsub.GenericMessage var message pubsub.GenericMessage
switch typ { switch typ {