Understanding Ethereum (Part 4): Proof Of Work Puzzle Explained Using A Simple Analogy

Hey guys,

In my previous posts I explained Sharding Using A Simple Analogy. I intended on writing on Plasma & Casper moving forward, but I noticed that there’s still a few other topics that need clearing out. Mainly on Proof of Work and Proof Of Stake.

As many of you may know – Ethereum is currently still using Proof Of Work. To fully understand the implications of the move to Proof Of Stake, we need a basic understanding of Proof Of Work.

Proof Of Work is used to determine the representation of the majority . Determining the majority is one of the keys in being able to come to consensus on decisions. But in order to determine the majority, Proof Of Work uses Cryptographic Puzzles (or Proof of Work Puzzles) – making them just as important.

But how do these Proof Of Work puzzles work? What kind of puzzle is this? I get these questions a lot. Usually in different forms.

In this post I break down the Proof Of Work Puzzle & Mining using a simple analogy – and no technical jargon!

# The PoW Puzzle – The ‘Reverse’ Lottery Analogy

To avoid the nitty-gritty technicals, let’s use an analogy.

Suppose you enter yourself into a lottery.. But this is a special kind of lottery. We’ll call it a “Reverse Lottery”.

In this lottery everybody knows the winning numbers. Sounds like an easy lottery to win, right? Not exactly.

You can’t simply “pick” your numbers when buying your ticket. You can only buy a ticket with numbers randomly generated on it. So, the only way for you to win the lottery is to keep buying ticket after ticket after ticket…. Until you buy one that matches the winning numbers you have.

This is precisely what is involved in the Proof Of Work cryptographic puzzle. People use their computers to randomly generate numbers at a rapid pace. (These people are called miners, btw.) If they generate the “winning” number, they win the lottery.

# The Reverse Lottery & PoW : Breaking It Down

Let’s say you know the winning ticket number of a Reverse Lottery to be: 1111111111.

Now it’d be nice if you could go up to the counter and ask for a ticket with those numbers. But you can’t. All you can do is pay for a ticket and hope it generates: 1111111111. If not – tough luck. Buy another ticket and try again.

The good news is that you can try as many times as you can. The bad news is that you have to pay for each new ticket.

Our “Reverse Lottery” is essentially what the cryptographic puzzle is.

Player in the Lottery = Miner in the Network

Buying tickets with random numbers = Using Computational Power To ‘Solve’ Algorithms (Hashing)

In the Reverse Lottery, each player is hoping that he generates the winning ticket number before someone else does. Similarly, each Miner is hoping that he can generate (by ‘hashing’) the winning numbers before other miners do.

In the lottery, players are paying for each ticket with money. Miners are using computational power to “hash” their numbers – which translates to electricity costs.

The good news is the miners are using hardware that generate millions of hashes per second.

The miner who finds the winning hash gets to add his “block” to the blockchain. In return he gets a reward. He also gets to collect transaction fees for all transactions listed in the block.

On average, a winning number (or winning hash) is found every 10 minutes. This average can be adjusted but we’ll talk about that later. And the miners move on to compete for the next winning hash. It’s kinda like a new Reverse Lottery every 10 minutes.

The process of trying to find the winning hash is called “Mining”. The term actually originates from the traditional “mining” of gold. But instead of using a pick-axe to dig for Gold, Miners are using their computers to dig for the winning hash.

That’s pretty much it. You pretty much understand how the process works now. But I may have left out one aspect. The Nonce.

# The Cryptographic Puzzle: Nonce?

Let’s go back to our Reverse Lottery. Suppose the creators of this lottery decide to spice things up. They realize that they need to make lottery players feel more “involved”.

To achieve this, they add a new element into the Reverse Lottery. Now, instead of simply randomly generating a number they ask the player for the following information first:

1. His Name (For example : Bob )

2. His Favourite Color (For example : Green )

3. A “random number” of his choice (For example : 7)

The Reverse Lottery will take all three answers – Bob, Green, 7 – and put it into a special “mixer”. You can think of Bob, Green and 7 are the “ingredients”. The mixer will spit out a Lottery Ticket for Bob based on the ingredients he gave it.

(Btw this is precisely what “hashing” is. A function/algorithm that takes “ingredients” and produces an output based the input.)

If the ticket matches the winning number – great! He wins! If not, he will have to try again – but this time with a different “random number”. This will give him a new lottery ticket number.

Essentially, his name “Bob” and favorite color “Green” will remain fixed as ingredients. His ‘random number’ keep changing until he gets the winning lottery ticket.

In Mining, this “random number” is what we call the nonce. The other “fixed” ingredients are the transaction data, block data, timestamp etc.

The nonce is incremented after each failed attempt. (Fyi, the other ingredients are relatively fixed. They change when necessary – but that’s nitty-gritty stuff we don’t care about atm) And the "ingredients" are run through the mixer again. The mixer spits out a new hash each time. If the hash matches – great! If not, the miners computer will increment the nonce and try again. (This is done at an extremely rapid pace btw)

# Wrapping Up

To sum it all: In Proof Of Work people (miners) are essentially racing against each other to generate the winning numbers for the Reverse Lottery.

Instead of repeatedly buying tickets at a counter, they expend electricity by rapidly running an algorithm on their computer over and over again. When and If they generate the winning number (winning hash) they get to add their “block” of transactions to the blockchain. In return, they claim a reward and the transaction fees for all the transactions in the added block.

There’s more I’d like to discuss – like Verifiability. I’ll leave that for the next post though. For now, I’ll let you ponder over this question:

“How do the other miners verify that he really did find the winning hash?”