You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Streamline, refactor and unify PS checks for mixing entries and final txes (#3246)
* Move PS mixing entry verification on masternodes into `AddEntry()`
Also streamline logic a bit and drop unused/excessive parts.
* Unify PS checks among masternodes and clients
* No need to re-check outputs over and over again
* No need to count, fail early if any output is missing
* No need to look any further once we found the input we expected
A tx with duplicate inputs would be considered invalid anyway and we also know there are no duplicates because we just verified the final tx above.
Also drop an unused variable.
* Unify LogPrint-s
* Drop human-readable strings for unused PoolMessage-s
* Apply suggestions from code review
Co-Authored-By: PastaPastaPasta <6443210+PastaPastaPasta@users.noreply.github.com>
* Re-introduce zero-fee checks
* fix log
* Move all txin/txout verification logic shared by CPrivateSendClientSession::SignFinalTransaction() and CPrivateSendServer::AddEntry() into CPrivateSendBaseSession::IsValidInOuts()
* fix nit
* Add missing return
* Use CCoinsViewMemPool instead of doing it manually
Co-authored-by: PastaPastaPasta <6443210+PastaPastaPasta@users.noreply.github.com>
Co-authored-by: Alexander Block <ablock84@gmail.com>
// STEP 2: make sure our own inputs/outputs are present, otherwise refuse to sign
571
+
558
572
std::vector<CTxIn> sigs;
559
573
560
-
//make sure my inputs/outputs are present, otherwise refuse to sign
561
574
for (constauto& entry : vecEntries) {
575
+
// Check that the final transaction has all our outputs
576
+
for (constauto& txout : entry.vecTxOut) {
577
+
boolfFound = false;
578
+
for (constauto& txoutFinal : finalMutableTransaction.vout) {
579
+
if (txoutFinal == txout) {
580
+
fFound = true;
581
+
break;
582
+
}
583
+
}
584
+
if (!fFound) {
585
+
// Something went wrong and we'll refuse to sign. It's possible we'll be charged collateral. But that's
586
+
// better than signing if the transaction doesn't look like what we wanted.
587
+
LogPrint(BCLog::PRIVATESEND, "CPrivateSendClientSession::%s -- an output is missing, refusing to sign! txout=%s\n", txout.ToString());
588
+
UnlockCoins();
589
+
keyHolderStorage.ReturnAll();
590
+
SetNull();
591
+
returnfalse;
592
+
}
593
+
}
594
+
562
595
for (constauto& txdsin : entry.vecTxDSIn) {
563
596
/* Sign my transaction and all outputs */
564
597
int nMyInputIndex = -1;
565
598
CScript prevPubKey = CScript();
566
-
CTxIn txin = CTxIn();
567
599
568
600
for (unsignedint i = 0; i < finalMutableTransaction.vin.size(); i++) {
569
601
if (finalMutableTransaction.vin[i] == txdsin) {
570
602
nMyInputIndex = i;
571
603
prevPubKey = txdsin.prevPubKey;
572
-
txin = txdsin;
604
+
break;
573
605
}
574
606
}
575
607
576
-
if (nMyInputIndex >= 0) { //might have to do this one input at a time?
577
-
int nFoundOutputsCount = 0;
578
-
CAmount nValue1 = 0;
579
-
CAmount nValue2 = 0;
580
-
581
-
for (constauto& txoutFinal : finalMutableTransaction.vout) {
582
-
for (constauto& txout : entry.vecTxOut) {
583
-
if (txoutFinal == txout) {
584
-
nFoundOutputsCount++;
585
-
nValue1 += txoutFinal.nValue;
586
-
}
587
-
}
588
-
}
589
-
590
-
for (constauto& txout : entry.vecTxOut) {
591
-
nValue2 += txout.nValue;
592
-
}
593
-
594
-
int nTargetOuputsCount = entry.vecTxOut.size();
595
-
if (nFoundOutputsCount < nTargetOuputsCount || nValue1 != nValue2) {
596
-
// in this case, something went wrong and we'll refuse to sign. It's possible we'll be charged collateral. But that's
597
-
// better then signing if the transaction doesn't look like what we wanted.
598
-
LogPrint(BCLog::PRIVATESEND, "CPrivateSendClientSession::SignFinalTransaction -- My entries are not correct! Refusing to sign: nFoundOutputsCount: %d, nTargetOuputsCount: %d\n", nFoundOutputsCount, nTargetOuputsCount);
599
-
UnlockCoins();
600
-
keyHolderStorage.ReturnAll();
601
-
SetNull();
602
-
603
-
returnfalse;
604
-
}
605
-
606
-
const CKeyStore& keystore = *vpwallets[0];
608
+
if (nMyInputIndex == -1) {
609
+
// Can't find one of my own inputs, refuse to sign. It's possible we'll be charged collateral. But that's
610
+
// better than signing if the transaction doesn't look like what we wanted.
LogPrint(BCLog::PRIVATESEND, "CPrivateSendClientSession::SignFinalTransaction -- Signing my input %i\n", nMyInputIndex);
609
-
// TODO we're using amount=0 here but we should use the correct amount. This works because Dash ignores the amount while signing/verifying (only used in Bitcoin/Segwit)
LogPrint(BCLog::PRIVATESEND, "CPrivateSendClientSession::%s -- Signing my input %i\n", __func__, nMyInputIndex);
621
+
// TODO we're using amount=0 here but we should use the correct amount. This works because Dash ignores the amount while signing/verifying (only used in Bitcoin/Segwit)
LogPrint(BCLog::PRIVATESEND, "CPrivateSendClientSession::SignFinalTransaction -- pushing sigs to the masternode, finalMutableTransaction=%s", finalMutableTransaction.ToString());
643
+
LogPrint(BCLog::PRIVATESEND, "CPrivateSendClientSession::%s -- pushing sigs to the masternode, finalMutableTransaction=%s", __func__, finalMutableTransaction.ToString());
0 commit comments