Skip to content

Commit 57a70f2

Browse files
fix: gate payout collateral reuse checks to multipayout
1 parent 4401017 commit 57a70f2

4 files changed

Lines changed: 20 additions & 10 deletions

File tree

src/evo/providertx.cpp

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -88,17 +88,20 @@ bool IsPayoutListTriviallyValid(const MasternodePayoutShares& payouts, const CKe
8888
}
8989

9090
bool IsPayoutListKeySafe(const MasternodePayoutShares& payouts, const CTxDestination& collateral_dest,
91-
const CKeyID& keyIDOwner, const CKeyID& keyIDVoting, TxValidationState& state)
91+
const CKeyID& keyIDOwner, const CKeyID& keyIDVoting,
92+
bool check_payout_collateral_reuse, TxValidationState& state)
9293
{
9394
if (collateral_dest == CTxDestination(PKHash(keyIDOwner)) ||
9495
collateral_dest == CTxDestination(PKHash(keyIDVoting))) {
9596
return state.Invalid(TxValidationResult::TX_BAD_SPECIAL, "bad-protx-collateral-reuse");
9697
}
9798

98-
for (const auto& payout : payouts) {
99-
CTxDestination payout_dest;
100-
if (ExtractDestination(payout.scriptPayout, payout_dest) && payout_dest == collateral_dest) {
101-
return state.Invalid(TxValidationResult::TX_BAD_SPECIAL, "bad-protx-payee-reuse");
99+
if (check_payout_collateral_reuse) {
100+
for (const auto& payout : payouts) {
101+
CTxDestination payout_dest;
102+
if (ExtractDestination(payout.scriptPayout, payout_dest) && payout_dest == collateral_dest) {
103+
return state.Invalid(TxValidationResult::TX_BAD_SPECIAL, "bad-protx-payee-reuse");
104+
}
102105
}
103106
}
104107
return true;

src/evo/providertx.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,8 @@ using MasternodePayoutShares = std::vector<CMasternodePayoutShare>;
100100
[[nodiscard]] bool IsPayoutListTriviallyValid(const MasternodePayoutShares& payouts, const CKeyID& keyIDOwner,
101101
const CKeyID& keyIDVoting, TxValidationState& state);
102102
[[nodiscard]] bool IsPayoutListKeySafe(const MasternodePayoutShares& payouts, const CTxDestination& collateral_dest,
103-
const CKeyID& keyIDOwner, const CKeyID& keyIDVoting, TxValidationState& state);
103+
const CKeyID& keyIDOwner, const CKeyID& keyIDVoting,
104+
bool check_payout_collateral_reuse, TxValidationState& state);
104105
[[nodiscard]] std::string PayoutListToString(const MasternodePayoutShares& payouts);
105106
[[nodiscard]] UniValue PayoutListToJson(const MasternodePayoutShares& payouts);
106107

src/evo/specialtxman.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1067,7 +1067,8 @@ bool CheckProRegTx(const CTransaction& tx, gsl::not_null<const CBlockIndex*> pin
10671067
// don't allow reuse of collateral key for other keys (don't allow people to put the collateral key onto an online server)
10681068
// this check applies to internal and external collateral, but internal collaterals are not necessarily a P2PKH
10691069
if (!IsPayoutListKeySafe(GetOwnerPayouts(opt_ptx->nVersion, opt_ptx->scriptPayout, opt_ptx->payouts),
1070-
collateralTxDest, opt_ptx->keyIDOwner, opt_ptx->keyIDVoting, state)) return false;
1070+
collateralTxDest, opt_ptx->keyIDOwner, opt_ptx->keyIDVoting,
1071+
opt_ptx->nVersion >= ProTxVersion::MultiPayout, state)) return false;
10711072

10721073
if (pindexPrev) {
10731074
auto mnList = dmnman.GetListForBlock(pindexPrev);
@@ -1243,7 +1244,8 @@ bool CheckProUpRegTx(const CTransaction& tx, gsl::not_null<const CBlockIndex*> p
12431244
if (!ExtractDestination(coin.out.scriptPubKey, collateralTxDest)) {
12441245
return state.Invalid(TxValidationResult::TX_CONSENSUS, "bad-protx-collateral-dest");
12451246
}
1246-
if (!IsPayoutListKeySafe(owner_payouts, collateralTxDest, dmn->pdmnState->keyIDOwner, opt_ptx->keyIDVoting, state)) return false;
1247+
if (!IsPayoutListKeySafe(owner_payouts, collateralTxDest, dmn->pdmnState->keyIDOwner, opt_ptx->keyIDVoting,
1248+
opt_ptx->nVersion >= ProTxVersion::MultiPayout, state)) return false;
12471249

12481250
if (mnList.HasUniqueProperty(opt_ptx->pubKeyOperator)) {
12491251
auto otherDmn = mnList.GetUniquePropertyMN(opt_ptx->pubKeyOperator);

src/test/evo_trivialvalidation.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -183,14 +183,18 @@ BOOST_AUTO_TEST_CASE(multipayout_list_validation)
183183

184184
TxValidationState state;
185185
BOOST_CHECK(!IsPayoutListKeySafe({{payout1, 10000}}, CTxDestination(PKHash(payout_key1.GetPubKey().GetID())),
186-
owner_id, voting_id, state));
186+
owner_id, voting_id, /*check_payout_collateral_reuse=*/true, state));
187187
BOOST_CHECK_EQUAL(state.GetRejectReason(), "bad-protx-payee-reuse");
188+
state = TxValidationState{};
189+
BOOST_CHECK(IsPayoutListKeySafe({{payout1, 10000}}, CTxDestination(PKHash(payout_key1.GetPubKey().GetID())),
190+
owner_id, voting_id, /*check_payout_collateral_reuse=*/false, state));
188191

189192
CScript p2sh_collateral = GetScriptForDestination(ScriptHash(payout1));
190193
CTxDestination p2sh_dest;
191194
BOOST_CHECK(ExtractDestination(p2sh_collateral, p2sh_dest));
192195
state = TxValidationState{};
193-
BOOST_CHECK(!IsPayoutListKeySafe({{p2sh_collateral, 10000}}, p2sh_dest, owner_id, voting_id, state));
196+
BOOST_CHECK(!IsPayoutListKeySafe({{p2sh_collateral, 10000}}, p2sh_dest, owner_id, voting_id,
197+
/*check_payout_collateral_reuse=*/true, state));
194198
BOOST_CHECK_EQUAL(state.GetRejectReason(), "bad-protx-payee-reuse");
195199
}
196200

0 commit comments

Comments
 (0)