Ethereum Hashing Algorithm Keccak
Ethereum uses hashing in several areas: mining, blocks connection, transactions reference, addressing scheme. Ethash as one of Ethereum hashing methods is adopted for all operations related to mining. The main reasons are that Ethash is fast and ASIC-proof. For all other hashing processes in Ethereum, the Keccak method is used.
And here some confusion may arise. Ethereum was launched before the National Institute of Standardization and Technology (NIST) announced a hash function competition to create a new hash standard, SHA-3. Later, the Keccak algorithm was selected as the winner. Now the original SHA3 Keccak is known as “Keccak” in the Ethereum community, while the SHA3 standard approved by NIST is called “SHA-3”. The fact that Solidity uses the SHA3 and Keccak256 functions makes things even more complicated.
In this article, we will talk about the simplest Keccak implementations.
Some Keccak Details
As Keccak home page states, Keccak is a flexible cryptographic function. Its wide publicity is due to its hashing properties, but it can also be used for authentication, reliable encryption, and pseudo-random number generation.
Keccak uses a so-called sponge construction. Here, data is gathered and processed in parts with the help of permutation functions and the XOR operator.
After Keccak won the competition, it was used in several standards. Many third parties have been changing it for their own projects. Keccak developers also brought several other schemes based on this method.
Keccak in Ethereum Yellow Paper
Ethereum yellow paper explains all basic features of Keccak. It is so far the best source to get information about hashing in Ethereum functioning processes. There are several mentioned hashing names like KEC, Keccak-256 and KEC512 implemented for different purposes.
Word State Safety
Ethereum operates with the “Word state” meaning. It is basically the reference between addresses and accounts of two types. This state is assured and secured by the Patricia Tree (advanced kind of the Merkle Tree). Each intermediate element of this tree starting from above data itself is a result of a hash function. Apart from verification, hashing here serves as a mark and allows restoring a desired state of the system by its hash value.
Each account is defined by four elements. Two of them are hashed data. The first one is a hash of the data storage associated with the current account. Also, Ethereum is know by its smart contract concept introduction. All contract codes are stored in the world state. The second hash element of the account is a hash of the contract code situated within the current address. Such approach allows checking the system for malicious behaviour and is used for addressing purposes.
Addressing And References
Transactions use addresses with 160 bit each to define a recipient. Each address here is a 20-bytes cut from the hash of account data. Each block contains the hash of previous block header. Here, we get another interesting mining detail called the Ommers system. Ommers are valid blocks mined later than the first correct block added to blockchain. The hash of their list gets included in the block header along with the hashes of the state tree, transactions tree, and the tree with all transactions effects.
Ethereum uses nonce combined with another hash to prove that enough of computation power was used in data processing.
Ethereum uses hashing in many processes. In this article, we have considered the most technically simple areas of its application. For experienced users interested in a more detailed study of this complex topic, we recommend to proceed with the technical documentation.