Skip to content

Tracking: Improving receiver coin selection and output construction #1413

Open

Description

@arminsabouri

The purpose of this ticket is to collect improvements to receiver coin selection and output creation so that the resulting PayJoin transaction has a plausible trivial sub tx mapping and its more likely than other interpertations.

The current receiver strategy is:

  1. If output subsitution is allowed, add outputs / substitute output.
  2. Select a candidate input that avoids UIH2: the smallest input must exceed the smallest output
  3. Bump the payment output by exactly the receiver's input value (drain bump)

When no candidate passes the UIH2 check, the implementation falls back to selecting the first available candidate regardless. Technically this could be represented as a transient error and the implementation can decide wether to broadcast the fallback or produce a PJ with a UIH2 marker. UIH arguably is worse bc it definetly leaks idiosyncratic distribution.

An alternative raised during mob programming: split the receiver's outputs such that no single output is smaller than the receiver's input, simulating a batch payment and avoiding UIH2 without requiring a large input. How common is the peelchain-like structure in practice? Example Cake to BB tx. It seems like some data collection here is neccessary.

The cost is twofold. First, additional block space. Second and more importantly: the resulting outputs must never be spent together. Doing so reinstates CIH linkage and retroactively degrades the PayJoin.
What would the interface of this look like? Wallets today don't keep track of what UTXOs should NOT be spent together. Perhaps we have an oppurtunity to set the standard here.

Another observation: Input selection is not scored. The current loop returns the first UIH2-passing candidate. Among all passing candidates, those closest in magnitude to the sender's inputs are strictly preferable as they minimize value asymmetry, reduce the size signal UIH2 is a proxy for, and make the trivial mapping harder to distinguish from the two-party interpretation.

Perhaps another way of stating the problem and solution: input selection and output construction should be treated as a joint optimization. Given:

  • Sender inputs $I_S$ and outputs $O_S$ (fixed)
  • Receiver candidate UTXOs $\mathcal{C}$
  • Outputs the receiver must create
  • Outputs the receiver is willing to create (e.g. via splitting)

Select $I_R, O_R$ s.t the final transaction's value structure and behavioral fingerprints are consistent with a single rational party. The trivial mapping is arithmetically valid and no heuristic rules it out. Other valid mappings may exist and will likely exist as $|O_R|$ grows. Will need to workshop this definition a bit more.

Concrete tickets are TBD. First wanted to put my thoughts on paper

Related tickets: #460, #551

Activity

  1. bc1cindy commented on Mar 17, 2026

    @bc1cindy
    Contributor

    hey @arminsabouri !

    I'm very curious and excited about this area. Yesterday I was reading about fingerprints and found this repo (https://github.com/ishaanam/wallet-fingerprinting), so I started using to make some tests based on (https://github.com/payjoin/research-docs/blob/main/fingerprints/payjoin.md), and I saw your issue today, so I made a python script to collect data using a fork of the repo that I have locally, following the methodology bellow:

    100 blocks sampled uniformly across the last ~2 years (blocks ~835,898–941,018, one every ~1,051 blocks), 200 random transactions per block, ~20,000 transactions total. Data via mempool.space public API. Coinbase transactions and OP_RETURN outputs excluded

    Primary criterion requires all three simultaneously: 2+ inputs, 3+ outputs, and min(inputs) > min(outputs)

    Relaxed criterion structural match only: 2+ inputs, 3+ outputs, no value check. The gap between the two figures isolates how many transactions have the right structure but fail specifically on UIH2.

    for transactions passing the primary criterion, input asymmetry (max(inputs) / min(inputs)) was also recorded to address the scoring observation in the issue among UIH2-passing candidates. A ratio close to 1.0 means both inputs are similar in value, and high ratio (e.g. 10x) means that one input is much larger than the other

    after 5 hours running:

    python research.py --blocks 100 --max-txs 200 --spread
    Current block height : 941018
    Blocks to analyze    : 100
    Max txs per block    : 200
    Sampling             : random
    Temporal spread      : ~2 years
    
    Block 941018: 3571 total txs | analyzed: 200 | matches: 5 (2.5%)
    Block 939967: 4810 total txs | analyzed: 200 | matches: 0 (0.0%)
    Block 938916: 4972 total txs | analyzed: 200 | matches: 0 (0.0%)
    Block 937865: 4856 total txs | analyzed: 200 | matches: 3 (1.5%)
    Block 936814: 2373 total txs | analyzed: 200 | matches: 0 (0.0%)
    Block 935763: 1219 total txs | analyzed: 200 | matches: 2 (1.0%)
    Block 934712: 3285 total txs | analyzed: 200 | matches: 1 (0.5%)
    Block 933661: 3581 total txs | analyzed: 200 | matches: 1 (0.5%)
    Block 932610: 362 total txs | analyzed: 200 | matches: 0 (0.0%)
    Block 931559: 3242 total txs | analyzed: 200 | matches: 0 (0.0%)
    Block 930508: 4584 total txs | analyzed: 200 | matches: 0 (0.0%)
    Block 929457: 3799 total txs | analyzed: 200 | matches: 2 (1.0%)
    Block 928406: 3178 total txs | analyzed: 200 | matches: 3 (1.5%)
    Block 927355: 3227 total txs | analyzed: 200 | matches: 2 (1.0%)
    Block 926304: 3439 total txs | analyzed: 200 | matches: 0 (0.0%)
    Block 925253: 763 total txs | analyzed: 200 | matches: 1 (0.5%)
    Block 924202: 491 total txs | analyzed: 200 | matches: 4 (2.0%)
    Block 923151: 3605 total txs | analyzed: 200 | matches: 4 (2.0%)
    Block 922100: 3966 total txs | analyzed: 200 | matches: 1 (0.5%)
    Block 921049: 4598 total txs | analyzed: 200 | matches: 2 (1.0%)
    Block 919998: 4171 total txs | analyzed: 200 | matches: 3 (1.5%)
    Block 918947: 3603 total txs | analyzed: 200 | matches: 0 (0.0%)
    Block 917896: 3318 total txs | analyzed: 200 | matches: 5 (2.5%)
    Block 916845: 5540 total txs | analyzed: 200 | matches: 1 (0.5%)
    Block 915794: 5463 total txs | analyzed: 200 | matches: 2 (1.0%)
    Block 914743: 5538 total txs | analyzed: 200 | matches: 0 (0.0%)
    Block 913692: 3908 total txs | analyzed: 200 | matches: 2 (1.0%)
    Block 912641: 1901 total txs | analyzed: 200 | matches: 4 (2.0%)
    Block 911590: 2902 total txs | analyzed: 200 | matches: 1 (0.5%)
    Block 910539: 968 total txs | analyzed: 200 | matches: 1 (0.5%)
    Block 909488: 4003 total txs | analyzed: 200 | matches: 1 (0.5%)
    Block 908437: 135 total txs | analyzed: 134 | matches: 1 (0.7%)
    Block 907386: 3608 total txs | analyzed: 200 | matches: 1 (0.5%)
    Block 906335: 3058 total txs | analyzed: 200 | matches: 3 (1.5%)
    Block 905284: 1300 total txs | analyzed: 200 | matches: 5 (2.5%)
    Block 904233: 3537 total txs | analyzed: 200 | matches: 1 (0.5%)
    Block 903182: 3840 total txs | analyzed: 200 | matches: 2 (1.0%)
    Block 902131: 2398 total txs | analyzed: 200 | matches: 4 (2.0%)
    Block 901080: 2792 total txs | analyzed: 200 | matches: 3 (1.5%)
    Block 900029: 3228 total txs | analyzed: 200 | matches: 3 (1.5%)
    Block 898978: 1565 total txs | analyzed: 200 | matches: 2 (1.0%)
    Block 897927: 3755 total txs | analyzed: 200 | matches: 2 (1.0%)
    Block 896876: 4117 total txs | analyzed: 200 | matches: 3 (1.5%)
    Block 895825: 3382 total txs | analyzed: 200 | matches: 2 (1.0%)
    Block 894774: 1793 total txs | analyzed: 200 | matches: 4 (2.0%)
    Block 893723: 4979 total txs | analyzed: 200 | matches: 0 (0.0%)
    Block 892672: 4097 total txs | analyzed: 200 | matches: 4 (2.0%)
    Block 891621: 187 total txs | analyzed: 186 | matches: 3 (1.6%)
    Block 890570: 902 total txs | analyzed: 200 | matches: 3 (1.5%)
    Block 889519: 3182 total txs | analyzed: 200 | matches: 1 (0.5%)
    Block 888468: 1365 total txs | analyzed: 200 | matches: 2 (1.0%)
    Block 887417: 3773 total txs | analyzed: 200 | matches: 0 (0.0%)
    Block 886366: 2327 total txs | analyzed: 200 | matches: 3 (1.5%)
    Block 885315: 3433 total txs | analyzed: 200 | matches: 0 (0.0%)
    Block 884264: 311 total txs | analyzed: 200 | matches: 6 (3.0%)
    Block 883213: 3139 total txs | analyzed: 200 | matches: 2 (1.0%)
    Block 882162: 3474 total txs | analyzed: 200 | matches: 5 (2.5%)
    Block 881111: 3484 total txs | analyzed: 200 | matches: 5 (2.5%)
    Block 880060: 430 total txs | analyzed: 200 | matches: 1 (0.5%)
    Block 879009: 2923 total txs | analyzed: 200 | matches: 3 (1.5%)
    Block 877958: 4065 total txs | analyzed: 200 | matches: 1 (0.5%)
    Block 876907: 1569 total txs | analyzed: 200 | matches: 5 (2.5%)
    Block 875856: 2229 total txs | analyzed: 200 | matches: 1 (0.5%)
    Block 874805: 5036 total txs | analyzed: 200 | matches: 0 (0.0%)
    Block 873754: 3241 total txs | analyzed: 200 | matches: 1 (0.5%)
    Block 872703: 4164 total txs | analyzed: 200 | matches: 3 (1.5%)
    Block 871652: 1261 total txs | analyzed: 200 | matches: 1 (0.5%)
    Block 870601: 4820 total txs | analyzed: 200 | matches: 2 (1.0%)
    Block 869550: 4723 total txs | analyzed: 200 | matches: 0 (0.0%)
    Block 868499: 1840 total txs | analyzed: 200 | matches: 0 (0.0%)
    Block 867448: 3920 total txs | analyzed: 200 | matches: 6 (3.0%)
    Block 866397: 4824 total txs | analyzed: 200 | matches: 2 (1.0%)
    Block 865346: 3418 total txs | analyzed: 200 | matches: 1 (0.5%)
    Block 864295: 5021 total txs | analyzed: 200 | matches: 0 (0.0%)
    Block 863244: 3433 total txs | analyzed: 200 | matches: 1 (0.5%)
    Block 862193: 7161 total txs | analyzed: 200 | matches: 1 (0.5%)
    Block 861142: 3501 total txs | analyzed: 200 | matches: 3 (1.5%)
    Block 860091: 4565 total txs | analyzed: 200 | matches: 0 (0.0%)
    Block 859040: 3995 total txs | analyzed: 200 | matches: 1 (0.5%)
    Block 857989: 4026 total txs | analyzed: 200 | matches: 1 (0.5%)
    Block 856938: 7125 total txs | analyzed: 200 | matches: 0 (0.0%)
    Block 855887: 3443 total txs | analyzed: 200 | matches: 1 (0.5%)
    Block 854836: 3394 total txs | analyzed: 200 | matches: 2 (1.0%)
    Block 853785: 2621 total txs | analyzed: 200 | matches: 1 (0.5%)
    Block 852734: 2562 total txs | analyzed: 200 | matches: 2 (1.0%)
    Block 851683: 6375 total txs | analyzed: 200 | matches: 0 (0.0%)
    Block 850632: 5863 total txs | analyzed: 200 | matches: 0 (0.0%)
    Block 849581: 2908 total txs | analyzed: 200 | matches: 6 (3.0%)
    Block 848530: 5073 total txs | analyzed: 200 | matches: 0 (0.0%)
    Block 847479: 3903 total txs | analyzed: 200 | matches: 4 (2.0%)
    Block 846428: 6313 total txs | analyzed: 200 | matches: 2 (1.0%)
    Block 845377: 6383 total txs | analyzed: 200 | matches: 0 (0.0%)
    Block 844326: 3782 total txs | analyzed: 200 | matches: 2 (1.0%)
    Block 843275: 2209 total txs | analyzed: 200 | matches: 4 (2.0%)
    Block 842224: 3622 total txs | analyzed: 200 | matches: 2 (1.0%)
    Block 841173: 5051 total txs | analyzed: 200 | matches: 2 (1.0%)
    Block 840122: 5500 total txs | analyzed: 200 | matches: 8 (4.0%)
    Block 839071: 3139 total txs | analyzed: 200 | matches: 3 (1.5%)
    Block 838020: 4601 total txs | analyzed: 200 | matches: 4 (2.0%)
    Block 836969: 3850 total txs | analyzed: 200 | matches: 2 (1.0%)
    
    ──────────────────────────────────────────────────────────────────────
    METHODOLOGY
      Data source     : mempool.space public API
      Blocks analyzed : 100
      Sample size     : 19920 transactions
      Sampling method : random per block (unbiased)
      Block selection : spread across ~2 years 
      API requests    : 20112
      Coinbase txs    : excluded
      OP_RETURN outs  : excluded from output count
    
    ──────────────────────────────────────────────────────────────────────
    FINDINGS
    
      Primary criterion:
        Pattern : 2+ inputs + 3+ outputs
                  no output < smallest input  [UIH2-safe]
        Result  : 200 / 19920 = 1.00%
    
      Relaxed criterion  (without UIH2 value check):
        Pattern : 2+ inputs + 3+ outputs
        Result  : 620 / 19920 = 3.11%
    
      Note: the 2.11pp gap between relaxed and primary
      represents cases where the structure exists but fails UIH2,
      i.e. at least one output is smaller than the receiver's input.
    ──────────────────────────────────────────────────────────────────────
    INPUT ASYMMETRY  (transactions matching primary criterion)
      Ratio = max(input) / min(input).  1.0 = perfectly symmetric.
    
      1.0–1.5x  (near-symmetric)        50   25.0%  ████████████
      1.5–3x    (moderate)              32   16.0%  ████████
      3–10x     (asymmetric)            30   15.0%  ███████
      10x+      (highly asymm.)         88   44.0%  ██████████████████████
    
      Median ratio : 6.4x
      Mean ratio   : 77601.3x
    
      Interpretation: near-symmetric inputs (ratio close to 1.0) are
      the most plausible genuine PayJoin candidates. Higher ratios are
      more likely to be ordinary batch payments that happen to fit the
      structural pattern.
    ──────────────────────────────────────────────────────────────────────
    
    TRANSACTION STRUCTURE DISTRIBUTION  (inputs x outputs)
    
      Structure                        Count    Share  Notes
      ────────────────────────────── ───────  ───────  ──────────────────────────────
      1 input(s), 1 output(s)           8714   43.74%  sweep / consolidation
      1 input(s), 2 output(s)           6947   34.87%  classic payment
      2 input(s), 2 output(s)           1055    5.30%  classic PayJoin
      2 input(s), 1 output(s)            423    2.12%  
      1 input(s), 3 output(s)            378    1.90%  
      3 input(s), 2 output(s)            217    1.09%  
      3 input(s), 1 output(s)            145    0.73%  
      1 input(s), 4 output(s)            142    0.71%  
      2 input(s), 3 output(s)            116    0.58%  
      4 input(s), 1 output(s)             96    0.48%  
      4 input(s), 2 output(s)             82    0.41%  
      1 input(s), 5 output(s)             71    0.36%  
      4 input(s), 6 output(s)             64    0.32%  
      5 input(s), 1 output(s)             62    0.31%  
      5 input(s), 2 output(s)             59    0.30%  
      2 input(s), 4 output(s)             57    0.29%  
      1 input(s), 6 output(s)             50    0.25%  
      6 input(s), 1 output(s)             49    0.25%  
      60 input(s), 1 output(s)            47    0.24%  
      1 input(s), 7 output(s)             43    0.22%  
    
      Transactions containing OP_RETURN: 7098 (35.6%)
    
    ──────────────────────────────────────────────────────────────────────
    SAMPLE VALUE DISTRIBUTION  (total output value per tx)
      Reported for transparency:  higher-value txs are more likely
      to represent genuine user wallet activity vs. exchange/dust.
    
      <100k sat         8999   45.2%  ██████████████████████
      100k–1M           5620   28.2%  ██████████████
      1M–10M            2951   14.8%  ███████
      10M+ sat          2350   11.8%  █████
    

    here are some of the txids saved:

    Total UIH2-safe matches: 202
    
    ce884d617a0b64b2c9d2bc7feff0395da4dc857907601565eb6a952f9c720976  asymmetry=1.8x
    9c4e8b34903bd4382cc05d960253466d0ddc3a5f0437d4a257763ad9bf61219f  asymmetry=1.0x
    18bd7a4ffc62c48979dfad4297a6ccc2be3477450ac5c0b97637c7a2bf3d7262  asymmetry=1.3x
    f7b848ffe0daa668d93c717011e0d287a324ceb90f7beb96fad1345c8826a99c  asymmetry=428.7x
    840de0227fea1b7e01dfb56522af1dcb6978ff7f0f9cab47b11b43c5dcc07950  asymmetry=1.4x
    3b4f860c5d940929674a2641ab521ab02bbc0fd3a335e8cda27148cbdbeead6d  asymmetry=1.0x
    dd3e87334e994487b7c215b0c1610cf2a4fcd2497dde51baf00e5199438fa5cd  asymmetry=1.0x
    c14676a1253d08ef46e2ad069ce53fa009198403eda161321960c828f7cdebdb  asymmetry=8.8x
    88087eacb6c8691eeb110565d05ae0c8ffab8b8c99c50c9f79a1612cc94b7e52  asymmetry=4.0x
    5cddd7eb2af3e182950d4b4fadecf58caab7a80727242bc8112ae98cbe4048c1  asymmetry=328.3x
    bafb7fc2cc57eff8c1dd3a493d601e8bbaf5881411d229f34730015a3e5d91e3  asymmetry=987.7x
    d9965caf21ce9ff6f8154914959d3f8edc376761e32053d9066d4ceec1b6afee  asymmetry=1.4x
    e9d46e32f130ba6074f775b95b122348110eb80f6a9ea243e8b702b5d9de5634  asymmetry=5030.6x
    f22d92b88974fe8e9a79234273ebf27a30efa7fbf1ea44b91543d925b9b0e2a8  asymmetry=621.1x
    1808b51aacc0edb9047aaeeaa90fc38168abade0b6d5b021ce85eec88ffe92a7  asymmetry=1.1x
    9d438861f1c4e976f8134f795a41114970cb1093aecc89a471cd2cc283cff099  asymmetry=1.0x
    a8e457fe6a5fb825c16aade4a53191cc4f0a22dcfa968c78b1bb0c56e84d03f3  asymmetry=1.1x
    9d140b60505988096d6221e8f75a68b62d5cb534ca312c577d3d65f7ebf7c3f8  asymmetry=2.0x
    38fc8378686e32fd4c473c29f283220194eb8913247234d8c372937e5e205e93  asymmetry=110.3x
    5243db1d52665add728677517ecafa91a1d39c68a8bae0b89d52fc3e69fc4d76  asymmetry=53.2x
    2e4b07c7ba5e9a65a8a3f00ad3ef6f951acc769cc2cb6a3d07c11f8aacbcfbc6  asymmetry=1.0x
    f5f6af366c53928d24657f145c0ddeba549ee9861366f3ce8d9b340d1184efc4  asymmetry=8.2x
    6bc439d4c98950476d0125581b85469fb8f50a2bc165a20cb291124d06b72f81  asymmetry=10.8x
    177e0aa5a252f7caba076aaa62dff7f5733acd8894d8200299806233805a2ab0  asymmetry=3.5x
    654f77e1d2062c576c4ef6fceeada7644257fb6b911784363c01f636a6cdbd5b  asymmetry=25.5x
    c71b3856052ee2e9a15280e4a0a32cae5d57f64ac77491dd00dd0b4dbb379600  asymmetry=1.3x
    cc5a14f6e71b0d640db30d1c458e798bebe26d313578a8a7c295c16ca968d7dd  asymmetry=1.0x
    e447332b6dacd244491b4647d3cd3693a165c7e3fb171c167b3099cebe394ba4  asymmetry=22.6x
    e91f45d0f2cd7967dcb122f840b0ef6a44f875d3834e844db6866ffa83ed6d9f  asymmetry=1003.8x
    02dd24bf54a85e2412e2e34a26f06c8b3b6d85a262cf3dd5b7d88e784a7989c1  asymmetry=1.3x
    

    i was also thinking that could be good to contribute to (https://github.com/0xB10C/mainnet-observer) to have the data we may need being monitored

    digging more around the interface point, I see that when the receiver reaches the PayjoinProposal state, it already has all the info needed to create an isolation group: the set of output outpoints that must never be combined in a future spend. The wallet receives this group and persists it locally, encrypted alongside other UTXO metadata, never forwarded to the sender. This is the same pattern Samourai implemented with BlockedUTXO for Whirlpool outputs.
    The coin selector can honor the group before constructing any future transaction, it checks whether any pair of selected UTXOs belongs to the same isolation group. If so, the combination is discarded.

    if it's useful, I'm happy to run other scripts, in a different temporal spread, or criterions and help with what's needed!

  2. bc1cindy commented on Mar 17, 2026

    @bc1cindy
    Contributor
  3. arminsabouri commented on Mar 18, 2026

    @arminsabouri
    ContributorAuthor

    1 input(s), 1 output(s) 8714 43.74% sweep / consolidation

    Wow that is odd. Almost 50% are one input one output txs? Do these txs have any other similarities? Are they cpfp'ing? These questions are not related to the ticket but just curious what the story here is.

    Thanks for showing interest here. On-chain data def helps us make more informed choices (specifically whether or not to split outputs and understanding how bad of a problem this is). Im also curious if these consolidation txs are during fee rate dips. In the data set you collected what is the precentage of UIH2 flagged 2-input 2-output txs?

    PS: this kind of data collection pipeline is exactly what https://github.com/payjoin/tx-indexer was designed for. Its a work in progress but just wantted to mention it

  4. bc1cindy commented on Mar 19, 2026

    @bc1cindy
    Contributor

    How common is the peelchain-like structure in practice? @arminsabouri

    Image

    Almost 50% are one input one output txs? Do these txs have any other similarities? Are they cpfp'ing?

    Image Image

    In the data set you collected what is the percentage of UIH2 flagged 2-input 2-output txs?

    Image

    Do outputs get spent together?

    Image

    Input selection is not scored. The current loop returns the first UIH2-passing candidate. Among all passing candidates, those closest in magnitude to the sender's inputs are strictly preferable as they minimize value asymmetry, reduce the size signal UIH2 is a proxy for, and make the trivial mapping harder to distinguish from the two-party interpretation.

    Image

    62.7% of candidates contain P2PKH in some input or output, compared to 15.1% in the baseline, a difference of +47.6 pp. P2PKH is a legacy script type, practically absent in modern wallets. 44.1% have at least one output with a value divisible by 10,000 sat, compared to 6.3% in the baseline +37.8 pp. Round outputs are characteristic of exchange payments where the value is a clean number. 93.2% have locktime=0, without anti-fee-sniping, Bitcoin Core has enabled anti-fee-sniping by default since 2014. Only 10.2% have Taproot input, compared to 35.4% in the baseline -25.2 pp.

    Image

    282 transactions in the dataset have the structure that output splitting would produce, 1.4% of the total. Of these, 25.2% also pass the UIH2-check.

    Image

    Im also curious if these consolidation txs are during fee rate dips.

    Image
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions