Proof of work

In this article proof of work, as used in bitcoin and other cryptocurrencies, is explained. Also a small demonstration, which simulates proof of works inside the browser is linked.

Hashcash

Originally proof of work algorithms were researched to be an effective measure against spam or denial of service attacks. Adam Back released a paper in 2002 were he named this approach as Hashcash. Similar approaches seem to be older than Hashcash, as found in the related work section on the Hashcash website.

The basic idea behind Hashcash is to limit the usage of a service by requesting solutions to computational problems for each use. Metaphorically this can be though as a payment for the service. E.g. everytime an email service can be used to send an email some seconds of computational work have to be done in advance by the service user. This would require lot's of computational work from somebody who wants to send spam mails via this email service. In the following a simple description of the steps of the Hashcash algorithm are given:

Depending on the number of leading zeros to the hash, the computation gets harder and harder. So the Hashcash algorithm can be adjusted with rising computing power available to service users. The Hashcash approach seems like an interesting idea for fighting spam, however at least on the web this approach is not used widely. Captchas which require human involvment are probably more effective.

Proof of work in bitcoin/blockchain

The bitcoin blockchain is a public and distributed database of all valid transactions. As the bitcoin blockchain generally is public, everybody could add transactions to one's own benefit. Proof of work is used to prevent the incorrect addition of transactions to the bitcoin blockchain. This makes the bitcoin blockchain a database which can be read by anyone, however changes can only be added under certain conditions:

Difficulty retargeting

The important part with proof of work is the difficulty (number of zeros at the beginning of the hash result). The difficulty specifies the approximate amount of time required to find a solution by the available computing power (hashrate). The bitcoin network specified a block time of 10 minutes, this means that the available computing power should not find a solution before 10 minutes.

The available computing power for the bitcoin blockchain is measured by the hashrate (amount of hashes computed within a second). The more computing power is added to the network, the higher gets the hashrate and thus a solution for the proof of work is found earlier that 10 minutes. Therefore the difficulty target needs to be dynamic based on the available computing power. Bitcoin added an intelligent mechanism to retarget the difficulty every 2016 blocks. Based on the assumption that every 10 minutes one new block is generated, this would mean 2016 blocks take exactly 2 weeks to mine. So if it took more time that 2 weeks to find 2016 blocks the difficulty is decreased otherwise it is increased.

Browser simulation

I created a small simulation, which can be run inside a browser. The simulation should demonstrate how proof of work mining works. The simulation can be found here and the source code is available on github.

Further reading