Skip to content

Conversation

@instagibbs
Copy link
Member

@instagibbs instagibbs commented Mar 15, 2018

Currently inputs are ordered based on COutPoint ordering, which while doesn't leak additional internal wallet state, likely further fingerprints the wallet as a Core wallet to observers.

Note: This slightly changed behavior of fundrawtransaction in that the newly-appended inputs will now be shuffled rather than in outpoint-order. This does not break API compatibility.

Simple shuffling of the coins being returned will hopefully allow the wallet to blend in a bit more, in lieu of additional data to find what other wallets are doing, or another standard, ala @gmaxwell's suggested of ordering via scriptPubKey.

@instagibbs instagibbs changed the title Shuffle transaction inputs before returning from SelectCoins [wallet] Shuffle transaction inputs before returning from SelectCoins Mar 15, 2018
@laanwj laanwj added the Wallet label Mar 15, 2018
@laanwj
Copy link
Member

laanwj commented Mar 15, 2018

Concept ACK - haven't reviewed yet but this looks like a lot of changes for just an additional input shuffle step?

@instagibbs
Copy link
Member Author

instagibbs commented Mar 15, 2018

Ok, I can make this smaller. Just realized that the inner-use of the inputs doesn't actually require proper ordering for transaction size estimation, so it should just be a single shuffle before signing.

A bit annoying due to inner-loop behavior, but I'll see what I can do.

@ryanofsky
Copy link
Contributor

@Sjors
Copy link
Member

Sjors commented Mar 15, 2018

Maybe just use the same ordering as BIP-69?

@instagibbs
Copy link
Member Author

@Sjors I'd prefer to something slightly less bad now, and converge on a standard later. I have some quibbles with BIP69, which I think are out of scope for this thread.

@Sjors
Copy link
Member

Sjors commented Mar 15, 2018

TIL the Core wallet doesn't use BIP-69 (which is a separate discussion), so that does weaken the case for using it here. (and TIL coin selection function also determines the order, not just the set)

See also #12457

@instagibbs
Copy link
Member Author

Smaller changeset now, had to move the final input creation further output to avoid storing shuffle ordering.

@fanquake fanquake requested a review from achow101 March 15, 2018 22:50
@instagibbs
Copy link
Member Author

instagibbs commented Mar 16, 2018

Turns out that we're ~this far away(in master) from having the input part compliant with BIP69:

struct bip69_compare {
bool operator() (const uint256& lhs, const uint256& rhs) const
{
uint256 lhs_hash = rhs;
uint256 rhs_hash = lhs;
std::reverse(lhs_hash.begin(), lhs_hash.end());
std::reverse(rhs_hash.begin(), rhs_hash.end());
return rhs_hash < lhs_hash;
}
};`

The inputs are being sorted by BE rather than LE as per the BIP.

We also currently aren't really shuffling outputs randomly(except the case of 2 outputs, 1 destination and 1 change. This is fixed by a single shuffle line. BIP69 compliance would be another comparison struct.

I still prefer this changeset for the time being, due to ease of implementation and complementary nature with #12709

@luke-jr
Copy link
Member

luke-jr commented Mar 16, 2018

BIP 69 contradicts SIGHASH_SINGLE usage, and its concerns seem unrealistic (if you use malicious closed source wallet software, you're already compromised regardless). Randomising seems fine.

@donaloconnor
Copy link
Contributor

utACK 8712bbd

@instagibbs
Copy link
Member Author

rebased onto #12742 to avoid code churn

@sipa
Copy link
Member

sipa commented Mar 21, 2018

utACK 2fb9c1e

@maflcko
Copy link
Member

maflcko commented Mar 22, 2018

If you want to remove the erroneous diff from the GitHub web view:

EDITOR=true git commit --allow-empty -m empty && git push [email protected]:instagibbs/bitcoin.git shuffleinputs && git reset --hard 2fb9c1e && git push [email protected]:instagibbs/bitcoin.git shuffleinputs -f

@maflcko
Copy link
Member

maflcko commented Mar 22, 2018

utACK 2fb9c1e

maflcko pushed a commit that referenced this pull request Mar 23, 2018
6acb02d add release note for sendmany output shuffling (Gregory Sanders)
cf6ef3c shuffle sendmany recipients ordering to shuffle tx outputs (Gregory Sanders)

Pull request description:

  Unless there is something important I'm missing, we're just possible leaking information by preserving whatever ordering json object ordering is giving us (no guarantees at all).

  This is unneeded for `sendtoaddress` since there is only 1 or 2 outputs, and the change output is shuffled in.

  This will not effect `*raw` behavior by design, since users generally want full control using those apis. Further PRs could add optional args to over-ride that behavior.

  Alternative ideas would be to sort the outputs by some deterministic ordering. (this would require more refactoring since change outputs are created and handled by caller)

  related: #12699

Tree-SHA512: afdd990dde6a4a9e7eef7bb2e3342a46d11900d7fe6e6e4eb0cc6b5deed89df989fa7931a4bdcbf49b7c2d7a13c90169af3a166466e5760948bacabe3490f572
@promag
Copy link
Contributor

promag commented Mar 24, 2018

utACK 2fb9c1e, looks good.

This slightly changed behavior of fundrawtransaction in that the newly-appended inputs will now be shuffled rather than in outpoint-order.

At least the test framework doesn't rely on the order.

@sipa
Copy link
Member

sipa commented Mar 24, 2018

PR title seems outdated now (the shuffle happens after SelectCoins returns).

@instagibbs instagibbs changed the title [wallet] Shuffle transaction inputs before returning from SelectCoins [wallet] Shuffle transaction inputs before signing Mar 26, 2018
@instagibbs
Copy link
Member Author

updated title

@jamesob
Copy link
Contributor

jamesob commented Mar 26, 2018

utACK 2fb9c1e

@laanwj laanwj merged commit 2fb9c1e into bitcoin:master Mar 26, 2018
laanwj added a commit that referenced this pull request Mar 26, 2018
2fb9c1e shuffle selected coins before transaction finalization (Gregory Sanders)

Pull request description:

  Currently inputs are ordered based on COutPoint ordering, which while doesn't leak additional internal wallet state, likely further fingerprints the wallet as a Core wallet to observers.

  Note: This slightly changed behavior of `fundrawtransaction` in that the newly-appended inputs will now be shuffled rather than in outpoint-order. This does not break API compatibility.

  Simple shuffling of the coins being returned will hopefully allow the wallet to blend in a bit more, in lieu of additional data to find what other wallets are doing, or another standard, ala @gmaxwell's suggested of ordering via scriptPubKey.

Tree-SHA512: 70689a6eccf9fa7fc6e3d884f2eba4b482446a1e6128beff7a98f446d0c60f7966c5a6c55e9b0b3d73a9b539ce54889a26c7efe78ab7f34af386d5e4f3fa6df2
Fabcien pushed a commit to Bitcoin-ABC/bitcoin-abc that referenced this pull request Aug 30, 2019
Summary:
6acb02d add release note for sendmany output shuffling (Gregory Sanders)
cf6ef3c shuffle sendmany recipients ordering to shuffle tx outputs (Gregory Sanders)

Pull request description:

  Unless there is something important I'm missing, we're just possible leaking information by preserving whatever ordering json object ordering is giving us (no guarantees at all).

  This is unneeded for `sendtoaddress` since there is only 1 or 2 outputs, and the change output is shuffled in.

  This will not effect `*raw` behavior by design, since users generally want full control using those apis. Further PRs could add optional args to over-ride that behavior.

  Alternative ideas would be to sort the outputs by some deterministic ordering. (this would require more refactoring since change outputs are created and handled by caller)

  related: bitcoin/bitcoin#12699

Tree-SHA512: afdd990dde6a4a9e7eef7bb2e3342a46d11900d7fe6e6e4eb0cc6b5deed89df989fa7931a4bdcbf49b7c2d7a13c90169af3a166466e5760948bacabe3490f572

Backport of Core PR12709
bitcoin/bitcoin#12709

Test Plan:
  make check
  test_runner.py

Reviewers: deadalnix, Fabien, jasonbcox, O1 Bitcoin ABC, #bitcoin_abc

Reviewed By: deadalnix, O1 Bitcoin ABC, #bitcoin_abc

Differential Revision: https://reviews.bitcoinabc.org/D3897
@bitcoin bitcoin locked as resolved and limited conversation to collaborators Sep 8, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

10 participants