OSDN Git Service

validate vote pubkey (#128)
authormuscle_boy <shenao.78@163.com>
Tue, 4 Jun 2019 07:40:43 +0000 (15:40 +0800)
committerPaladz <yzhu101@uottawa.ca>
Tue, 4 Jun 2019 07:40:43 +0000 (15:40 +0800)
protocol/validation/tx.go

index 14d1b87..d7cc42b 100644 (file)
@@ -38,6 +38,7 @@ var (
        ErrUnbalanced                = errors.New("unbalanced asset amount between input and output")
        ErrOverGasCredit             = errors.New("all gas credit has been spend")
        ErrGasCalculate              = errors.New("gas usage calculate got a math error")
        ErrUnbalanced                = errors.New("unbalanced asset amount between input and output")
        ErrOverGasCredit             = errors.New("all gas credit has been spend")
        ErrGasCalculate              = errors.New("gas usage calculate got a math error")
+       ErrVotePubKey                = errors.New("invalid public key of vote")
 )
 
 // GasState record the gas usage status
 )
 
 // GasState record the gas usage status
@@ -227,6 +228,9 @@ func checkValid(vs *validationState, e bc.Entry) (err error) {
                }
 
        case *bc.VoteOutput:
                }
 
        case *bc.VoteOutput:
+               if len(e.Vote) != 64 {
+                       return ErrVotePubKey
+               }
                vs2 := *vs
                vs2.sourcePos = 0
                if err = checkValidSrc(&vs2, e.Source); err != nil {
                vs2 := *vs
                vs2.sourcePos = 0
                if err = checkValidSrc(&vs2, e.Source); err != nil {
@@ -270,6 +274,9 @@ func checkValid(vs *validationState, e bc.Entry) (err error) {
                        controlProgram = output.ControlProgram
                        value = output.Source.Value
                case *bc.VoteOutput:
                        controlProgram = output.ControlProgram
                        value = output.Source.Value
                case *bc.VoteOutput:
+                       if len(output.Vote) != 64 {
+                               return ErrVotePubKey
+                       }
                        controlProgram = output.ControlProgram
                        value = output.Source.Value
                default:
                        controlProgram = output.ControlProgram
                        value = output.Source.Value
                default: