‘Proof of work’ is the name given to the confirmation mechanism most famously adopted by the Bitcoin blockchain. In proof of work, in order for a node to be elected as a leader (i.e. be allowed to choose the next block containing information to be added to the blockchain, which will then be universally accepted by and replicated across the network), the network participant must find a solution to a particular mathematical problem.
Difficulty means how hard it is for the nodes to solve the mathematical problem and is linked to the ‘target’ (i.e. Y in the mathematical problem above). The lower the target, the more difficult (and therefore the more time-consuming and expensive) the mathematical problem becomes to solve.
Hashing means the transformation of a string of characters into a (typically shorter) fixed-length value or key that represents the original string.
Nonce stands for ‘number once’ and means the integer value which is appended to the end of the hash of the previous block and the new data (i.e. X in the mathematical problem above) incrementally by miners. The nonce is n in the mathematical problem above.
Let’s say the base string (i.e. X in the mathematical problem above), is: “Hello, world!”. We first append a nonce to this message. The first nonce will be ‘0’, making the full string: “Hello, world!0” We then hash this string using a cryptographic hash function. There are a number of such functions though, for the purpose of this article, we will use SHA-256, being the hash function used by the Bitcoin blockchain. If we hash our string using SHA-256, we get: 1312AF178C253F84028D480A6ADC1E25E81CAA44C749EC81976192E2EC934C64.
We then convert our hash into a long integer. There are a number of ways in which this can be done, none of which are particularly exciting or interesting. If our example were to be running on the Bitcoin blockchain, our string’s hash would be interpreted as 2^252.253458683.
As stated in our mathematical problem above, we are looking for our string to hash to a value which, when interpreted as a long integer, is a number less than Y. For the purposes of our example, let’s say that our Y target value is 2^240. Clearly, our string (which, when hashed and interpreted as a long integer is 2^252.253458683) fails in this regard. No problem! We incrementally increase the nonce (i.e. our string is now: “Hello, world!1”) and try again.
One of the ideal properties of a cryptographic hash function such as SHA-256 is that even a small change to the string will change the hash so extensively that the new hash appears uncorrelated to the old hash. Our incremental increase to the nonce completely changes our hash – our string now hashes to: E9AFC424B79E4F6AB42D99C81156D3A17228D6E1EEF4139BE78E948A9332A7D8. Interpreted as a long integer, this hash is: 2^255.868431117. Still no luck!
The target has been met and whichever node solved the problem first wins the right to append the new block to the chain. This sounds pretty arduous, but in reality 4251 hashes on a modern computer is not particularly difficult. The Bitcoin blockchain automatically varies the difficulty to keep a roughly constant rate of block generation – the difficulty would be much greater than 2^240! The base string on the Bitcoin blockchain would be all of the unconfirmed transaction which the miner proposes to bundle into a block. The act of solving the problem by the nodes is called ‘mining’ and nodes are incentivised to mine by the mining reward – the ‘winning’ miner is rewarded with newly created Bitcoin.
Secure – it becomes extremely difficult to alter historic blocks, since any such alteration would require re-mining all subsequent blocks. This is why blockchains are often described as being ‘immutable’.
Slow – the time it takes the miners to solve the mathematical problem (and thereby confirm the transactions) is sub-optimal for many blockchain use-cases.
Environmentally unfriendly – effort requires computing power and computing power requires electricity. The scale of the Bitcoin network, coupled with the spike in BTC value in late-2017, saw a surge in Bitcoin mining activity and associated energy consumption. In mid-2018 estimates as to the energy consumption of the Bitcoin network were as high as 22 terawatt-hours (TWh) per year – almost the same as the Republic of Ireland. Given that this spike did not coincide with anything like mass adoption of BTC, this is clearly sub-optimal in the long run for high-volume blockchains.
If you have any questions regarding proof of work, consensus mechanisms, blockchain or smart contracts and how they might impact you or your business, please get in touch – tom.grogan@mishcon.com.