PoW is insane

Last modified:

So when I get into discussions about bitcoin, a lot of the time I get "you don't understand it" like reactions. This mostly ends the discussion from their part. It's easy to say for people, the "you don't understand", because often they don't understand it themselves, so they assume you also don't understand it. This reaction seems to have been learned in 'bitcoin school', like other reactions such as the well known FUD, where they have learned not to listen to informed criticism about bitcoin, and to disregard every negative comment as being FUD so they can stay in their own bubble. I also have noticed quite some questions online that go like "how do I respond to ..." in the bitcoin community, it seems that these people have already made up their mind, and want somebody else to come up with a response that makes them feel at ease in their own confirmation bias.

So lets see what I supposedly don't understand, and write some PowerShell script, to show the concept of PoW. This is to make it clear what this PoW concept entails, and to get people thinking about why this is an insane 'algorithm'. Below you will find the script I created, in a hopefully human readable format.

# Sample of PoW in action using PowerShell (human readable)
# based on description found on:
# https://en.wikipedia.org/wiki/Proof_of_work

$global:sha256 = [System.Security.Cryptography.SHA256]::Create()

function GetPoWHash([int]$leadingZeros, [string]$blockContent) {
    Write-Output "Getting PoW hash with at least $leadingZeros leading zero's"
    $checkValue = ""
    1..$leadingZeros | ForEach-Object { $checkValue += "0" }
    do {
        $salt = [guid]::NewGuid()
        $blockContentBytes = [System.Text.Encoding]::UTF8.GetBytes("$blockContent - $salt")
        $bytesHash = $global:sha256.ComputeHash($blockContentBytes)
        $hexHash = [BitConverter]::ToString($bytesHash).Replace("-","")
    }
    while (-not $hexHash.StartsWith($checkValue))
    return $hexHash
}

$blockContent = "The Times 11/Nov/2022 Crypto giant FTX collapses into bankruptcy"

Write-Output (Get-Date).ToString("HH:mm:ss:fff")
GetPoWHash 2 $blockContent
Write-Output (Get-Date).ToString("HH:mm:ss:fff")
GetPoWHash 4 $blockContent
Write-Output (Get-Date).ToString("HH:mm:ss:fff")
GetPoWHash 6 $blockContent
Write-Output (Get-Date).ToString("HH:mm:ss:fff")
      

So, first of all, what are people saying about PoW? Most often they talk about "complex calculations" or "solving a puzzle". Well all a computer does is computing, or making calculations. And no, PoW is not solving a Sudoku, although I have created a program for that once. Describing PoW as "complex calculations" or "solving a puzzle" is actually a euphemism for wasting a lot of energy to hopefully find the hash that meets the criteria. And remember, this is not done by one computer, but by who knows how many thousands of computers.

To make it clear, finding a hash (multiple options could be found) that meets the criteria, is an expensive task when the criteria gets harder and harder. The speed at which a matching hash is found, is of course related to how many computing power is used. And it also requires some luck to find the hash that matches the criteria, and the more computing power, the more chances a miner has at finding this hash value.

Now, lets run the script. Yeah, I actually wasted some extra energy to get you this output. Try it yourself to hear your computer's cooling fan making more noise. Luckily I have not made it multi threaded.

PS P:\Projects\BitCon> .\PoWsample.ps1
13:05:50:522
Getting PoW hash with at least 2 leading zero's
00FC94C5546AC83F1A1AF62D98B36B234FC4BBD616D9E366BE71CA9CB87E630F
13:05:50:532
Getting PoW hash with at least 4 leading zero's
0000A474E01886C7000A2A6D781F76F89AD9324715A11F4AA8CDB4DCB376D758
13:05:55:020
Getting PoW hash with at least 6 leading zero's
000000694A5F3D7E5269D74AB71F1C3A167A5640FAF4D1EB44276B2E5517C37F
13:25:29:637
      

For the salt a new random value has to be created, as I am a bit lazy, I just use a new guid for each try. Then we add this random value to the content of the block, and get the bytes of this that we use to get the hash from. The hash of the result is then converted to a readable hexadecimal string and then there is a check if this value matches the criteria.

So, now you know how the concept of PoW works. You would see that "complex calculations" or "solving a puzzle" isn't really what is happening. What is happening is: Guessing a 'salt' value that will lead to a hash that meets the criteria. This is done countless of times, where each time a new hash is calculated and checked.

As you can see, finding a hash starting with 00 took some milliseconds, with 0000 took about 5 seconds and with 000000 took about 20 minutes. Although, as it is all guesswork, times can vary and sometimes harder criteria will come sooner, but on average of course harder criteria will lead to more guesses and checks. And that is what PoW is, and if you would like to describe PoW to others, you best call it: doing a lot of guesses and checks.

Of course, using the block contents and the 'salt', you can generate a hash from that and check that the 'salt' produces the hash that matches the criteria. The issue is with finding the 'salt' that produces this hash, that is the Proof of Work, not with checking the hash afterwards.

I hope you now understand why PoW is an insane 'algorithm', and I think you understand why this wasn't suitable for preventing spam e-mail messages. It is also not really suitable for any other purpose, although I do think the concept is interesting. And maybe next time, if you want to say to someone critical to bitcoin or crypto-coins, "you don't understand", remember this article, some of us do understand.