diff --git a/src/validation.cpp b/src/validation.cpp index bc8e163cb5ece7..046b303ce29caa 100644 --- a/src/validation.cpp +++ b/src/validation.cpp @@ -11,6 +11,7 @@ #include "validation.h" #include "addrman.h" +#include "amount.h" #include "blocksignature.h" #include "budget/budgetmanager.h" #include "chainparams.h" @@ -1567,6 +1568,15 @@ static bool ConnectBlock(const CBlock& block, CValidationState& state, CBlockInd CAmount txValueOut = tx.GetValueOut(); if (!tx.IsCoinBase()) { CAmount txValueIn = view.GetValueIn(tx); + // Check that CoinStake pays the expected amount + if (tx.IsCoinStake() && isV6UpgradeEnforced) { + CAmount stakeMint = txValueOut - txValueIn; + CAmount nExpectedStakeMint = GetBlockValue(pindex->nHeight) - GetMasternodePayment(pindex->nHeight); + if (stakeMint != nExpectedStakeMint) { + return state.DoS(100, error("%s: coinstake pays too much (actual=%s vs limit=%s)", __func__, FormatMoney(stakeMint), FormatMoney(nExpectedStakeMint)), + REJECT_INVALID, "bad-blk-stake-amount"); + } + } if (!tx.IsCoinStake()) nFees += txValueIn - txValueOut; nValueIn += txValueIn;