Mining

Photo by Simon Basler

The process by which consensus is achieved is described synonymous as mining. As in the real world, where mining is hard work, the connotation translates well into the meaning within a blockchain context.

Before we get into the nitty gritty details of how this process works, we will start with an overview of the flow of transactions. Let’s take Bitcoin for this example. The first step is to verify and subsequently bundle transactions during a certain amount of time (in Bitcoin’s case ~10 min) into a single block.

The nodes than all take part in a race to solve a cryptographic puzzle, this process is known as Proof of Work. If a node has found the right answer to the puzzle, they get the right to broadcast to the network, which then verifies the validity of the solution found and the transactions included. Once this is done, the block is cryptographically linked to the blocks before it — slowly growing into a chain of blocks.

After having looked at a high-level description of the process, we will explore the fascinating specifics of this ingenious marvel.

There are some concepts mentioned below, such as hashing and merkle trees, that have been covered in prior posts, therefore we will not get into them in too great detail — if you haven’t read them yet, feel free to do so here:

We will begin by looking at the way all of these blocks are constructed. Each block has a so-called block header, which consists of several components, such as the version of the software, the previous block hash, the merkle root, a timestamp, a difficulty target and a nonce.

The software version is used in order to keep track of changes or upgrades in the underlying protocol.

The previous block hash creates the chain of cryptographically linked blocks.

The merkle root is the all encompassing hash of the underlying merkle tree (explained in a prior post in depth).

The timestamp is counting the quantity of seconds that have passed since the first of January 1970. https://en.wikipedia.org/wiki/Unix_time

The difficulty target is an important part in the cryptographic puzzle and dictates, well, the difficulty.

Last but not least, the nonce, is used in the cryptographic puzzle as well.

For our little journey into Proof of Work, we will focus on the last two bits, difficulty target and nonce. The original idea behind this concept can be traced back to 1992, when Dr. Cynthia Dwork and Dr. Moni Naor published their research on how to combat junk-mail.

More commonly known is Adam Back’s hashcash though, which is covered in depth in the following post:

Hashcash was designed as a system to combat junk email. It does so by obliging the sender of an email to solve a little cryptographic puzzle, which requires some processing power and thus energy (that has to be paid for) to be solved. On a small scale for individual emails this does not matter too much, but in the case of spam, where potentially millions of emails are send, this suddenly incurs a very high energy bill.

Satoshi Nakamoto incorporated this idea into Bitcoin and directly credits Adam Back in his whitepaper “Bitcoin: A Peer-to-Peer Electronic Cash System”.

So what exactly is the place of this concept within some of the most widely used blockchains like Bitcoin and Ethereum?

Well, Proof of Work is the most commonly adopted consensus algorithm and is used both by those systems. It constitutes a cryptographic puzzle, which competing mining nodes try to solve.

In order for a competing mining node to win the right to broadcast their block into the network, the node needs to hash the block header repeatedly, changing one parameter at the time (the nonce we mentioned earlier). They continue doing this until the resulting hash output matches a predefined target, which is defined by the software in the block header.

By changing the nonce, the mining nodes need to use a lot of computational power to use brute-force in order to produce a hash that is less than the target. By setting a lower target, the computational power needed increases exponentially and it is thus more difficult to find. Since the probability of any possible outcome can be calculated in advance, is is possible to use an outcome of a specific difficulty as a proof of a specific amount of work.

Photo by Dominik Vanyi

But why would people willingly commit their computers to perform so many random guesses simply to solve a cryptographic puzzle?

Well, the incentive structure behind this idea is what truly makes Bitcoin and other blockchains so secure and ensures integrity! If your computer is the one to find a valid solution and the block is accepted by the other nodes into the chain of blocks, you get two rewards — Bitcoins and the fees that all the transactions incur.

Right now that would still amount up to 12.5 Bitcoins (even though this number is halving every 210.000 blocks), which would make you a nifty ~40.000 Euro — not too bad, heh?

As more and more people want to take part in this mining race (and thus the possibility to make some nice income), the total processing power increases — this is also called the total hash rate of the network. In order to ensure a steady production of new blocks (and therefore a steady process of minting new coins), the mining difficulty increases proportionally to the total hash rate of the network.

Using Proof of Work has the advantage that it makes it extremely costly for malicious actors to introduce false transactions or change the ledger, since they would need to be in control of a vast amount of the total processing power within the network.

Blockchains that use Proof of Work as their consensus mechanism always encourage the computers that form part of their respective system, to take the chain with the most Proof of Work as the valid chain.

For an in-depth look into both Bitcoin and Ethereum, I’d humbly recommend you to read these two posts:

Before we end this section, I’d love to highlight some of the different ways in which different blockchains enable computers to mine and therefore perform the Proofs of Work.

There are mainly five different ways which can be used to take part in the mining process:

CPU mining is utilising the Central Processing Unit of a computer, which is the “heart” of a computer, controlling instructions and the data flow inside a system.

GPU mining is using the Graphic Processor Unit (aka Graphic Card) to perform the required calculations.

ASIC mining is making use of specialized chips that were designed to calculate hashes with a very high throughout. It stands for Application Specific Integrated Circuits and is the most widely used way for mining on Bitcoin and Ethereum currently.

Mining pools bundle together the processing power of many individual computers and share the profits — for most people this is the most common and most effective way of taking part in the mining business.

Cloud Mining refers to the possibility of utilizing the services of a remote datacenter to take part in the mining process.

So far so good, before coming to an end of this post, we will briefly examine the limitations and problems surrounding Proof of Work.