Understanding Proof-of-Work, Part 1: Demystifying Solving a Block

Julian Roberto
6 min readMay 1, 2018

--

2018 will be a challenging year for blockchain technology. Several Ethereum projects are expected to go live this year and these projects will push the limits of what smart contracts can achieve on proof-of-work style blockchains. CryptoKitties alone congested Ethereum for over a week and, at its current capacity, it is unlikely that Ethereum will be able to handle multiple popular dApps simultaneously.

Ethereum’s long-term solution to scaling is to enable sharding after upgrading to proof-of-stake but there are also many other alternative consensus mechanisms that claim to scale better, such as delegated-proof-of-stake and directed acyclic graphs (DAGs). In order to better understand scaling and the future of cryptocurrency, my latest series will break down these consensus mechanisms starting with proof-of-work.

Miners Have to Pay to Play

Consensus mechanisms all share a common goal: securing a decentralized database by properly incentivizing participants in the network. This means financially rewarding participants that facilitate the goals of the network and making attackers waste money when they attack the network. The differences in consensus mechanisms start to emerge when we look at how they defend their networks from attackers while maintaining a certain level of transaction speed for their users.

First we will analyze proof-of-work blockchains and use Bitcoin as an example. It is called proof-of-work because, before a miner can update the network with new transactions, they need to prove they have skin in the game. The “work” they need to do in order to prove that they have skin in the game is solve puzzles that take a ridiculously large amount of processing power to complete. These puzzles also cost lots of money to solve because large amounts of processing power consumes lots of electricity.

The reason miners are willing to waste this electricity is because, if they follow the rules of the Bitcoin network, they will be able to recover the money they spend on electricity and make profit in the process. They make this profit through newly minted Bitcoins.

The reason proof-of-work makes it intentionally expensive for miners to participate is because proof-of-work also makes it expensive for a malicious miner to attack the network. The difference is that proof-of-work doesn’t pay attackers. If a miner attempts to attack the network, they still have to consume lots of electricity, but they will have no way to pay that electricity off.

What Does Solving a Block Really Look Like?

Before we discuss how proof-of-work forces miners to consume lots of electricity, let’s first understand the things that miners do that are not energy intensive. When a miner verifies transactions, organizes these transactions into a block and distributes completed blocks (already solved) throughout the network, this happens very quickly and is not energy intensive. What is energy intensive is the “lottery system” or “puzzle” that miners need to solve in order to create a valid block.

In order to make a block artificially difficult to solve and energy intensive for a miner, the hash of the solved block has to meet certain conditions. Although hashes are usually only thought of as digital fingerprints, the hash of a block can also represent a numerical value. In order to correctly solve a block, miners have to manipulate the hash of a potential block until that hash is below a certain numerical value. That numerical value is called a target hash.

This is summary information of Bitcoin’s genesis block. The target hash is circled in green. This value is truncated (compacted) and in hexadecimal form. This data is truncated to conserve space on the blockchain. Source: https://www.smartbit.com.au/block/0

How Do You Manipulate the Hash of a Block?

At the moment you might be confused, and for good reason. Every file has only one hash, also known as a digital fingerprint. The only way to modify the hash of a specific file is to modify the contents of that file. So how does a miner modify the hash of a block they are solving? They modify the contents of the block.

In order to manipulate a block’s hash so that it falls under the target hash, miners include a random number within their block called a nonce. A nonce is a “number used once.” When you hear “solving a block” described as a puzzle or lottery system, it is because of the nonce. The puzzle is solved and the lottery is won when the correct nonce is discovered. In order to find the correct nonce, miners repeatedly choose a nonce, include it in the contents of the block, hash the block and see if the hash falls below the target hash.

If the hash of the block does not fall below the target hash, miners pick a new nonce until they find one that succeeds.

This is the hash of my name. Hash your name here.
The hash of my name and a nonce is circled in red. Notice how it is different than just the hash of just my name.
This is a recent Bitcoin block. This block was accepted by the bitcoin network because the the block hash, circled in the top right, fell below the target hash. The nonce, circled in the bottom left, was essential for meeting the target hash.

Once the block is solved, the miner broadcasts the block to the entire network. The entire network checks that the block is correct by rehashing the block to see if it falls below the target hash. If it does, then the block is accepted by the entire network, the miner that solves the block receives newly minted Bitcoin and transactions fees, and miners start trying to solve for the next block.

Putting the Puzzle into Perspective: Hash Rate and Electricity

The computing power and security of the Bitcoin network is measured by the amount of hashes per second miners collectively make in the entire network. Hashes per second is formally known as the hash rate. As of the writing of this article, the network’s hash rate is 30,345,703 TH/s (trillion hashes per second). This is 30,345,703,000,000,000,000 hashes per second! That is a lot of hashes.

The only way for a miner to increase their chances of solving a block is to increase their hash rate or hash power, which also requires spending more money on equipment and electricity. Proof-of-work is elegant in this way because if you have a greater influence over the network, you also have more to lose if you try and tamper with the network and fail.

This graph is tracking Bitcoins hash rate over the last year.

It is hard to measure the exact amount of energy that the entire Bitcoin network consumes because, depending on the type of mining equipment you own, you can get more hash power per unit of electricity. Estimates of how much electricity Bitcoin consumes vary widely but sources seem to agree that Bitcoin consumes at least as much electricity as small countries.

Adjusting the Difficulty aka the Target Hash

As more miners join the Bitcoin network, blocks start getting discovered faster. In order to consistently find 1 block every 10 minutes, Bitcoin adjusts how difficult it is for miners to solve a block. This means that the target hash is a flexible parameter. The target hash adjusts once every 2016 blocks or approximately once every 2 weeks.

This graph measures Bitcoin’s current difficulty. When the difficulty increases, it takes more guesses for a miner to solve a block.

What’s Next

In part 1, I elaborated on how a miner correctly solves a block and described what made solving a block expensive. In part 2 (click here for part 2), I will describe how consensus is achieved in proof-of-work and what a successful attack to the Bitcoin network might look like.

Follow me on twitter @jmartinez_43

Citations/Resources/LearnMore:

  1. Mastering Bitcoin — Andreas Antonopoulos
  2. Blockchain/Bitcoin for beginners 9: Bitcoin difficulty, target, BITS — all you need to knowMatt Thomas
  3. Hash Rate or Hash Power Sudhir Khatwani

--

--

Julian Roberto

Cryptocurrency enthusiast living in the San Francisco Bay Area.