BitTorrent v2: Extract and Verify Individual Files
BitTorrent v2 fundamentally changes how multi-file torrents are structured by transitioning from a single global piece hash list to per-file Merkle hash trees using SHA-256. This architecture treats every file in a torrent as an isolated cryptographic unit rather than merging all files into one continuous byte stream. As a result, users can selectively download, validate, and extract single files from a multi-file collection without needing data or boundary padding from adjacent files.
The Architectural Flaw of BitTorrent v1
In the original BitTorrent specification (v1), a multi-file torrent concatenated all files into a single, continuous stream of data. This stream was divided into fixed-size pieces (such as 1 MB or 2 MB), and each piece was hashed using SHA-1.
Because files were placed end-to-end without strict alignment, piece boundaries frequently overlapped multiple files. The end of one file and the beginning of another often shared the same piece. Consequently, downloading a single file required downloading the shared boundary pieces of adjacent files. Furthermore, an individual file could not be cryptographically verified on its own; verification depended entirely on the hash of the shared piece within the context of the entire torrent.
Per-File Merkle Trees
BitTorrent v2 resolves this limitation by generating an independent Merkle hash tree for every individual file in the torrent:
- Standardized Block Size: Each file is broken down into small 16 KiB blocks.
- Leaf Hashes: A SHA-256 hash is computed for each 16 KiB block, forming the leaves of the tree.
- Tree Construction: Adjacent hashes are concatenated and hashed in pairs recursively until reaching a single root hash (the “Merkle root”).
Because each file generates its own discrete Merkle tree, file boundaries are absolute. No tree or piece ever spans across two distinct files.
Cryptographic Verification via Root Hashes
The root hash of a file’s Merkle tree serves as its unique, global
identifier within the .torrent metadata (or magnet link).
When a client selects a single file to download:
- Hash Path Requests: The client requests the necessary intermediate hashes (the Merkle path) from peers to reconstruct the branch from the target blocks up to the known Merkle root.
- Immediate Block Validation: As each 16 KiB block arrives, the client verifies it against the Merkle tree path immediately.
- Self-Contained Integrity: If the recalculated root matches the root hash listed in the torrent metadata, the block is verified.
This verification process does not require hashes, data, or parity from any other file in the torrent payload.
Cross-Swarm Deduplication and Extraction
Because the root hash is calculated solely from the contents of the individual file, identical files produce identical root hashes regardless of the torrent they belong to.
This allows a BitTorrent v2 client to extract an individual file directly, verify it against its isolated root hash, and even seed or download that identical file across entirely different torrents or swarms. Once the file’s specific Merkle tree is complete, the file is fully verified and ready for immediate use.