fbpx
Reading Time: 2 minutes

Merkle Tree

Merkle trees are hash-based data structures that make it easier to process large amounts of data. For Bitcoin, Merkle trees are an efficient way to protect transaction data that is less demanding on resources but still heavily encrypted.

How do they work?

As transactions are added to the block, each one is hashed. But in the interest of efficiency, the Bitcoin software will concatenate pairs of transactions into one combined hash. Then, these two combined hashes will be hashed and concatenated again, over and over again until they finally gain one single hash that represents the entire block, the Merkle root

Blocks can have hundreds of transactions per block, but let’s look at a simple 4 transaction block above. Transactions L1, L2, L3, and L4 all receive a hash, Hash 0-0, Hash 0-1, Hash 1-0, and Hash 1-1 respectively. Then, the Bitcoin software concatenates Hash 0-0 and Hash 0-1 to make Hash 0 – a hash of the two transactions – and Hash 1-0 and Hash 1-1 to make Hash 1. Now there are only two hashes left, Hash 0 and Hash 1, which concatenate into the Top Hash – the Merkle Root – which represents all the transactions in the block with one relational hash.

The bottom parts of the Merkle Tree, the individual transactions, are often referred to as “leaves” and the intermediate hashes, “branches.”

Note: If there are an uneven amount of hashes in the block, then the Bitcoin software will create two hashes for the odd numbered transaction so that the Merkle tree can continue.

Links