bitcoin-transaction-network-2009-2013 / docs /DATA_AND_PROCESSING.md
FelNeg's picture
Upload folder using huggingface_hub
0014210 verified
|
Raw History Blame Contribute Delete
18.8 kB

Bitcoin transaction network — data & processing documentation

Window: 2009-01-03 → 2013-01-08 (the exact window of Aspembitova, Feng, Melnikov & Chew, Fitness preferential attachment as a driving mechanism in bitcoin transaction network, PLoS ONE 14(8): e0219346, 2019).

What it is: a cluster-level and address-level transaction network (edge lists) built from the raw Bitcoin blockchain by porting and running the paper's own extraction pipeline, with every stage validated against independent counts. Everything here is derived from public chain data.

Generated: 2026-10-03. Manifest with sha256 checksums: docs/data_manifest.json.


1. Quick start (this is all most analyses need)

import duckdb
ROOT = "<path-to>/bitcoin-network"

# The network: one row per transaction output
edges = duckdb.sql(f"""
  SELECT * FROM read_csv('{ROOT}/runs/full_window/out/user_edges.txt', header=false,
    columns={{'tx':'BIGINT','u_from':'BIGINT','u_to':'BIGINT','date':'VARCHAR','value_btc':'DOUBLE'}})
""")
# 25,356,719 edges over 4,910,855 clusters, 2009-01-03 .. 2013-01-08.
# `date` is YYYYMMDDHHMMSS. `u_from == u_to` marks a self-loop (coinbase / internal transfer).

# Cluster sizes and members
sizes = duckdb.sql(f"SELECT * FROM read_parquet('{ROOT}/runs/full_window/out/clsize.parquet')")
pk_of_cluster = duckdb.sql(f"SELECT * FROM read_parquet('{ROOT}/runs/full_window/out/pk_user.parquet')")

If you only take one file, take user_edges.txt plus clsize.parquet.


2. Provenance

item source
raw chain AWS Open Data, https://aws-public-blockchain.s3.us-east-2.amazonaws.com/v1.0/btc/transactions/date=YYYY-MM-DD/ (public, no credentials, decoded per-day parquet)
extraction code github.com/ivanbrugere/Bitcoin-Transaction-Network-Extraction (Python 2, 2013); ported to Python 3 in code/btc_py3/ with the algorithm unchanged so results stay comparable to the paper
paper's own dataset https://dynamics.cs.washington.edu/nobackup/bitcoin/bitcoin.tar.gz (679 MB, GraphLab SFrame; aggregated pairs only)
partition loader scripts/download_parquet_days.py
parquet → extraction text scripts/gen_transactions_txt.py

Downloaded for this work: 1,462 daily partitions, 15.06 GB (data/parquet/, not redistributed — re-downloadable in ~17 min at ~14.6 MB/s with the script above).


3. Directory layout

bitcoin-network/
├── data/
│   ├── parquet/            1,462 daily partitions, 15 GB   (raw source, re-downloadable)
│   ├── raw/                7.5 GB  extraction input text (7.4 GB) + 2010 test slice
│   └── bitcoin/            the paper's own tarball, decoded (aggregated pairs)
├── runs/
│   ├── full_window/        4.6 GB  ← THE DELIVERABLE (see §4)
│   │   ├── out/            all edge lists, maps and flags
│   │   └── step3/          cluster assignments (.npy)
│   └── 2010_window/        small validation run (2009-2010 slice)
├── code/btc_py3/           the Python 3 port of the extraction pipeline
├── scripts/                generators, runners, analysis
└── docs/
    ├── DATA_AND_PROCESSING.md   ← this file
    ├── data_manifest.json       sizes + sha256 for every artifact
    ├── data_processing_findings.md   chronological working record, all measurements
    └── clustering_best_practice.md  clustering methodology + literature + measured comparisons

4. File inventory

All paths relative to the repository root. Sizes and row counts are from docs/data_manifest.json (regenerate with scripts/analysis/inventory.py).

4.1 The networks

file size rows what it holds
runs/full_window/out/user_edges.txt 1.0 GB 25,356,719 cluster-level network: tx_id, u_from, u_to, date, value_btc; one row per output
runs/full_window/out/addr_edges.parquet 1.1 GB 25,356,719 address-level network + change-detection flags: tx_id, txid, sender_pk, dst_pk, value, ts, oidx, n_in, n_out, fresh_any, fresh_out, n_fresh_any, n_fresh_out

user_edges.txt is the primary object: 25,356,719 edges, 10,886,588 transactions, 4,910,855 clusters, 5,878,290 self-loops (23.18%), span 20090103181505 → 20130108235206.

4.2 Id maps (read §5 before joining anything)

file size rows mapping
out/pubkey_list.txt 314 MB 8,906,547 line → identity string ("(None)" first)
out/pk_map.parquet 251 MB 8,906,547 pk_id → ident
out/userkey_list.txt 67 MB 4,910,855 line = one cluster, listing its pubkey ids
out/pk_user.parquet 32 MB 8,906,547 pk_id → cluster id u (the clustering)
out/clsize.parquet 5 MB 4,910,855 u → n_pk (addresses per cluster)
out/transactionkey_list.txt 675 MB 10,886,588 line → txid
out/tx_map.parquet 378 MB 10,886,588 tx_id → txid

4.3 Clustering inputs, flags and results

file size rows what it holds
out/user_edge_input_public_keys.txt 223 MB 10,670,810 per tx: its input pubkey ids — the re-clustering handle
out/user_edge_inputs.txt 248 MB 10,670,810 per tx: its input values in satoshi (NOT ids — see §5)
out/pairs.parquet 73 MB 22,030,699 exploded (tx_id, pk_id) input pairs
out/change_pairs.parquet 58 MB 3,727,704 change-address candidates tx_id, change_pk, sender_pk, value, n_out, n_in, rule
out/coinjoin_flags.parquet 163 KB 28,470 CoinJoin-like txs (≥3 in, ≥3 out, repeated output value)
out/collapse_events.parquet 2.9 KB 96 merges absorbing ≥1,000 new pubkeys (collapse diagnostic)
out/variant_stats.parquet 1.8 KB 5 headline statistics per variant/level
step3/clusters_h1.npy, clusters_h2.npy 34 MB each 8,906,548 int32 cluster label per pk_id for the unguarded change variants — see the caveat in §8

clsize.tsv (46 MB) is the TSV twin of clsize.parquet, kept because it carries an order-preserving index.


5. The three id spaces (critical — read before joining)

Verified directly against the 2013 source code:

space rule trap
cluster id (u in user_edges.txt) assigned 1,2,3,… in write order → userkey_list.txt line k is cluster k must parse the file in order; a SQL row_number() over a parallel CSV read is not a file ordinal
tx_id t_id starts at 1 and increments densely → transactionkey_list.txt line k is tx k for an in line the referent txid is indexed before the own txid, so ids follow that order
pk_id "(None)"=0, then 2,3,4,… → pubkey_list.txt line 0 → id 0, line k≥1 → id k+1 pk id 1 is never used (an off-by-one in the original). Indexing by line number shifts every id by one and silently corrupts every pk→cluster lookup

And one file-name trap: user_edge_inputs.txt holds values in satoshi, not ids. It is the per-input amount (row[5], later scaled by 1e-9), so joining it as if it were identifier data produces plausible-looking nonsense. The identifier file is user_edge_input_public_keys.txt.


6. Processing pipeline, step by step

Each step is a script in scripts/, runnable end-to-end. Heavy steps run inside Docker (scripts/run_step*_docker.sh) because they need more than the 4 GB that an agent-runtime background job is capped at; the container gets its own cgroup.

Step 0 — download (17 min, 15.06 GB)

python3 scripts/download_parquet_days.py 2009-01-03 2013-01-08 → 1,462 day-partitions. Verified: 0 unreadable, schema clean for 2011–2013.

Step 1 — parquet → extraction text (2 min 54 s, 7.9 GB, peak RSS 25 GB)

python3 scripts/gen_transactions_txt.py data/parquet/ data/raw/transactions_2009_2013.txt → 47,387,418 rows (22,030,699 in + 25,356,719 out), 7 space-separated fields:

in  <own_txid> <spent_txid> <spent_out_idx> <pk> <iso_ts> <sortkey>
out <own_txid> <out_idx> <pk> <value_btc> <iso_ts> <sortkey>

Two non-obvious requirements (both silently corrupt results if changed): the timestamp must be a single whitespace-free token of ≥19 chars with an ISO T (the parser slices fixed positions), and coinbase transactions emit only their out rows (which is what turns mining rewards into self-loops downstream). Pay-to-pubkey outputs have no address in the ETL, so the output pubkey is recovered from script_hex, and P2PK spends (which store only a signature) are resolved by back-joining (spent_transaction_hash, spent_output_index).

Step 2 — extraction (10 minutes, Docker)

bash scripts/run_full_window_docker.sh Runs the ported pipeline: dictionaries → fix_missing_public_keys → clustering (write_user_public_keys) → edge writing (write_user_edges). → runs/full_window/out/ : user_edges.txt, userkey_list.txt, pubkey_list.txt, transactionkey_list.txt, user_edge_input*.txt.

Step 3 — address-level layer + freshness (2 minutes, Docker)

bash scripts/run_step2_docker.sh → scripts/step2_build_address_edges.py Rebuilds address-level edges from the raw text with the pipeline's own sender rule (rows sorted (tx, io, idx) ⇒ the sender is the last input; a coinbase's sender is its first output) and computes per-output freshness flags.

End-to-end validation (this is the important one): mapping the reconstructed edges through identity → pk_id → cluster_id and grouping by (tx, from, dst) gives 25,356,719 edges in 24,383,640 groups — identical to the pipeline's own user_edges.txt, with identical hash sums (224917165203570464631041835 on both sides). The address-level layer is therefore provably faithful, not merely plausible.

Step 4 — change heuristics, re-clustering, flags (3 minutes, Docker)

bash scripts/run_step3_docker.sh → scripts/step3_change_heuristics.py

  • H1 (Meiklejohn et al. 2013): 3,727,704 transactions; of those, 2,353,768 also satisfy the stricter H2 (Ermilov et al. 2017) conditions
  • 1,619,208 transactions excluded as self-change
  • CoinJoin-like flags: 28,470
  • collapse diagnostic: 96 merges absorbing ≥1,000 new pubkeys
  • re-clustered variants: co-spend+H1 (4,910,855 → 2,561,952 clusters) and co-spend+H2 (→ 3,380,393)

Step 5 — variant statistics (1 minute, Docker)

bash scripts/run_step4_docker.sh → scripts/step4_variant_statistics.py → variant_stats.parquet Computes nodes/edges/degree/component statistics at both granularities for the co-spend baseline, the size-guarded change variant, and the hubs-removed variant.

Analysis scripts (read-only, run on the host)

scripts/analysis/: merge_profile.py, clustering_policies.py (policy sweep), collapse_trace.py, exchange_removal.py / service_removal_degree.py (removal sensitivity), compare_table2.py (paper comparison), inventory.py, make_manifest.py.


7. Measured results (headline)

Full detail in docs/clustering_best_practice.md.

Scale: 25,356,719 edges · 10,886,588 transactions · 4,910,855 clusters · 8,906,547 pubkeys · 23.18% self-loops.

Independent validation: distinct transactions (10,886,588) match blockchain.com's independent daily series for 2011–2012 (10.4M) within 5%; edge count equals the generator's output-row count exactly; the reconstruction check in §6 reproduces the pipeline byte-for-byte.

Versus the paper's Table 2: 2P nodes match to +2.4% (4,803,046 vs 4,689,069) and global scale matches (25.4M vs ">25M" links). But their two periods use inconsistent link definitions (their 2P number matches aggregated distinct pairs, their 1P number matches per-output edges), so their 1P column cannot be reproduced from their own published dataset.

Clustering methods, measured:

  • The naive change-address heuristic collapses the network: the giant cluster goes from 261,808 to 3,315,509 addresses (37% of all addresses) and the cluster count halves.
  • A size-guarded variant (refuse any merge above 10^4 addresses) applies 2,136,864 change merges (clusters −43%) while leaving the giant cluster bit-identical to baseline. Recommended policy.
  • The degree tail is robust to the clustering choice: Hill tail slope ≈ 2.0 across address-level (2.22), co-spend (2.00), guarded-change (1.99) and hubs-removed (1.99).

Two classes of giant node: whales by address count (cluster 232: 261,808 addresses — the Mt. Gox-shaped object whose 2012 consolidation burst we traced) versus high-frequency nodes (cluster 213: 1,090 addresses but 4.9M edges; cluster 235: 3 addresses and 615k edges, 97.3% self-loops — the SatoshiDICE pattern).


8. Caveats and limitations (please carry these into any analysis)

  1. Clustering ≠ identities. A "cluster" is a set of addresses linked by co-spend evidence. It is an upper bound on co-ownership, not ground truth. 89.6% of clusters are singletons.
  2. Self-loops (23.18%) come from coinbase and internal transfers. Keep/drop changes the degree distribution; state the choice. They are excluded from variant_stats.parquet degrees.
  3. The (None) bucket is one small cluster (373 pubkeys) holding outputs whose identity cannot be resolved. Left as a node.
  4. Temporal resolution is the block, not the second. Timestamps are miner-set. Freshness flags are ordered by (timestamp, txid) because this text dump carries no block number — a documented approximation.
  5. clusters_h1.npy / clusters_h2.npy are the COLLAPSED variants. Do not use them for network analysis without the guard described in §7. The baseline clustering is pk_user.parquet.
  6. The 261,808-address cluster is probably — not certainly — Mt. Gox. It contains the May–June 2012 consolidation burst and matches Ron & Shamir's 2012 entity scale, but entity attribution has not been performed. Do not publish it as an identified entity without that step.
  7. Hill tail slopes are crude (fixed d_min = 100, no lognormal comparison). A defensible power-law claim needs MLE plus a likelihood-ratio test.
  8. The extraction does not scale past this window. The ported pipeline is in-memory (155 bytes/row); the modern corpus (1.5B transactions) needs a streaming rewrite.

9. Reproducing / verifying

# 1. verify your copy against the manifest
python3 - <<'PY'
import json, hashlib, os
m = json.load(open("docs/data_manifest.json"))
for e in m["files"]:
    h = hashlib.sha256(open(e["path"], "rb").read()).hexdigest()
    print("OK " if h == e["sha256"] else "MISMATCH ", e["path"])
PY

# 2. rebuild everything from the raw chain (needs ~40 GB RAM for step 1, Docker for steps 2-5)
python3 scripts/download_parquet_days.py 2009-01-03 2013-01-08
python3 scripts/gen_transactions_txt.py data/parquet/ data/raw/transactions_2009_2013.txt
bash scripts/run_full_window_docker.sh
bash scripts/run_step2_docker.sh      # address-level layer + validation
bash scripts/run_step3_docker.sh      # change heuristics, flags, collapse events
bash scripts/run_step4_docker.sh      # variant statistics

Environment: Python 3 with duckdb, numpy, scipy (a Docker image carrying DuckDB and scipy is used for heavy steps; inside the container duckdb is installed with pip install --break-system-packages duckdb).


10. Sharing guidance

To share everything: the runs/full_window/ tree (4.6 GB) plus code/, scripts/, docs/ (11 MB). The two large text files (user_edges.txt 1.0 GB, addr_edges.parquet 1.1 GB) dominate.

Measured bundle options:

bundle contents size
minimum (network only) user_edges.txt + clsize.parquet 1.1 GB
+ re-clustering the above + userkey_list.txt + user_edge_input_public_keys.txt + pk_map.parquet 1.6 GB
full deliverable runs/full_window/ + code/ + scripts/ + docs/ 4.6 GB

The small analysis outputs (variant_stats, collapse_events, coinjoin_flags, change_pairs, pk_user, tx_map) together add well under 500 MB and are worth including in any bundle.

What is shared where. A single deposit: the Hugging Face repository (FelNeg/bitcoin-transaction-network-2009-2013, private). It carries the processed networks (runs/full_window/), the pipeline (code/, scripts/), these docs, and the extraction's input layer, data/raw/transactions_2009_2013.txt (7.9 GB) — the unclustered per-input/output records, so a collaborator can apply their own clustering instead of inheriting ours. Verify any copy with scripts/verify_hf_upload.py.

Not sent anywhere: data/parquet/ (15 GB) — publicly re-downloadable with the scripts in under 30 minutes — and data/raw/transactions_2010_clean.txt (77 MB), an early 2010-window scoping byproduct that is superseded by the full-window dump. data/bitcoin/ is the paper's own dataset, also public.

Suggested transfer: archive with checksums and let the recipient verify against the manifest:

tar --exclude='data/parquet' --exclude='data/raw' -czf btc-network-2009-2013.tar.gz \
    runs/full_window code scripts docs
sha256sum btc-network-2009-2013.tar.gz > btc-network-2009-2013.tar.gz.sha256

Version control — read this before reaching for git. git rev-parse --show-toplevel from this project resolves to the parent research directory with zero commits, no .gitignore, and 443 GB of contents: several unrelated projects, model checkpoints, figures, plus the 15 GB data/parquet and 7.5 GB data/raw trees. A git add . there would be destructive, and a push would leak unrelated work or simply fail. Use the tar bundle above for sharing.

If a GitHub hand-off is wanted instead, it needs to be set up deliberately, not by pushing this tree: create a dedicated repository for this project, add a .gitignore that excludes data/, runs/**/*.parquet, runs/**/*.npy, .duckdb_tmp/, __pycache__/, and ship the large artifacts as release assets or via the tar.


11. Responsible use

All underlying data is public chain data. However, address clustering is a re-identification technique: even without names, a cluster label can point at a real entity, and the largest clusters in this dataset are very likely identifiable services. For publication, prefer aggregates and distributions; if individual cluster labels are shared, treat the "likely Mt. Gox / likely exchange" attributions as unverified hypotheses, and state the clustering policy and its caveats (§8) in any write-up.