Skip to content

Commit

Permalink
Enforce correct coinstake payment
Browse files Browse the repository at this point in the history
  • Loading branch information
panleone committed Jul 27, 2023
1 parent 559e4f1 commit 4968454
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/validation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include "validation.h"

#include "addrman.h"
#include "amount.h"
#include "blocksignature.h"
#include "budget/budgetmanager.h"
#include "chainparams.h"
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 4968454

Please sign in to comment.