Why Changing a File Breaks BitTorrent v1 Swarms

In the BitTorrent v1 protocol, any modification to a torrent’s files—whether editing content, renaming a file, or changing the directory structure—fundamentally changes the global info_hash. This happens because BitTorrent v1 treats all files in a multi-file torrent as a single continuous byte stream and calculates the info_hash from the metadata of that entire structure. Because peers and trackers rely exclusively on this hash to locate one another, altering even a single byte separates the modified torrent into an isolated swarm, completely breaking compatibility with existing seeders and leechers.

The Info Dictionary and the Info Hash

A standard .torrent file is encoded using Bencode, a lightweight serialization format. Inside this file lies the info dictionary, which defines the content payload of the transfer. This dictionary includes parameters such as:

The global identifier for any torrent—known as the info_hash—is generated by taking the cryptographic SHA-1 hash of the raw, Bencoded info dictionary. Because it is a cryptographic hash, any modification to the data inside the info dictionary triggers the avalanche effect, producing a completely different 20-byte hash.

The Continuous Byte Stream Model

Unlike modern file synchronization tools or BitTorrent v2, BitTorrent v1 does not maintain a per-file hash tree (Merkle tree). Instead, it serializes all files in the torrent sequentially into one continuous virtual stream of data.

This virtual stream is sliced into uniform pieces based on the specified piece length. Consequently:

  1. Shared Boundaries: A single piece frequently contains the trailing bytes of one file and the leading bytes of the next file.
  2. Cascading Shifts: Changing the size of a single file shifts the offsets of all subsequent files in the virtual stream. This invalidates the piece boundaries and changes the SHA-1 hash of every piece downstream from that file.
  3. Content Alterations: Even if the file size remains identical, altering its content changes the hashes of the pieces spanning that file, which updates the pieces string inside the info dictionary.

Metadata Sensitivity

The info_hash is not only sensitive to the binary content of the files, but also to the file metadata. If you modify a file’s name, add a file, delete a file, or alter the directory path, the text inside the Bencoded info dictionary changes. Even if the actual data payloads remain identical, the modified text produces a completely different SHA-1 digest for the info dictionary itself.

Swarm Isolation

BitTorrent swarms operate on exact hash matching:

Because the modified file alters the info dictionary, the resulting info_hash changes entirely. The client announces a unique identifier that no other peer in the original swarm recognizes, effectively creating an empty, separate swarm with zero connectivity to the original seeders.