Skip to content

Commit 0c4d2df

Browse files
committed
Enforce correct coinstake payment
1 parent 559e4f1 commit 0c4d2df

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

src/validation.cpp

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#include "validation.h"
1212

1313
#include "addrman.h"
14+
#include "amount.h"
1415
#include "blocksignature.h"
1516
#include "budget/budgetmanager.h"
1617
#include "chainparams.h"
@@ -21,6 +22,7 @@
2122
#include "consensus/tx_verify.h"
2223
#include "consensus/validation.h"
2324
#include "consensus/zerocoin_verify.h"
25+
#include "evo/deterministicmns.h"
2426
#include "evo/evodb.h"
2527
#include "evo/specialtx_validation.h"
2628
#include "flatfile.h"
@@ -1567,6 +1569,28 @@ static bool ConnectBlock(const CBlock& block, CValidationState& state, CBlockInd
15671569
CAmount txValueOut = tx.GetValueOut();
15681570
if (!tx.IsCoinBase()) {
15691571
CAmount txValueIn = view.GetValueIn(tx);
1572+
// Once v6 is enforced and legacy mns are obsolete check that CoinStake does not overmint
1573+
if (tx.IsCoinStake() && isV6UpgradeEnforced && deterministicMNManager->LegacyMNObsolete(pindex->nHeight)) {
1574+
CAmount stakeMint = txValueOut - txValueIn;
1575+
// This is a possible superblock: coinstake cannot pay more than the blockvalue (TODO: update for single superblock payment)
1576+
if (pindex->nHeight % consensus.nBudgetCycleBlocks < 100) {
1577+
CAmount maxStakeMint = GetBlockValue(pindex->nHeight);
1578+
if (stakeMint > maxStakeMint) {
1579+
return state.DoS(100, error("%s: coinstake pays too much (actual=%s vs limit=%s)", __func__, FormatMoney(stakeMint), FormatMoney(maxStakeMint)),
1580+
REJECT_INVALID, "bad-blk-stake-amount");
1581+
}
1582+
} else {
1583+
// Masternode found, subtract its reward from the expected stake reward
1584+
CAmount nExpectedStakeMint = GetBlockValue(pindex->nHeight);
1585+
if (deterministicMNManager->GetListForBlock(pindex->pprev).GetMNPayee()) {
1586+
nExpectedStakeMint -= GetMasternodePayment(pindex->nHeight);
1587+
}
1588+
if (stakeMint != nExpectedStakeMint) {
1589+
return state.DoS(100, error("%s: coinstake pays too much (actual=%s vs limit=%s)", __func__, FormatMoney(stakeMint), FormatMoney(nExpectedStakeMint)),
1590+
REJECT_INVALID, "bad-blk-stake-amount");
1591+
}
1592+
}
1593+
}
15701594
if (!tx.IsCoinStake())
15711595
nFees += txValueIn - txValueOut;
15721596
nValueIn += txValueIn;

test/lint/lint-circular-dependencies.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ EXPECTED_CIRCULAR_DEPENDENCIES=(
5555
"chain -> legacy/stakemodifier -> validation -> pow -> chain"
5656
"evo/deterministicmns -> masternodeman -> net -> tiertwo/net_masternodes -> evo/deterministicmns"
5757
"evo/deterministicmns -> masternodeman -> validation -> validationinterface -> evo/deterministicmns"
58+
"evo/deterministicmns -> masternodeman -> validation -> evo/deterministicmns"
5859
)
5960

6061
EXIT_CODE=0

0 commit comments

Comments
 (0)