Sub topic 5
Grouping addresses into entities with clustering heuristics
This chapter assumes you know what a wallet address and a transaction are, and that you can read basic Python. It also assumes you have seen the UTXO and account models from the earlier chapter. Here you will learn how analysts merge many addresses into one entity, which is a single person, company, or service that controls them. You will also learn when those merges are wrong.
Why clustering is needed
A blockchain records addresses, not owners. One exchange can use thousands of addresses, and one person can use hundreds. If you compute flows or balances per address, you will undercount large holders and miss exchange activity. For example, a holder who splits 10,000 coins across 100 addresses looks like 100 small holders.
Address clustering is the process of grouping addresses that probably share a controller. The result is a cluster. A later chapter covers labeling, which attaches a name such as "ExchangeA" to a cluster. Clustering comes first and labeling builds on it. A wrong cluster therefore carries into every label and every flow number built on it.
Clustering produces probabilities, not proofs. Every heuristic below is an assumption about how people and software behave, and each one has known exceptions.
Heuristic 1: common-input ownership (UTXO chains)
On Bitcoin-style chains, a transaction spends several inputs, which are previous outputs. To spend an input, the spender must sign with the key that controls it. A wallet that needs more value than any single input holds will therefore sign several inputs in one transaction. The heuristic infers that all input addresses of one transaction share an owner.
Clusters then grow by transitivity. If transaction 1 spends from A and B, and transaction 2 spends from B and C, then A, B, and C form one cluster. A union-find (disjoint-set) structure handles this efficiently. It keeps one representative per group and merges groups as evidence arrives.
def cluster_by_common_input(transactions, max_inputs=None):
"""transactions: list of lists of input addresses, one list per transaction.
max_inputs: skip transactions with more inputs than this (possible mixers).
Returns a dict mapping each address to a cluster representative."""
parent = {}
def find(a):
parent.setdefault(a, a)
while parent[a] != a:
parent[a] = parent[parent[a]] # path halving
a = parent[a]
return a
def union(a, b):
ra, rb = find(a), find(b)
if ra != rb:
parent[rb] = ra
for inputs in transactions:
if not inputs:
continue
if max_inputs is not None and len(inputs) > max_inputs:
continue
for addr in inputs:
find(addr)
for addr in inputs[1:]:
union(inputs[0], addr)
return {addr: find(addr) for addr in list(parent)}
def group_clusters(mapping):
groups = {}
for addr, rep in mapping.items():
groups.setdefault(rep, set()).add(addr)
return sorted(sorted(g) for g in groups.values())
txs = [["A", "B"], ["B", "C"], ["D"], ["E", "F", "G", "H", "I", "J"]]
print(group_clusters(cluster_by_common_input(txs, max_inputs=5)))
# [['A', 'B', 'C'], ['D']]The last transaction has six inputs and is skipped because of max_inputs=5. Without that limit, E through J would form a cluster too. The guard is crude. It is useful to see why it exists, which the next sections explain.
Heuristic 2: change-address detection
A UTXO transaction usually sends part of its inputs to the recipient and the rest back to the sender as change. If you can identify the change output, you can link it to the inputs. Analysts look for these signals:
- The output address has never appeared on-chain before, while the payment output has.
- The output uses the same script type as the inputs, and the payment output does not.
- One output is a round amount, such as 0.5, and the other is not.
These signals are weaker than common-input ownership. Wallets differ in how they build transactions, and a single wrong change link can merge two unrelated clusters. Many analysts apply this heuristic only when several signals agree.
Heuristic 3: deposit-address sweeps (account chains)
Ethereum and similar chains have no multi-input transactions, so common-input does not apply. Exchanges give the pattern that works instead. Each customer receives a unique deposit address. The exchange then sweeps the funds, meaning it moves them from the deposit address into a hot wallet it controls.
If an address receives funds and sends nearly all of them to a known exchange wallet, repeatedly and to no one else, it is probably a deposit address of that exchange. The sketch below counts sweeps and requires a single destination.
from collections import Counter, defaultdict
def find_deposit_addresses(transfers, hot_wallet, min_sweeps=2):
"""transfers: dicts with 'from' and 'to'. Returns addresses that sent
to hot_wallet at least min_sweeps times and to nobody else."""
destinations = defaultdict(set)
sweeps = Counter()
for t in transfers:
destinations[t["from"]].add(t["to"])
if t["to"] == hot_wallet:
sweeps[t["from"]] += 1
return {
addr
for addr, n in sweeps.items()
if n >= min_sweeps and destinations[addr] == {hot_wallet}
}
transfers = [
{"from": "dep1", "to": "hot"}, {"from": "dep1", "to": "hot"},
{"from": "dep2", "to": "hot"},
{"from": "dep3", "to": "hot"}, {"from": "dep3", "to": "hot"},
{"from": "dep3", "to": "someone_else"},
]
print(sorted(find_deposit_addresses(transfers, "hot"))) # ['dep1']dep2 is excluded because it swept only once. dep3 is excluded because it also sent to another address. Raising min_sweeps trades recall for precision: you find fewer deposit addresses, and fewer of them are wrong.
Other signals
Some heuristics apply to either model but are weaker still:
- Shared funding: many fresh addresses receive their first gas or fee funds from the same source address.
- Timing and behavior: addresses that act in the same seconds, with the same fee settings or the same sequence of contract calls, may be driven by one program.
- Off-chain evidence: a public statement, a donation page, or a leaked address list. This is often the strongest evidence, but it is not on-chain.
How clustering fails
Because clusters grow by transitivity, one bad link merges two whole clusters. The common failure modes are these:
| Failure | What happens | Mitigation |
|---|---|---|
| CoinJoin | Many users co-sign one transaction, so unrelated inputs look like one owner | Skip transactions with many inputs and equal-value outputs |
| PayJoin | Sender and receiver both contribute inputs, so the heuristic links payer to payee | Hard to detect, so treat merges as probabilistic |
| Custodial batching | A service spends customer funds together, so one cluster covers many customers | Treat large clusters as services, not people |
| Wrong change link | Two unrelated clusters merge | Require several agreeing signals |
| Giant component | Repeated bad merges produce one cluster holding a large share of all addresses | Cap cluster size and audit the largest clusters |
Two errors have different costs. A false merge puts unrelated addresses into one entity, which inflates holdings and flows. A false split leaves one entity's addresses apart, which understates them. Exchange flow work usually prefers false splits, because a false merge can wrongly turn an ordinary user into "an exchange." Whale work often prefers the opposite, because whales hide by splitting.
Practical guidance
- Start from the highest-confidence evidence: official exchange disclosures, then deposit-sweep patterns, then common-input links.
- Record the heuristic that produced each link. A cluster should explain itself.
- Exclude known mixing transactions before clustering, not after.
- Re-run clustering when your data grows. New transactions can merge clusters you thought were final.
- Report confidence with each cluster instead of presenting every cluster as fact.
Exercise
Transaction 1 spends inputs from A and B. Transaction 2 spends inputs from C and D. Transaction 3 spends inputs from B and D. Using common-input ownership, what clusters result? Then suppose transaction 3 turns out to be a CoinJoin with many unrelated participants. What should you do, and why?
Show answer
Without any exclusion, transaction 1 merges A and B, transaction 2 merges C and D, and transaction 3 joins the two groups, so A, B, C, and D form one cluster. If transaction 3 is a CoinJoin, B and D do not share an owner, so that merge is false. Remove transaction 3 from the input list (or exclude it with a guard such as max_inputs) and rebuild. The result is two clusters: {A, B} and {C, D}. You must rebuild, because a union-find structure cannot split a merged group.
Exercise
Why does the deposit-sweep heuristic in this chapter require both a minimum number of sweeps and a single destination?
Show answer
A single sweep could be an ordinary user paying an exchange once, which proves nothing about control. Requiring several sweeps shows a repeated pattern. Requiring that the address sends only to the hot wallet rules out normal wallets that also pay other parties. Together the two conditions raise precision, at the cost of missing deposit addresses that were swept only once.