Crypto glossary

Keccak-256

Definition

Keccak-256 is the hash function used across Ethereum to derive addresses, identify contract functions and locate storage; it differs slightly from SHA3-256.

Keccak won the US government's SHA-3 competition in 2012. Ethereum adopted it before the standard was finalised, and NIST later changed the padding rule, so the official SHA3-256 produces different outputs from the Keccak-256 that Ethereum uses. Libraries name them separately for that reason, and confusing the two is a classic developer bug.

The function is everywhere in the EVM. An Ethereum address is the last 20 bytes of the Keccak-256 hash of the public key. Contract functions are identified by the first four bytes of the hash of their signature, so transfer(address,uint256) becomes 0xa9059cbb. Event topics, mapping storage slots, Merkle Patricia trie keys and many signature schemes also rely on it, and the EVM has a dedicated opcode for it.

Keccak-256 has no known practical weaknesses, and hash functions are considered relatively resistant to quantum attacks. Short function selectors can collide by chance, which attackers have exploited to disguise malicious functions in contracts that look harmless.

Example

A developer hashes the text transfer(address,uint256) with Keccak-256 and takes the first four bytes, 0xa9059cbb, which is exactly what appears at the start of every ERC-20 transfer's input data.

Related terms