Bitcoin is based on the blockchain, everyone knows that. But what is this blockchain? More precisely, how can one imagine the individual components of the blockchain, the blocks?
The blockchain is a chain of data blocks. Each block can be thought of as a page in a ledger. The individual blocks are composed of several components. Roughly these can be differentiated into the head of the block (block header) and his body (block body).
The head of the block is divided into six components:
- the version number of the software
- the hash of the previous block
- the root hash of the Merkle tree
- the time in seconds since 1970–01–01 T00: 00 UTC
- the goal of the current difficulty
- the nonce
The version number of the software
The software version number does not matter in most cases. However, a miner with a particular version number can signal which protocol decisions he supports.
The hash of the previous block
The hash of the previous block is, so to speak, the chain of blockchains. Because the hash of the previous block is contained in the hash of the new block, the blocks of the blockchain all build on each other. Without this component, there would be no connection and chronology between each block.
The root hash of the Merkle tree
All transactions contained in a block can be aggregated in a hash. This is the root hash of the Merkle tree.
The time in seconds since 1970–01–01 T00: 00 UTC
A timestamp in the block itself. The time is given in seconds since 1.1.1970.
The goal of the current difficulty
The goal indicates how small the new hash must be to claim validity. In other words, every hash has a size in bits. The lower the goal in bits is, the harder it is to find a matching hash. A hash with many zeros at the beginning is smaller than a hash without zeros. Find out more about the difficulty of the proof of work.
The nonce is the variable incremented by the proof of work. In this way, the miner guesses a valid hash, a hash that is smaller than the target.
The six components form the block header. The block header plays a fundamental role in Bitcoin because it connects all blocks together. You can imagine it like the cockpit of a truck. Here are the important papers with which the truck comes through the controls of the network.
The block body is conceivable as the loading space of a truck. It contains all transactions that are confirmed with the block.
When a miner constructs a block, it validates the transactions. That is, he checks that the sender actually has enough money to spend. He can easily read this information from the blockchain. The miner looks in the past blocks to see if the sender has even gotten ten Bitcoins if he wants to send ten Bitcoins.
The transactions in a block are not just in a list, but in a so-called Merkle Tree.
What is a Merkle Tree?
The Merkle Tree takes its name from the mathematician Ralph Merkle. The discovery was that much information can be represented in a single hash. For this, the data itself is first hashed. Then the hashes are hashed again and merged. Finally, the Merkle Tree is merged into a single hash. This last hash is also called root hash, the root of the tree. It represents all the information of its “leaves” (individual transactions) and “branches” (hashes of the leaves) in a relatively short string.
Creating the root hash is quick and easy, as long as all branches and leaves are known. We remember the function of a hash function: it works clearly and quickly in one direction and is impossible to break down in the other direction. If the root hash is known, but the transactions are unknown, it is impossible to guess the transactions.
A root hash alone is therefore not enough, and the rest of the block must be saved. Thus, the miner can validate the root hash at any time by hashing the information contained in the block again. As long as the hash function is the same, the miners always get the same hash for a given input of data. This is very handy because they can only check if they are on the same level as the hash.
Mining: The search for a special hash
In this context, it is easier to understand the mining of the proof of work. When mining, the block header of the block is incrementally changed to get a special hash. The header consists of five constants and one variable. The constants are the version number of the software, the hash of the previous block, the root hash of the Merkle tree, the timestamp, and the target size of the searched hash in bytes.
The variable is the nonce. A nonce is a number raised by one. Then the miner hashes the data and checks if the data results in a hash that is below the searched target value. If the hash value is greater than the target, the miner repeats the process; So it increases the nonce by one, hashes and checks again. It repeats this until it finds a hash below the target, or it gets another block from another networker whose hash is below the target. Then takes this new block and uses it as the basis for the next block (using the new hash as the “hash of the previous block”).
Mining is a hyper-repetitive process whose goal is to find a special hash. Once the hash is found, the game starts again. The probability of finding a special hash depends on the difficulty. On average Bitcoin finds a new block every ten minutes. The difficulty keeps adapting, so this average stays the same.
The special feature of this process is that the special hash can only be found by guessing. This rate costs computing power and therefore energy. A look at the special hash is enough to see that it is special because it begins with zeros.
Here is an example of such a hash from the Bitcoin blockchain:
Hashes: The matryoshka of the blockchain
A block can be simplified as a matryoshka imagine. The smallest doll is the unhashed transaction. The next envelope is the hashed form of this transaction. Thereafter, two hashed transactions are hashed together. So the hashes are merged more and more. In the end, there is only one hash remaining, the root hash, or the biggest matryoshka.
Author: Marko Vidrih
@cryptomarks (@VidrihMarko) | Twitter
Image via Pixabay
What Is a Block in the Blockchain? was originally published in Data Driven Investor on Medium, where people are continuing the conversation by highlighting and responding to this story.