diff --git a/src/darksend.cpp b/src/darksend.cpp index 4ce9a27828aa..d66826372871 100644 --- a/src/darksend.cpp +++ b/src/darksend.cpp @@ -379,8 +379,6 @@ void CDarksendPool::ProcessMessageDarksend(CNode* pfrom, std::string& strCommand } -int randomizeList (int i) { return std::rand()%i;} - void CDarksendPool::Reset(){ cachedLastSuccess = 0; lastNewBlock = 0; @@ -533,9 +531,9 @@ void CDarksendPool::Check() txNew.vin.push_back(s); } - // shuffle the outputs for improved anonymity - std::random_shuffle ( txNew.vin.begin(), txNew.vin.end(), randomizeList); - std::random_shuffle ( txNew.vout.begin(), txNew.vout.end(), randomizeList); + // BIP69 https://github.com/kristovatlas/bips/blob/master/bip-0069.mediawiki + sort(txNew.vin.begin(), txNew.vin.end()); + sort(txNew.vout.begin(), txNew.vout.end()); LogPrint("darksend", "Transaction 1: %s\n", txNew.ToString()); diff --git a/src/primitives/transaction.h b/src/primitives/transaction.h index af2c09738812..3c207785d93a 100644 --- a/src/primitives/transaction.h +++ b/src/primitives/transaction.h @@ -99,6 +99,11 @@ class CTxIn return !(a == b); } + friend bool operator<(const CTxIn& a, const CTxIn& b) + { + return a.prevout >& vecSend, BOOST_FOREACH(const PAIRTYPE(const CWalletTx*,unsigned int)& coin, setCoins) txNew.vin.push_back(CTxIn(coin.first->GetHash(),coin.second)); + // BIP69 https://github.com/kristovatlas/bips/blob/master/bip-0069.mediawiki + sort(txNew.vin.begin(), txNew.vin.end()); + sort(txNew.vout.begin(), txNew.vout.end()); + // Sign int nIn = 0; - BOOST_FOREACH(const PAIRTYPE(const CWalletTx*,unsigned int)& coin, setCoins) - if (!SignSignature(*this, *coin.first, txNew, nIn++)) + BOOST_FOREACH(const CTxIn& vin, txNew.vin) + if (!SignSignature(*this, mapWallet[vin.prevout.hash], txNew, nIn++)) { strFailReason = _("Signing transaction failed"); return false; @@ -2505,9 +2509,6 @@ string CWallet::PrepareDarksendDenominate(int minRounds, int maxRounds) return "Error: can't make current denominated outputs"; } - // randomize the output order - std::random_shuffle (vOut.begin(), vOut.end()); - // We also do not care about full amount as long as we have right denominations, just pass what we found darkSendPool.SendDarksendDenominate(vCoinsResult, vOut, nValueIn - nValueLeft);