Shuffle zouts to prevent leaking change output position

This commit is contained in:
Duke Leto
2021-06-27 22:35:59 -04:00
parent 195af2c65a
commit d58396f05e
2 changed files with 12 additions and 0 deletions

View File

@@ -59,6 +59,13 @@ void TransactionBuilder::AddSaplingOutput(
mtx.valueBalance -= value;
}
// randomize the order of outputs
void TransactionBuilder::ShuffleOutputs()
{
LogPrintf("%s: Shuffling %d zouts\n", __func__, outputs.size() );
random_shuffle( outputs.begin(), outputs.end(), GetRandInt );
}
void TransactionBuilder::AddTransparentInput(COutPoint utxo, CScript scriptPubKey, CAmount value, uint32_t _nSequence)
{
if (keystore == nullptr) {
@@ -212,6 +219,9 @@ boost::optional<CTransaction> TransactionBuilder::Build()
mtx.vShieldedSpend.push_back(sdesc);
}
// Prevent leaking metadata about the position of change output
ShuffleOutputs();
// Create Sapling OutputDescriptions
for (auto output : outputs) {
auto cm = output.note.cm();