Showing posts with label Ethas. Show all posts
Showing posts with label Ethas. Show all posts

Wednesday, May 30, 2018

The Ethereum's Proof of Work

Information about BitCoin proof of work is easily accessible in the whole internet, but what about the Ethreum Proof of Work? It has not been very easy for me to retrieve the technical information I was looking for and put them together in a way that could be easily understood.

Let's start at the beginning: what the proof of work is and why it is necessary.


Proof of work means that something satisfies the requirement of an expensive computer calculation. In fact, in a blockchain system as Ethereum, where the consensus is based on the proof of work, every transaction needs a lot of computer calculation to be done before it can be considered closed and "valid". The objective is to avoid DDoS (distributed denial of service) attacks to the network. In this specific scenario, the purpose is to avoid distributed attempts to close "forged" transactions. Given that, for closing a transaction a lot of calculation is needed, it would be really hard to execute a successful attack, where a lot of fake transactions should be closed (and received and spread) faster than any other node on the network. Considering that normally nodes which close transactions (the so called mining process) are remunerated with "ether" (the Ethereum's crypto currency), even if someone has the necessary calculation power, maybe it is more remunerative to close real transactions than to try to close the forged ones.

The Ethereum Proof of Work algorithm, Ethash


The algorithm used by the Ethereum blockchain, is known as Ethash, and is quite similar to the bitcoin one, but with some differences. For example, a lot more memory is needed and the majority of a miner's effort will be spent reading a great set of data then making changes to it. But let's go into details, and try to put it in a way which is easily understandable.

Everything starts with the seed. The seed is a 32 digit number and actually it is the basis of the mining process. It is calculated looping through the headers of the current block and applying a variant of the SHA3 algorithm. The results are joined together and combined into the 32 digit number mentioned before.

From the seed, a 32 MB random cache using a combination of the SHA3 algorithm and a random memory hash algorithm (Strict Memory Hard Hashing Functions) is then calculated. The SHA3 algorithm is applied repeatedly to the seed until we get a 32 MB memory string. This one is subsequently double passed by the random memory hash algorithm. The result is a set of 524288 64-byte values.

From the cache a 1 GB dataset combining data from 256 cache nodes is generated. The dataset is stored in miners and full clients and grows linearly during the time. This gives an idea of why the majority of a miner's effort will be reading the data (a big amount of).

The mining process consists of taking slices of the dataset (nounce) and combining them with a header until the algorithm gets a result value below a desired target. This is when the miner has succeeded in closing a block.
The header is the hash of a truncated block header that is keep fixed. The nounce is 128 bytes of sequencially read data from the dataset (taken from random nodes). The mining loop keeps the header fixed and tries to combine it with all the different nounces until calculating the desired result.

That's it, a quite simplified, but still technical, explanation of how the proof of work "works" inside the Ethereum network. More detailed information can be found on the official Ethreum wiki.

It is worth saying that the network wants to move from a process where consensus is based on the proof of work, to a system where the consensus is based on the proof of stake, and later we'll talk about that too.