keccak

The Keccak algorithm is a hash function that compresses arbitrary data into a fixed-length "fingerprint" and serves as the core of the SHA-3 standard adopted by NIST. It is widely utilized in Ethereum for address generation, contract function selectors, and event logs. Keccak employs a "sponge" construction, thoroughly mixing data through absorb and squeeze processes combined with 24 rounds of permutation. This design supports multiple output lengths, balancing security and performance.
Abstract
1.
Keccak is a cryptographic hash function selected as the foundation for the SHA-3 standard.
2.
Ethereum blockchain uses Keccak-256 algorithm to generate addresses and transaction hashes.
3.
Keccak employs a sponge construction design, offering high security and flexible output lengths.
4.
Compared to traditional SHA-2 algorithms, Keccak provides stronger collision resistance and performance advantages.
keccak

What Is the Keccak Algorithm?

The Keccak algorithm is a family of cryptographic hash functions designed to map arbitrary input data into a fixed-length digital fingerprint. It serves as the foundation of the SHA-3 standard and is widely adopted in blockchain applications.

A hash function can be thought of as a “fingerprinting machine”: the same input will always produce the same output, but it is nearly impossible to reconstruct the original input from the output alone. Keccak supports variable output lengths, with 256-bit (Keccak-256) being the most common. This fixed-length output enables efficient verification, indexing, and consistency checks.

Why Is Keccak Important in Web3?

Keccak is crucial because it functions as the core “fingerprinting machine” for systems like Ethereum, underpinning essential processes such as address generation, smart contract function selectors, and event log indexing.

For example, on exchanges like Gate, when you deposit ETH, the address beginning with “0x” is derived by hashing the public key with Keccak-256 and taking the last 20 bytes. For contract calls, the function selector is generated by applying Keccak-256 to the function’s signature and extracting the first 4 bytes. Event logs use Keccak to generate topics for fast searching.

How Does the Keccak Algorithm Work?

Keccak uses a “sponge construction.” Imagine a sponge: it first “absorbs” input data to mix the internal state, then “squeezes” out the desired hash output.

Step 1, Absorption: The input message is divided into blocks, which are XORed into the “writable area” of the state—like soaking up water into a sponge and integrating data into the state.

Step 2, Permutation: A permutation function (Keccak-f) is applied in multiple rounds to shuffle the bits in the state. This permutation is a reversible “shuffling” process; Keccak-f[1600] typically runs for 24 rounds.

Step 3, Squeezing: The output is read from the “readable area” of the state. For longer outputs, further permutations are applied before more data is extracted—much like squeezing more water from a sponge as needed.

With standard Keccak-256 parameters, the internal state has 1600 bits, partitioned into a bitrate (read/write area) of 1088 bits and a capacity (security buffer) of 512 bits. Larger capacity means higher security.

How Is Keccak Used in Ethereum?

There are four main applications of Keccak in Ethereum: address generation, function selectors, event topics, and data structure indexing.

  • Address Generation: An Ethereum address is typically produced by applying Keccak-256 to a public key and taking the last 20 bytes for the “0x”-prefixed address. Deposit addresses you see on Gate are generated this way. Some address checksum formats also use Keccak for case verification.
  • Function Selectors: The textual signature of a function (e.g., "transfer(address,uint256)") is hashed with Keccak-256, and the first 4 bytes are used as the selector. The well-known selector "0xa9059cbb" comes from this rule.
  • Event Topics: An event’s name and parameter types are concatenated and hashed with Keccak-256 to produce a topic. This enables fast, efficient on-chain event searches.
  • Data Structure Indexing: In state trees or mapping keys, Keccak-256 hashes keys to minimize collisions and speed up queries.

What Is the Difference Between Keccak and SHA3?

The main distinction between Keccak and SHA3 lies in their padding (“domain separation”) parameters. SHA3-256 uses a padding suffix of 0x06, while Ethereum’s common Keccak-256 uses 0x01.

This means identical inputs produce different outputs for Keccak-256 and SHA3-256. In development or audits, it’s critical to confirm whether you’re using “Keccak-256” or “SHA3-256”—they are not interchangeable. When NIST standardized SHA-3 in 2015, it made this domain separation adjustment (source: NIST, 2015).

How to Use Keccak Correctly in Development

Step one: Confirm whether your input is bytes or text. If it’s a string, always encode it as UTF-8; for hexadecimal strings, convert them to raw bytes and don’t include any “0x” prefix as part of the data.

Step two: Choose the correct function. In the EVM, keccak256 (i.e., Keccak-256) is standard. Some libraries refer to SHA3-256 as sha3—check documentation and library versions carefully to avoid mistakes.

Step three: Cross-validate results. Use two independent libraries or tools to compute hashes and ensure they match; you can use known selectors like "transfer(address,uint256)" producing "0xa9059cbb" as test cases.

Treat hashes as irreversible fingerprints in your workflows—they are not encryption or random numbers. To prevent rainbow table attacks, always add random salt before hashing, and hash both salt and data together.

What Are Common Risks and Pitfalls with Keccak?

There are three main pitfalls: padding differences, encoding errors, and misuse in application scenarios.

  • Padding Differences: Using Keccak-256 in place of SHA3-256 will yield different results, potentially leading to mismatched addresses or selectors—which can cause fund loss or contract call failures.
  • Encoding Errors: Treating text as hex or vice versa will completely change the hash result. Standardize encoding strategies in development and cover edge cases in tests.
  • Misuse in Application: Hashing is not encryption. Storing sensitive data after a single hash may still be vulnerable to dictionary attacks. Always add random salt and control access policies. For financial safety processes (such as Gate’s on-chain deposit recognition), conduct thorough pre-launch testing and auditing.

How Secure and Efficient Is Keccak?

Keccak’s security relies on its sponge construction and capacity parameter. For Keccak-256, collision resistance is approximately 2^128 operations; pre-image resistance is about 2^256 operations.

As of January 2025, no practical collision or pre-image attacks have been found against standard parameters; research mainly focuses on reduced-round variants or theoretical boundaries. Performance-wise, leading libraries have optimized CPU/GPU implementations for high throughput; hardware acceleration (e.g., ASICs) is advancing for demanding use cases.

What Is the Future Outlook for Keccak?

Keccak will remain central to system security as the core of SHA-3; within the EVM ecosystem, it is foundational for addresses, selectors, and log indexing. As hardware acceleration matures and library implementations improve, both performance and tooling will advance further. Some new use cases (such as zero-knowledge proofs) may adopt alternative hashes like Poseidon, but this does not affect Keccak’s stability for general-purpose fingerprinting and indexing tasks. For developers, as long as you distinguish between Keccak-256 and SHA3-256 and rigorously manage encoding and testing workflows, Keccak remains a reliable low-level tool.

FAQ

I want to generate a wallet address using Keccak—where do I start?

In Ethereum, Keccak-256 is used to generate account addresses—by hashing your public key with Keccak-256 and taking the last 20 bytes as your address. If you use Gate or another wallet app, this process happens automatically; if you are developing smart contracts, you can use Solidity’s built-in keccak256() function. Try libraries like Web3.js first to see how hashes convert arbitrary-length data into fixed 256-bit results.

Why do different tools produce different Keccak hash results?

This usually stems from differences in input data encoding. Keccak-256 expects byte data—if you enter text strings, tools may handle character encoding differently (UTF-8 vs ASCII). The solution is to standardize your encoding and explicitly specify input format during development; platforms like Gate typically provide clear input instructions. Also confirm whether you’re using Keccak-256 or SHA3-256—their outputs differ even for identical inputs.

Besides address generation, what else is Keccak used for in smart contracts?

Keccak-256 has broad applications in smart contracts: verifying data integrity (hashing transaction data for comparison), generating unique IDs (hashing combined parameters), or implementing access control (storing sensitive info as hashes rather than plaintext). Some contracts hash user data before storage to avoid exposing raw values. This flexibility makes Keccak a foundational Web3 tool—but remember that hashing is one-way: original data cannot be recovered from its hash.

Do I need advanced cryptography knowledge to learn Keccak?

No. As a Web3 user or entry-level developer, you only need to understand that “Keccak is a one-way hash function—identical input always yields identical output.” Deeper cryptography study is optional (for security audits or research); most developers simply call existing library functions such as Solidity’s keccak256. Start by experimenting with real applications like signatures or address generation on Gate or testnets.

What should I watch out for when using Keccak in off-chain applications?

When calling Keccak from off-chain code (front end or back end), make sure your library version matches what’s used on-chain—typically Keccak-256. Using standard libraries such as Web3.js or ethers.js avoids most pitfalls since they implement Keccak correctly by default. Be careful with data serialization—if you generate hashes off-chain for on-chain verification, serialization methods (like ABI encoding) must match exactly. Always validate thoroughly in test environments, especially for signatures or contract verification scenarios.

A simple like goes a long way

Share

Related Glossaries
epoch
In Web3, "cycle" refers to recurring processes or windows within blockchain protocols or applications that occur at fixed time or block intervals. Examples include Bitcoin halving events, Ethereum consensus rounds, token vesting schedules, Layer 2 withdrawal challenge periods, funding rate and yield settlements, oracle updates, and governance voting periods. The duration, triggering conditions, and flexibility of these cycles vary across different systems. Understanding these cycles can help you manage liquidity, optimize the timing of your actions, and identify risk boundaries.
Define Nonce
A nonce is a one-time-use number that ensures the uniqueness of operations and prevents replay attacks with old messages. In blockchain, an account’s nonce determines the order of transactions. In Bitcoin mining, the nonce is used to find a hash that meets the required difficulty. For login signatures, the nonce acts as a challenge value to enhance security. Nonces are fundamental across transactions, mining, and authentication processes.
Centralized
Centralization refers to an operational model where resources and decision-making power are concentrated within a small group of organizations or platforms. In the crypto industry, centralization is commonly seen in exchange custody, stablecoin issuance, node operation, and cross-chain bridge permissions. While centralization can enhance efficiency and user experience, it also introduces risks such as single points of failure, censorship, and insufficient transparency. Understanding the meaning of centralization is essential for choosing between CEX and DEX, evaluating project architectures, and developing effective risk management strategies.
What Is a Nonce
Nonce can be understood as a “number used once,” designed to ensure that a specific operation is executed only once or in a sequential order. In blockchain and cryptography, nonces are commonly used in three scenarios: transaction nonces guarantee that account transactions are processed sequentially and cannot be repeated; mining nonces are used to search for a hash that meets a certain difficulty level; and signature or login nonces prevent messages from being reused in replay attacks. You will encounter the concept of nonce when making on-chain transactions, monitoring mining processes, or using your wallet to log into websites.
Immutable
Immutability is a fundamental property of blockchain technology that prevents data from being altered or deleted once it has been recorded and received sufficient confirmations. Implemented through cryptographic hash functions linked in chains and consensus mechanisms, immutability ensures transaction history integrity and verifiability, providing a trustless foundation for decentralized systems.

Related Articles

What Is Ethereum 2.0? Understanding The Merge
Intermediate

What Is Ethereum 2.0? Understanding The Merge

A change in one of the top cryptocurrencies that might impact the whole ecosystem
2023-01-18 14:25:24
Reflections on Ethereum Governance Following the 3074 Saga
Intermediate

Reflections on Ethereum Governance Following the 3074 Saga

The Ethereum EIP-3074/EIP-7702 incident reveals the complexity of its governance structure: in addition to the formal governance processes, the informal roadmaps proposed by researchers also have significant influence.
2024-06-12 02:04:52
Blockchain Profitability & Issuance - Does It Matter?
Intermediate

Blockchain Profitability & Issuance - Does It Matter?

In the field of blockchain investment, the profitability of PoW (Proof of Work) and PoS (Proof of Stake) blockchains has always been a topic of significant interest. Crypto influencer Donovan has written an article exploring the profitability models of these blockchains, particularly focusing on the differences between Ethereum and Solana, and analyzing whether blockchain profitability should be a key concern for investors.
2024-06-17 15:14:00