Qaynaq LABS · TOOLS

CRYPTO GLOSSARY

Reentrancy attack

A type of exploit where an attacker repeatedly calls a function before its previous invocation completes, draining funds or corrupting state. Common in smart contracts that handle external calls before updating their own state.

Technical definition

A reentrancy attack occurs when a malicious contract calls back into a victim contract before the victim’s state changes are finalized. This exploits the victim’s assumption that external calls complete atomically. For example, if a victim contract checks a user’s balance, then sends funds to an attacker-controlled address, the attacker’s contract can recursively call the victim’s withdrawal function before the balance is updated. The attack relies on the victim’s failure to follow the Checks-Effects-Interactions pattern, where state changes occur before external calls.

An analogy

Imagine a vending machine that checks your wallet balance, then dispenses a snack, but before updating its inventory, an attacker repeatedly inserts coins while the machine is still processing the first transaction. The machine keeps dispensing snacks without realizing the balance was already spent.

Why it matters

Reentrancy attacks can lead to catastrophic financial losses, as seen in the DAO hack of 2016, where $60 million was drained. They highlight the importance of secure smart contract design and rigorous testing.

Where it came from

The concept gained prominence after the 2016 DAO hack, which exploited a reentrancy vulnerability in Ethereum’s smart contracts. However, similar attacks predate Ethereum, appearing in other systems where state and external calls are not properly synchronized.

Example in practice

In 2016, the DAO (Decentralized Autonomous Organization) was hacked via a reentrancy attack. The attacker exploited a flaw in the DAO’s smart contract, which allowed them to repeatedly withdraw funds before the contract updated its balance, resulting in the theft of approximately 3.6 million ETH.

Common misconceptions

  • Reentrancy attacks only affect Ethereum → Correction: They can affect any blockchain with smart contracts that handle external calls before state updates, including Ethereum, Binance Smart Chain, and others.
  • Reentrancy attacks are rare → Correction: While less common today due to improved practices, they still occur, as seen in the 2022 Mango Markets exploit on Solana.

Risks & limitations

  • Financial loss due to drained funds
  • Irreversible state corruption in smart contracts
  • Loss of user trust in blockchain applications
  • Legal and regulatory repercussions for project teams
  • Exploitation leading to protocol failures or insolvency

Related terms

About "Reentrancy attack" in crypto

Cryptocurrency vocabulary moves faster than any other technical field. New terms appear weekly, old terms quietly change meaning, and most "definitions" online were written by someone trying to sell you something. Qaynaq Labs' crypto glossary aims for the opposite: neutral, accurate, skeptical explainers that include the downside.

This entry covers the technical mechanics, a real-world analogy, where the concept came from, and what could go wrong. Pair it with the related terms to build a working mental model of how the pieces fit together.

Frequently asked

Can reentrancy attacks be prevented?

Yes, by following secure coding practices such as the Checks-Effects-Interactions pattern, using reentrancy guards (e.g., OpenZeppelin’s ReentrancyGuard), and avoiding external calls before state changes.

Are all smart contracts vulnerable to reentrancy attacks?

No, but any smart contract that makes external calls before updating its state is potentially vulnerable. Proper design and audits significantly reduce the risk.

Has reentrancy been fixed in modern blockchains?

Modern blockchains and smart contract languages have introduced features to mitigate reentrancy risks, but vulnerabilities can still emerge due to poor implementation or new attack vectors.

Can reentrancy attacks be detected automatically?

Static analysis tools like Slither or MythX can detect patterns indicative of reentrancy vulnerabilities, but they are not foolproof and require human review for accuracy.