Ethereum Hashing Implementation Called Ethash
Compared to Bitcoin, Ethereum has many new features. Also, plenty of properties inherited from Bitcoin have been improved. Some of them were partially modified (for example, addresses), while others (such as hashing algorithms) were completely replaced.
As for hashing, Bitcoin still uses the SHA256 method, while Ethereum has implemented the Keccak and Ethash algorithms. The target areas for these two methods are address compression, block connection, and mining.
Keccak and Ethash
Since the Keccak and Ethash algorithms have different properties, they are used in different processes. The main hash algorithm in Ethereum is called Keccak, which works like a “sponge”: it gathers data and spreads the result basing on all previously used processed data units. This brings up significant flexibility and may be considered as pseudorandomness. Keccak is used in many areas, except for mining.
Some Ethash details
Ethash is used for mining purposes only. Such an approach was chosen for the following reasons:
Mining algorithm is supposed to be ASIC-resistant. In order to achieve this goal, the algorithm was designed to use maximum memory.
Mining algorithm should be friendly to GPU-devices. Unfortunately, CPU can’t be used as the main target but GPU implementation is a fairly balanced solution.
New blocks should be quickly verified on light clients (also known as lightweight nodes).
New blocks should be slowly processed on light clients.
Light clients should be able to start working as soon as possible.
Overall, the Ethash algorithm consists of the following steps:
- Scanning blocks' headers allows to get a seed.
- Once the seed is found, it becomes a source of 15 MB pseudorandom cache. It is stored by light clients as well.
- Cash is a source of 1 GB data. It consists of many chunks, each of them depends on a part of cache. This data is stored by miners and full clients only.
- Random data units are taken and processed with hash for mining. If necessarily, one can store cache only and generate hashes instantly.
The Ethash algorithm is a reworked Dagger-Hashimoto method. It was revised at least 23 times. The block number defines the cache size and calculated data volume. Still, their growth rate is linear. Applied data aggregation uses a FNV-based function instead of the common logical operator XOR. It has two main differences. First, it is not cryptographic. It was intended to be used for checksum verifications and fast hash table construction. As a consequence, it is much faster to calculate. Second, it is implemented with ease.
More details on each step of cache, main dataset, mining calculations and others are presented and explained on the correspondent web page. Some calculations are implemented with the help of Recursive Length Prefix, the main encoding method for Ethereum objects serialization.
Ethereum is a very interesting solution. Most of other crypto projects proposed to public were just copies of Bitcoin with minor changes in the code. Ethereum instead offers a new approach to many of crypto components. Here, we have looked at one of two hashing methods in detail, but there are many other features worth mentioning. We will talk about them in the following articles.