My notes on the bitcoin blockchain

Ismail Akkila
3 min readDec 12, 2017

The bitcoin blockchain is essentially a data structure with an ordered back-linked list of blocks containing bitcoin transactions. At the moment, the average number of transactions per block is around 2000. Check it out here.

Each block within the blockchain is identified by a SHA256 cryptographic hash algorithm on the block header. The block references its parent using its block hash (SHA256 on the parent’s block header also). This results in a sequence of hashes linking each block to its parent that creates a chain all the way back to the first block ever created! The genesis block.

Block Structure

The block consists of a header, containing the metadata, followed by a long list of transactions that make up the majority of the size.

Block Header

Notice the “Previous Block Hash” field which links back to the parent block. The fields: difficulty, timestamp and nonce relate to mining which I hope to cover in a future post. The field merkle root is a data structure used to efficiently summarize transactions in a block.

It is important to note that full bitcoin nodes maintain a local copy of the blockchain, starting from the genesis block. As more blocks are added to this chain, the size grows larger. As of the current block height (498872), the size of the blockchain is approx 145GB. Check it out here.

Merkle Trees

Merkle trees are used to summarize the transactions in a block using a cryptographic hash, producing a digital fingerprint of the entire set of transactions. It provides an efficient process of verifying whether a transaction is included in the block. The tree is constructed by recursively hashing pairs of nodes until there is only one hash…the merkle root. Merkle trees are efficient because an element can be checked if it is included in the tree with at most 2*log~2~(N) calculations. It does not increase linearly with the number of elements or nodes in a tree.

So given a block with transactions. We can take transactions A and B and compute their hashes separately:

HA = SHA256(SHA256(Transaction A))
HB = SHA256(SHA256(Transaction B))

We can then concatenate these hashes to compute the following hash:

HAB = SHA256(SHA256(HA + HB))

The process continues until we arrive at the merkle root. This 32 byte hash is stored in the block header and summarizes all block transaction data.

With the merkle root, a merkle path can be used to verify if a transaction is inlcuded in the block. As the number of transactions in the block grows, we can rest assured that the complexity of this verification does not increase linearly. The table below shows the complexity involved where the path size (hashes) does not grow at the same rate as the number of transactions.

This makes merkle trees a suitable data structure to summarize our transactions especially in bitcoin SPV (simplified verification) nodes that do not download the full blockchain, but rather just the block headers. Such nodes can verify if a transaction is included in the block by determining the merkle path and arriving at the merkle root which is included in the block header.

--

--

Ismail Akkila

I live and breathe technology. Curious about programming, bitcoin and cybersecurity.