@@ -105,7 +105,7 @@ bool CheckProRegTx(const CTransaction& tx, const CBlockIndex* pindexPrev, CValid
105105 // should not happen as we checked script types before
106106 return state.DoS (10 , false , REJECT_INVALID, " bad-protx-payee-dest" );
107107 }
108- // don't allow reuse of collateral key for other keys (don't allow people to put the collateral key onto an online server)
108+ // don't allow reuse of payout key for other keys (don't allow people to put the payee key onto an online server)
109109 if (payoutDest == CTxDestination (ptx.keyIDOwner ) || payoutDest == CTxDestination (ptx.keyIDVoting )) {
110110 return state.DoS (10 , false , REJECT_INVALID, " bad-protx-payee-reuse" );
111111 }
@@ -120,6 +120,7 @@ bool CheckProRegTx(const CTransaction& tx, const CBlockIndex* pindexPrev, CValid
120120 return state.DoS (10 , false , REJECT_INVALID, " bad-protx-operator-reward" );
121121 }
122122
123+ CTxDestination collateralTxDest;
123124 CKeyID keyForPayloadSig;
124125 COutPoint collateralOutpoint;
125126
@@ -129,15 +130,13 @@ bool CheckProRegTx(const CTransaction& tx, const CBlockIndex* pindexPrev, CValid
129130 return state.DoS (10 , false , REJECT_INVALID, " bad-protx-collateral" );
130131 }
131132
132- CTxDestination txDest;
133- if (!ExtractDestination (coin.out .scriptPubKey , txDest)) {
133+ if (!ExtractDestination (coin.out .scriptPubKey , collateralTxDest)) {
134134 return state.DoS (10 , false , REJECT_INVALID, " bad-protx-collateral-dest" );
135135 }
136136
137137 // Extract key from collateral. This only works for P2PK and P2PKH collaterals and will fail for P2SH.
138138 // Issuer of this ProRegTx must prove ownership with this key by signing the ProRegTx
139- CBitcoinAddress txAddr (txDest);
140- if (!txAddr.GetKeyID (keyForPayloadSig)) {
139+ if (!CBitcoinAddress (collateralTxDest).GetKeyID (keyForPayloadSig)) {
141140 return state.DoS (10 , false , REJECT_INVALID, " bad-protx-collateral-pkh" );
142141 }
143142
@@ -149,9 +148,20 @@ bool CheckProRegTx(const CTransaction& tx, const CBlockIndex* pindexPrev, CValid
149148 if (tx.vout [ptx.collateralOutpoint .n ].nValue != 1000 * COIN) {
150149 return state.DoS (10 , false , REJECT_INVALID, " bad-protx-collateral" );
151150 }
151+
152+ if (!ExtractDestination (tx.vout [ptx.collateralOutpoint .n ].scriptPubKey , collateralTxDest)) {
153+ return state.DoS (10 , false , REJECT_INVALID, " bad-protx-collateral-dest" );
154+ }
155+
152156 collateralOutpoint = COutPoint (tx.GetHash (), ptx.collateralOutpoint .n );
153157 }
154158
159+ // don't allow reuse of collateral key for other keys (don't allow people to put the collateral key onto an online server)
160+ // this check applies to internal and external collateral, but internal collaterals are not necessarely a P2PKH
161+ if (collateralTxDest == CTxDestination (ptx.keyIDOwner ) || collateralTxDest == CTxDestination (ptx.keyIDVoting )) {
162+ return state.DoS (10 , false , REJECT_INVALID, " bad-protx-collateral-reuse" );
163+ }
164+
155165 if (pindexPrev) {
156166 auto mnList = deterministicMNManager->GetListForBlock (pindexPrev->GetBlockHash ());
157167
@@ -279,14 +289,24 @@ bool CheckProUpRegTx(const CTransaction& tx, const CBlockIndex* pindexPrev, CVal
279289 return state.DoS (100 , false , REJECT_INVALID, " bad-protx-hash" );
280290 }
281291
282- // don't allow reuse of collateral key for other keys (don't allow people to put the collateral key onto an online server)
292+ // don't allow reuse of payee key for other keys (don't allow people to put the payee key onto an online server)
283293 if (payoutDest == CTxDestination (dmn->pdmnState ->keyIDOwner ) || payoutDest == CTxDestination (ptx.keyIDVoting )) {
284294 return state.DoS (10 , false , REJECT_INVALID, " bad-protx-payee-reuse" );
285295 }
286296
287297 Coin coin;
288298 if (!GetUTXOCoin (dmn->collateralOutpoint , coin)) {
289- return state.DoS (100 , false , REJECT_INVALID, " bad-protx-payee-collateral" );
299+ // this should never happen (there would be no dmn otherwise)
300+ return state.DoS (100 , false , REJECT_INVALID, " bad-protx-collateral" );
301+ }
302+
303+ // don't allow reuse of collateral key for other keys (don't allow people to put the collateral key onto an online server)
304+ CTxDestination collateralTxDest;
305+ if (!ExtractDestination (coin.out .scriptPubKey , collateralTxDest)) {
306+ return state.DoS (100 , false , REJECT_INVALID, " bad-protx-collateral-dest" );
307+ }
308+ if (collateralTxDest == CTxDestination (dmn->pdmnState ->keyIDOwner ) || collateralTxDest == CTxDestination (ptx.keyIDVoting )) {
309+ return state.DoS (10 , false , REJECT_INVALID, " bad-protx-collateral-reuse" );
290310 }
291311
292312 if (mnList.HasUniqueProperty (ptx.pubKeyOperator )) {
0 commit comments