BitTorrent why use Merkle Tree for data integrity

458 Views Asked by At

Merkle hash torrent extension says naive way is to compute sha-1 hash for every chunk for data integrity. And using Merkle tree you know need the correct root sha-1 hash, so the peer calculate sha-1 hashes of each chunk from leaves for the root hash. I don't understand why you can't just use the sha-1 hash of the whole file for verification. Peers need to first combine the chunks to a file, and calculate sha-1 hash of that file to verify.

1

There are 1 best solutions below

0
user253751 On

If you have the whole file hash, you need the whole file to check that the hash is correct.

If you have a Merkle tree, then every time a peer sends you a chunk of the file, you can check that chunk, with only a little help from the peer. You can hash the chunk, and then go up the tree. At each tree node, you use the hash you have calculated so far, as well as the other hash from that node, which the peer sent to you because it knew you would do this. When you get to the root, if the root hash is the same as the expected one, you know the chunk is correct.