BitTorrent v2 File Hierarchy and Updates
BitTorrent v2 introduces a tree-based architecture powered by SHA-256 Merkle trees that isolates each file into its own cryptographic structure. Unlike the legacy BitTorrent v1 protocol, where all files in a multi-file torrent are merged into a single continuous byte stream, BitTorrent v2 treats every file independently. This design allows individual files to be modified, updated, or verified without corrupting the integrity hashes or requiring redownloads of the remaining unchanged files.
The Limitation of BitTorrent v1
In BitTorrent v1, a multi-file torrent concatenates all files together in order. The data is then sliced into uniform pieces (such as 1 MB or 2 MB blocks), each assigned a SHA-1 hash.
Because files are rarely an exact multiple of the piece size, the end of one file and the beginning of the next frequently share the same piece. Consequently, altering, adding, or removing a single file shifts byte offsets and changes the piece hashes across the entire payload, invalidating the data for every subsequent file in the swarm.
Per-File Merkle Trees in BitTorrent v2
BitTorrent v2 solves this issue by aligning every file to block boundaries and assigning each file its own Merkle tree:
- Independent Block Hashing: Each file is divided into standardized 16 KiB blocks. Each block is hashed using SHA-256 to create the “leaf nodes” of that file’s Merkle tree.
- Merkle Root Generation: Adjacent leaf hashes are repeatedly hashed together in pairs moving upward until a single cryptographic root—the “file root hash”—is produced for that specific file.
- Padded Alignment: Files are naturally piece-aligned within their respective trees. No piece or block ever spans across the boundary of two different files.
Why Modifying One File Does Not Invalidate Others
Because each file exists within its own isolated Merkle tree, changes to file contents remain strictly localized:
- Isolated Hash Changes: If File A is edited, only the leaf nodes, intermediate branches, and Merkle root corresponding to File A are altered.
- Preserved Integrity of Unmodified Files: The Merkle roots for File B, File C, and all other files remain completely identical.
- Granular Swarm Verification: BitTorrent v2 clients identify identical files across different torrents or updated revisions by comparing their root hashes. If a torrent is updated with a revised version of one file, clients can instantly verify that the other files are untouched, bypassing the need to re-check or re-download the rest of the dataset.
This cryptographic separation allows modern BitTorrent swarms to support file-level deduplication, selective updates, and efficient version control across multi-file datasets.