bitcoin/src/bench
Andrew Chow 1abbae65eb
Merge bitcoin/bitcoin#24584: wallet: avoid mixing different OutputTypes during coin selection
71d1d13627 test: add unit test for AvailableCoins (josibake)
da03cb41a4 test: functional test for new coin selection logic (josibake)
438e04845b wallet: run coin selection by `OutputType` (josibake)
77b0707206 refactor: use CoinsResult struct in SelectCoins (josibake)
2e67291ca3 refactor: store by OutputType in CoinsResult (josibake)

Pull request description:

  # Concept

  Following https://github.com/bitcoin/bitcoin/pull/23789, Bitcoin Core wallet will now generate a change address that matches the payment address type. This improves privacy by not revealing which of the outputs is the change at the time of the transaction in scenarios where the input address types differ from the payment address type. However, information about the change can be leaked in a later transaction. This proposal attempts to address that concern.

  ## Leaking information in a later transaction

  Consider the following scenario:

  ![mix input types(1)](https://user-images.githubusercontent.com/7444140/158597086-788339b0-c698-4b60-bd45-9ede4cd3a483.png)

  1. Alice has a wallet with bech32 type UTXOs and pays Bob, who gives her a P2SH address
  2. Alice's wallet generates a P2SH change output, preserving her privacy in `txid: a`
  3. Alice then pays Carol, who gives her a bech32 address
  4. Alice's wallet combines the P2SH UTXO with a bech32 UTXO and `txid: b` has two bech32 outputs

  From a chain analysis perspective, it is reasonable to infer that the P2SH input in `txid: b` was the change from `txid: a`. To avoid leaking information in this scenario, Alice's wallet should avoid picking the P2SH output and instead fund the transaction with only bech32 Outputs. If the payment to Carol can be funded with just the P2SH output, it should be preferred over the bech32 outputs as this will convert the P2SH UTXO to bech32 UTXOs via the payment and change outputs of the new transaction.

  **TLDR;** Avoid mixing output types, spend non-default `OutputTypes` when it is economical to do so.

  # Approach

  `AvailableCoins` now populates a struct, which makes it easier to access coins by `OutputType`. Coin selection tries to find a funding solution by each output type and chooses the most economical by waste metric. If a solution can't be found without mixing, coin selection runs over the entire wallet, allowing mixing, which is the same as the current behavior.

  I've also added a functional test (`test/functional/wallet_avoid_mixing_output_types.py`) and unit test (`src/wallet/test/availablecoins_tests.cpp`.

ACKs for top commit:
  achow101:
    re-ACK 71d1d13627
  aureleoules:
    ACK 71d1d13627.
  Xekyo:
    reACK 71d1d13627 via `git range-diff master 6530d19 71d1d13`
  LarryRuane:
    ACK 71d1d13627

Tree-SHA512: 2e0716efdae5adf5479446fabc731ae81d595131d3b8bade98b64ba323d0e0c6d964a67f8c14c89c428998bda47993fa924f3cfca1529e2bd49eaa4e31b7e426
2022-07-28 18:16:51 -04:00
..
data Add deserialize + CheckBlock benchmarks, and a full block hex 2016-11-09 11:27:59 -08:00
.gitignore Ignore bench_bitcoin binary. 2015-10-06 17:46:12 +02:00
addrman.cpp refactor: Use type-safe std::chrono for addrman time 2022-07-26 11:06:10 +02:00
base58.cpp scripted-diff: Bump copyright headers 2020-12-31 09:45:41 +01:00
bech32.cpp scripted-diff: Bump copyright headers 2021-12-30 19:36:57 +02:00
bench.cpp Fixup option name in bench message 2022-05-25 00:26:38 -05:00
bench.h bench: Add --sanity-check flag, use it in make check 2022-05-17 11:32:25 +02:00
bench_bitcoin.cpp bench: Make all arguments -kebab-case 2022-05-17 11:32:25 +02:00
block_assemble.cpp scripted-diff: Bump copyright headers 2021-12-30 19:36:57 +02:00
ccoins_caching.cpp scripted-diff: Bump copyright headers 2021-12-30 19:36:57 +02:00
chacha20.cpp scripted-diff: Bump copyright headers 2020-12-31 09:45:41 +01:00
chacha_poly_aead.cpp Do not run functions with necessary side-effects in assert() 2020-12-06 00:48:09 +00:00
checkblock.cpp Add missing includes 2022-07-19 14:12:33 +02:00
checkqueue.cpp refactor: use C++11 default initializers 2022-05-17 17:18:58 +01:00
coin_selection.cpp wallet: run coin selection by OutputType 2022-07-19 18:42:15 +02:00
crypto_hash.cpp scripted-diff: Bump copyright headers 2021-12-30 19:36:57 +02:00
data.cpp scripted-diff: Bump copyright headers 2021-12-30 19:36:57 +02:00
data.h bench: Move generated data to a dedicated translation unit 2019-07-02 18:11:15 +01:00
duplicate_inputs.cpp scripted-diff: Bump copyright headers 2021-12-30 19:36:57 +02:00
examples.cpp bench: Avoid deprecated use of volatile += 2022-02-17 17:25:57 +01:00
gcs_filter.cpp Update GCSFilter benchmarks 2022-05-22 14:17:15 +09:00
hashpadding.cpp scripted-diff: Bump copyright headers 2020-12-31 09:45:41 +01:00
lockedpool.cpp scripted-diff: Bump copyright headers 2020-12-31 09:45:41 +01:00
logging.cpp bench: Add logging benchmark 2021-12-15 14:33:59 +01:00
mempool_eviction.cpp bench: Use existing CTxMemPool in TestingSetup 2022-06-15 17:28:55 -04:00
mempool_stress.cpp use testing setup mempool in ComplexMemPool bench 2022-05-30 16:00:41 -07:00
merkle_root.cpp Replace current benchmarking framework with nanobench 2020-06-13 12:24:18 +02:00
nanobench.cpp Replace current benchmarking framework with nanobench 2020-06-13 12:24:18 +02:00
nanobench.h bench: update nanobench from 4.3.4 to 4.3.6 2021-09-21 11:46:01 +02:00
peer_eviction.cpp scripted-diff: Rename touched member variables 2021-12-13 13:32:08 +01:00
poly1305.cpp scripted-diff: Bump copyright headers 2020-12-31 09:45:41 +01:00
prevector.cpp refactor: use C++11 default initializers 2022-05-17 17:18:58 +01:00
rollingbloom.cpp refactor: Remove deduplication of data in rollingbloom bench 2022-04-06 13:57:31 +01:00
rpc_blockchain.cpp move-mostly: Make fHavePruned a BlockMan member 2022-04-19 14:34:56 -04:00
rpc_mempool.cpp bench/rpc_mempool: Create ChainTestingSetup, use its CTxMemPool 2022-06-15 17:28:55 -04:00
strencodings.cpp bench: Adds a benchmark for HexStr 2022-04-17 14:29:52 +02:00
util_time.cpp scripted-diff: Bump copyright headers 2020-12-31 09:45:41 +01:00
verify_script.cpp scripted-diff: Bump copyright headers 2021-12-30 19:36:57 +02:00
wallet_balance.cpp refactor: fix clang-tidy named args usage 2022-04-04 09:01:19 +01:00
wallet_loading.cpp refactor: remove unused using directives 2022-07-18 17:25:03 +01:00