Proof of work for dummies

Why is it such a hard work to guess a number less than a given number? Isn’t that what happens in Bitcoin mining? ‘I cannot understand this’ said one of my friend who does not have any connection to IT beyond using mobile phone. Here is my try.

First thing first, numbers. We need to understand number system. We have a decimal number system where we have digits from 0 through 9. For any number greater than 9, digits from 0 to 9 are used to represent them, like 10, 11, 135 etc. We all understand this. There is one more number system called Hexadecimal where digits are 0,1,2,3,4,56,7,8,9,a,b,c,d,e,f – total 16 digits. If I say the number is ‘f’, then it means 15 in decimal. ’10’ in hexadecimal is equal to 16 in decimal number system.

Thus, ’88a8aa’ is a number. That is the point.

SHA256 – It is an encryption algorithm which takes any length of numbers/text and gives out a fixed length hexadecimal number of 64 digits (256 bits). The output is called ‘hash’ of input. If it is difficult to understand, then treat it like a mathematical black box which takes some text or numbers as input and gives out 64 digit output. Take a look at the following input and output (You can try creating SHA256 hash here).

InputI have no special talent. I am only passionately curious

Outputf817b4162e7227ec09870f722997a7fa039bd1a7a4dc3a36ecb76180717daabc

Output is a number – a Hexadecimal number. The output of SHA256 is like a fingerprint of the input. That is, as long as input remains the same, you always get the same output. Take a look at the following input-output pair.

InputI have no special talent. I am only passionately curious.

Output37410c8cfdd6ad54378425c017e0b3ba0ed5d0fa93ddb791d8a2f2602e756f3e

You can immediately notice that output is entirely different. Can you notice the change in the input?

I have just added fullstop (‘ . ‘) at the end of the sentence. Just an additional character changes the output entirely. Even if you change an upper case letter to a lower case letter, output will change entirely. That is the magic of this black box called SHA256.

Few key learnings emerge from these examples –

  1. Given an input, the output of SHA256 is always the same.
  2. A small change in input will change the output entirely. And it is impossible to predict.
  3. It is impossible to guess what was the input, looking at the output.
  4. The output is a number (a hexadecimal number). That means this hexadecimal number can be compared with another hexadecimal number to check if it is equal to, greater than or less than the other number.

The Puzzle

We have enough background to understand the puzzle now. If I say, give me a number which is less than

0000000000000004378425c017e0b3ba0ed5d0fa93ddb791d8a2f2602e756f3e

How long does it take? This is no hard work. Simply pick any non-zero digit in the above number and reduce it by one, you get a number less than the one above. But I bring in a SHA256 twist.

Get a number less than 0000000000000004378425c017e0b3ba0ed5d0fa93ddb791d8a2f2602e756f3e (let’s call it target number) , but the number should be generated by SHA256 using the combination of text ‘I have no special talent. I am only passionately curious‘ and a number of your choice.

Now we know SHA256 output of ‘I have no special talent. I am only passionately curious‘. That cannot change. If I add some number at the end, I get another output. If I change the number yet another output. But how do I know what number to be added to given text to get the number less than 0000000000000004378425c017e0b3ba0ed5d0fa93ddb791d8a2f2602e756f3e ?

Nobody knows. The only way to get it is to try different numbers. How many numbers? As many until you get output less than target. The number that you attach to the given text is known as NONCE (Number used only once). Now that’s quite a hard work. One uses a computer to keep trying different number with given text, get the output, compare with target number until desired number is obtained.

This is the puzzle, in crux, that every Bitcoin miners is trying to solve. Guess the right NONCE for which SHA256 gives a number less than target number. When they hit the number, that number is the Proof of Work they have done (which can be easily verified), for which the miner is rewarded with Bitcoins.

The text to which NONCE needs to be attached is not some random text but details from a blockchain block.

Leave a comment