message: Make sure to check that block has 2 txs before checking 2nd tx is coinstake
diff: @@ -3542,17 +3542,19 @@ bool CheckBlock(const CBlock& block, CValidationState& state, const Consensus::P
  if (block.vtx[0]->vout.size() != (commitpos == -1 ? 1 : 2) || !block.vtx[0]->vout[0].IsEmpty())
  return state.DoS(100, false, REJECT_INVALID, "bad-cb-missing", false, "coinbase output not empty for proof-of-stake block");
  - // Second transaction must be coinstake, the rest must not be
  - if (block.vtx.empty() || !block.vtx[1]->IsCoinStake())
  + // Second transaction must be coinstake
  + if (block.vtx.empty() || block.vtx.size() < 2 || !block.vtx[1]->IsCoinStake())
  return state.DoS(100, false, REJECT_INVALID, "bad-cs-missing", false, "second tx is not coinstake");
  - for (unsigned int i = 2; i < block.vtx.size(); i++)
  - if (block.vtx[i]->IsCoinStake())
  - return state.DoS(100, false, REJECT_INVALID, "bad-cs-multiple", false, "more than one coinstake");
  //prevoutStake must exactly match the coinstake in the block body
  - if(block.prevoutStake != block.vtx[1]->vin[0].prevout){
  + if(block.vtx[1]->vin.empty() || block.prevoutStake != block.vtx[1]->vin[0].prevout){
  return state.DoS(100, false, REJECT_INVALID, "bad-cs-invalid", false, "prevoutStake in block header does not match coinstake in block body");
  }
  + //the rest of the transactions must not be coinstake
  + for (unsigned int i = 2; i < block.vtx.size(); i++)
  + if (block.vtx[i]->IsCoinStake())
  + return state.DoS(100, false, REJECT_INVALID, "bad-cs-multiple", false, "more than one coinstake");
  +
  }
  // Check proof-of-stake block signature
  