TeachMeBitcoin

The Art of the Group: Grouping Outputs to Avoid Address Reuse

From TeachMeBitcoin, the free encyclopedia Reading time: 3 min

The Art of the Group: Grouping Outputs to Avoid Address Reuse

In the "Forge of the Ledger," privacy is often lost through a simple mistake: Address Reuse. If you use the same address to receive money from five different people, those five people can see that those five payments belong to the same person. To prevent this, Bitcoin Core uses a system of "Output Grouping." When the wallet performs "Coin Selection," it doesn't just look at "Individual UTXOs"; it looks at "Groups" of UTXOs that belong to the same address. It treats the "Group" as a single, atomic unit. It is the "Privacy of the Collective."

The logic of grouping is simple: Spend it all or spend nothing. If you own three pieces of gold that were all sent to the same address, the wallet will always try to spend those three pieces together. This prevents the "Partial Spend" leak, where you spend one piece and leave the other two, inadvertently telling the world: "I still have more money at this address!" Grouping is handled by the GroupOutputs function in src/wallet/spend.cpp.

Analyzing the Group Logic: GroupOutputs

In the source code, we see how the wallet "Organizes" the inventory into groups using the "Address" (scriptPubKey) as the key.

/**
 * This function "Groups" individual coins by their address pattern.
 */
FilteredOutputGroups GroupOutputs(const CWallet& wallet, ...)
{
 // 1. We check the "Avoid Partial Spends" flag (-avoidpartialspends).
 if (!coin_sel_params.m_avoid_partial_spends) {
 // If disabled, every coin is its own "Group."
 return no_grouping;
 }

 // 2. Create a "Map" of Addresses to "OutputGroups."
 std::map<CScript, OutputGroup> group_map;

 // 3. We loop through every coin and "Insert" it into the correct group.
 for (const COutput& output : coins.All()) {
 group_map[output.scriptPubKey].Insert(output);
 }

 // 4. Return the "Groups" to the Selection Algorithms.
 return group_map;
}

Explaining the Group: The Money Bags

The Privacy of the "Identity Block"

By grouping outputs, you are telling the world: "This address is a single, atomic unit of wealth." This makes it much harder for someone to "Peel" your addresses apart and see the individual transactions that created them. Grouping is the "Shield of the Sovereign," the tool that allows you to manage your "Digital Shadows" with precision. You are the "Master of the Group," ensuring your financial "Identity" is never fragmented by the computer's greed for low fees.


☕ Help support TeachMeBitcoin

TeachMeBitcoin is an ad-free, open-source educational repository curated by a passionate team of Bitcoin researchers and educators for public benefit. If you found our articles helpful, please consider supporting our hosting and ongoing content updates with a clean donation:

Ethereum: 0x578417C51783663D8A6A811B3544E1f779D39A85
Bitcoin: bc1q77k9e95rn669kpzyjr8ke9w95zhk7pa5s63qzz
Solana: 4ycT2ayqeMucixj3wS8Ay8Tq9NRDYRPKYbj3UGESyQ4J
Address copied to clipboard!