What Is a Reentrancy Attack and How Does It Work? – MUO – MakeUseOf
Some of the biggest hacks in the blockchain industry, where millions of dollars worth of cryptocurrency tokens got stolen, resulted from reentrancy attacks. While these hacks have becomes less common in recent years, they still pose a significant threat to blockchain applications and users.
So what precisely are reentrancy attacks? How are they deployed? And are there any measures developers can take to prevent them from happening?
A reentrancy attack occurs when a vulnerable smart contract function makes an external call to a malicious contract, temporarily giving up control of the transaction flow. The malicious contract then repeatedly calls the original smart contract function before it finishes executing while draining its funds.
Essentially, a withdrawal transaction on the Ethereum blockchain follows a three-step cycle: balance confirmation, remittance, and balance update. If a cybercriminal can hijack the cycle before the balance update, they can repeatedly withdraw funds until a wallet is drained.
One of the most infamous blockchain hacks, the Ethereum DAO hack, as covered by Coindesk, was a reentrancy attack that led to a loss of over $60 million worth of eth and fundamentally changed the course of the second largest cryptocurrency.
Imagine a bank in your hometown where virtuous locals keep their money; its total liquidity is $1 million. However, the bank has a flawed accounting systemstaffers wait until the evening to update bank balances.
Your investor friend visits the town and discovers the accounting flaw. He creates an account and deposits $100,000. A day later, he withdraws $100,000. After one hour, he makes another attempt of withdrawing $100,000. Since the bank has not updated his balance, it still reads $100,000. So he gets the money. He does this repeatedly until there's no money left. Staffers only realize there's no money when they balance the books in the evening.
In the context of a smart contract, the process goes as follows:
Generally, the attacker successfully exploits the reentrancy vulnerability to their advantage, stealing funds from the contract.
So how exactly might a reentrancy attack technically occur when deployed? Here's a hypothetical smart contract with a reentrancy gateway. We'll use axiomatic naming to make it easier to follow along.
The VulnerableContract lets users deposit eth into the contract using the deposit function. Users can then withdraw their deposited eth using the withdraw function. However, there's a reentrancy vulnerability in the withdraw function. When a user withdraws, the contract transfers the requested amount to the user's address before updating the balance, creating an opportunity for an attacker to exploit.
Now, here's what an attacker's smart contract would look like.
When the attack is launched:
The attack can happen very fast, depending on the network's performance. When involving complex smart contracts such as the DAO Hack, which led to the hard fork of Ethereum into Ethereum and Ethereum Classic, the attack happens over several hours.
To prevent a reentrancy attack, we need to modify the vulnerable smart contract to follow the best practices for secure smart contract development. In this case, we should implement the "checks-effects-interactions" pattern as in the code below.
In this fixed version, we've introduced an isLocked mapping to track whether a particular account is in the process of a withdrawal. When a user initiates a withdrawal, the contract checks if their account is locked (!isLocked[msg.sender]), indicating that no other withdrawal from the same account is currently in progress.
If the account isn't locked, the contract continues with the state change and external interaction. After the state change and external interaction, the account is unlocked again, allowing future withdrawals.
Generally, there are three main types of reentrancy attacks based on their nature of exploitation.
Reentrancy attacks can manifest in different forms and so require specific measures to prevent each.
Reentrancy attacks have caused substantial financial losses and undermined trust in blockchain applications. To protect contracts, developers must adopt best practices diligently to avoid reentrancy vulnerabilities.
They should also implement secure withdrawal patterns, use trusted libraries, and conduct thorough audits to fortify the smart contract's defense further. Of course, staying informed about emerging threats and being proactive with security efforts can ensure they uphold blockchain ecosystems' integrity too.
Visit link:
What Is a Reentrancy Attack and How Does It Work? - MUO - MakeUseOf
- Smart Contracts Are Coming Soon to Dogecoin. Is It Time to Reconsider the World's Most Popular Meme Coin? - The Motley Fool - October 10th, 2026 [October 10th, 2026]
- Aptos Unveiled the MonoMove Update: Smart Contracts Will Run Up to 55 Times Faster - Incrypted - October 10th, 2026 [October 10th, 2026]
- AI Agents, Smart Contracts and Token Launches: How It All Works - Brave New Coin - October 6th, 2026 [October 6th, 2026]
- New AI Memecoin projects in 2026: How trend discovery and smart contracts are changing launches today - Latest news from Azerbaijan - October 6th, 2026 [October 6th, 2026]
- Smart Contracts Emerge as the Key Driver of Blockchain Adoption in Food Supply Chains - Bioengineer.org - October 6th, 2026 [October 6th, 2026]
- Aztec: Private Smart Contracts Settling to Ethereum Are Live - 21 Sep 2026 - TradingView - September 22nd, 2026 [September 22nd, 2026]
- AI Agents and Smart Contracts Could Secure and Speed Last-Mile Medicine Delivery - bioengineer.org - September 13th, 2026 [September 13th, 2026]
- Buterin Says Ethereum's Most Valuable Feature Is Not Smart Contracts - It's A Public Database - yellow.com - September 13th, 2026 [September 13th, 2026]
- Ethereums plan to triple network speed could silently break millions of existing smart contracts - CryptoSlate - August 29th, 2026 [August 29th, 2026]
- Pi Network News: Smart Contracts Go Live on Testnet, Will Pi Price Breakout? - CryptoRank - August 29th, 2026 [August 29th, 2026]
- Pi Network News: Smart Contracts Go Live on Testnet, Will Pi Price Breakout? - Coinpedia - August 29th, 2026 [August 29th, 2026]
- Pyth Networks API overhaul threatens to freeze unpatched smart contracts across 300 DeFi protocols - CryptoSlate - August 27th, 2026 [August 27th, 2026]
- DeadLock Ransomware Uses Polygon Smart Contracts to Make Extortion Infra Harder to Disrupt - The Hacker News - August 12th, 2026 [August 12th, 2026]
- What are blockchain oracles and why smart contracts cannot work without them - Crypto News - August 12th, 2026 [August 12th, 2026]
- ErrTraffic MaaS Hides Malware Infrastructure in Polygon Blockchain Smart Contracts - cyberpress.org - August 12th, 2026 [August 12th, 2026]
- Microsoft Exposes BNB Smart Chain Contracts Used to Deliver Malware Instructions - CryptoRank - August 11th, 2026 [August 11th, 2026]
- Microsoft Identifies Malware Threat Using BNB Chain Smart Contracts to Hide Attack Commands - Crowdfund Insider - August 11th, 2026 [August 11th, 2026]
- What Are Smart Contracts? A Deep Dive Into Their Tech Stack & Integrations - community.nasscom.in - August 5th, 2026 [August 5th, 2026]
- Smart Contracts Market Projected to Hit USD 19.51 Billion at a 21.5% CAGR by 2035 - EIN News - August 5th, 2026 [August 5th, 2026]
- How Smart Contracts Work: Key Concepts and Real-World Applications - Nasscom - July 21st, 2026 [July 21st, 2026]
- Ethereum Foundation AI Agent Research Shows Where Smart Contracts May Be Heading Next - CryptoRank - July 13th, 2026 [July 13th, 2026]
- Injective MCP server lets AI agents deploy smart contracts with a simple prompt - Crypto Briefing - July 7th, 2026 [July 7th, 2026]
- Crypto hacks hit a record count but the biggest threat isnt smart contracts - CryptoSlate - July 7th, 2026 [July 7th, 2026]
- Crypto hacks hit a record count but the biggest threat isnt smart contracts - CryptoRank - July 7th, 2026 [July 7th, 2026]
- Deprecated Aztec Connect contract exploited for $2.19M, exposing risks of inactive smart contracts - Pluang - June 19th, 2026 [June 19th, 2026]
- Circle unveils Arc Privacy to bring confidential smart contracts to institutions - crypto.news - June 16th, 2026 [June 16th, 2026]
- The Role Of Oracles In Defi: Unlock the Power of Smart Contracts! - Coin Bureau - June 16th, 2026 [June 16th, 2026]
- Learn Ethereum: Smart Contracts and dApps - Blockchain Council - June 12th, 2026 [June 12th, 2026]
- A Professional Guide to Smart Contracts and Decentralized Applications - Nasscom - June 12th, 2026 [June 12th, 2026]
- Can AI Write Secure Smart Contracts? Opportunities, Limitations, and Best Practices - Blockchain Council - June 5th, 2026 [June 5th, 2026]
- Smart contracts in South Africa: Legal recognition, challenges and the future of automated agreements - Polity.org.za - June 5th, 2026 [June 5th, 2026]
- Beyond the Dotted Line: Analysing the Legal and Regulatory Framework of Smart Contracts in India. - Legal Service India - June 5th, 2026 [June 5th, 2026]
- Legal and Compliance Considerations for Smart Contracts: Enforceability, Liability, and On-Chain Governance - Blockchain Council - June 5th, 2026 [June 5th, 2026]
- Smart Contracts for C&C: How ClearFake Hid in Plain Sight on BSC Testnet - TrendMicro - May 27th, 2026 [May 27th, 2026]
- Leading Industry Participants Reinforcing Their Presence in the Smart Contracts Market - openPR.com - May 20th, 2026 [May 20th, 2026]
- Solidity vs Rust for Smart Contracts (Ethereum vs Solana) - Blockchain Council - May 20th, 2026 [May 20th, 2026]
- Smart Contracts Explained: Automating Trust - Blockchain Council - May 20th, 2026 [May 20th, 2026]
- Ethereum leads in smart contracts with diverse uses; XRP targets institutional payments with higher risk-reward. - Pluang - May 20th, 2026 [May 20th, 2026]
- Beyond the Blockchain: Smart Contracts and Advanced Cryptocurrency Uses - Omaha World-Herald - May 7th, 2026 [May 7th, 2026]
- PI Network Price Prediction: Protocol 23 Smart Contracts Arrive in May While PEPETO Presale Secures $9.5 Million - openPR.com - May 7th, 2026 [May 7th, 2026]
- The Intersection of AI and Smart Contracts is Entering a Defining Moment of Chaos - Tekedia - May 7th, 2026 [May 7th, 2026]
- Pi Network News: Protocol 22 Activated as Network Prepares for Smart Contracts on May 11 - Coinpedia - May 7th, 2026 [May 7th, 2026]
- PI remains in red despite the launch of smart contracts on testnet - TradingView - April 25th, 2026 [April 25th, 2026]
- PI remains in red despite the launch of smart contracts on testnet - Invezz - April 25th, 2026 [April 25th, 2026]
- Vaults or NonCustodial Smart Contracts are Pooling Deposits into YieldGenerating Strategies : Analysis - Crowdfund Insider - April 17th, 2026 [April 17th, 2026]
- Lithosphere Advances AI-Native Smart Contracts with Lithic Execution Model - TMX Newsfile - April 17th, 2026 [April 17th, 2026]
- Pi Network Roadmap v21 to v23 Explained: From Stability to Smart Contracts and Full Web3 Utility - MEXC - April 17th, 2026 [April 17th, 2026]
- Pi Network Signals Smart Contracts and DEX With V23 Upgrade - Coinfomania - April 17th, 2026 [April 17th, 2026]
- Pi Network Smart Contracts with Rust and Soroban: How Programmable Finance Is Shaping the Future of Web3 - MEXC - April 12th, 2026 [April 12th, 2026]
- The Future Of DAO Treasury Management: Automation, Smart Contracts, And AI-Driven Allocation - Outlook India - April 10th, 2026 [April 10th, 2026]
- Blockchain for Intellectual Property Protection Market Research Report 2025: Immutable Records, Smart Contracts, and Tokenization, Addressing... - April 10th, 2026 [April 10th, 2026]
- AI + Smart Contracts: Safe Automation with Oversight - Blockchain Council - April 10th, 2026 [April 10th, 2026]
- Polymarket overhauls trading engine, smart contracts to introduce in-house stablecoin - - April 10th, 2026 [April 10th, 2026]
- Smart Contracts, Tokens, and a May Deadline: Pi Networks 2026 Roadmap Is Here - Coinpedia Fintech News - March 26th, 2026 [March 26th, 2026]
- Dogecoin (DOGE) Runs on 22 Developers and Zero Smart Contracts, Analysts Point to AI Trading Protocols - openPR.com - March 26th, 2026 [March 26th, 2026]
- Chicago Bears hand out smart contracts to sign high-impact free agents with limited salary cap space - WKYC - March 11th, 2026 [March 11th, 2026]
- DataVault AI and Wellgistics Health Announce Plans to Expand Partnership to Include Healthcare Delivery Intellectual Property for Healthcare as a... - February 27th, 2026 [February 27th, 2026]
- AI Meets Smart Contracts: The Next Phase Of Automation On The Blockchain - Outlook India - February 27th, 2026 [February 27th, 2026]
- World Liberty Financial: Zero smart contracts were affected. All USD1 funds remain completely safe, secure, and fully backed - marketscreener.com - February 27th, 2026 [February 27th, 2026]
- Interview with Haseeb, Managing Partner at Dragonfly: AI Armageddon Is Still Far Off; Smart Contracts Are Laws Designed for Machines - TechFlow - February 27th, 2026 [February 27th, 2026]
- The Role of Smart Contracts in Future Betting Infrastructure - bitrates.com - February 9th, 2026 [February 9th, 2026]
- Litecoin price prediction for 2040: LitVM smart contracts and halvings target $500 - Traders Union - February 9th, 2026 [February 9th, 2026]
- A Beginners Guide to Smart Contracts in Todays Web3 Economy - Nasscom - February 9th, 2026 [February 9th, 2026]
- Litecoin price prediction for 2027: July halving and LitVM smart contracts eye $150 - Traders Union - February 9th, 2026 [February 9th, 2026]
- What Happens When You Mix Smart Contracts With Artificial Intelligence 01/28/2026 - MediaPost - February 2nd, 2026 [February 2nd, 2026]
- Ethereum Chose Smart Contracts, Solana Chose Speed Why Bitcoin Everlight Is Focusing on Payments - Cryptopolitan - February 2nd, 2026 [February 2nd, 2026]
- Smart Contracts Under the Microscope: What Recent Audits Are Revealing - vocal.media - February 1st, 2026 [February 1st, 2026]
- REVOX joins TOYUSD1 to boost decentralized gaming via smart contracts - MSN - January 20th, 2026 [January 20th, 2026]
- Polygon smart contracts under attack, but the real danger may be just starting! - AMBCrypto - January 18th, 2026 [January 18th, 2026]
- Melento and Forrester reveal how smart contracts drive risk, compliance, and revenue insights - Mediabrief.com - January 18th, 2026 [January 18th, 2026]
- The father of smart contracts: supports X revoking access permissions to InfoFi application APIs; Kaito and other incentive-based content platforms... - January 18th, 2026 [January 18th, 2026]
- HIP-1249: Enhanced smart contracts on Hedera with precise throttling - Hedera - January 16th, 2026 [January 16th, 2026]
- 'Imagination the limit': DeadLock ransomware gang using smart contracts to hide their work - theregister.com - January 16th, 2026 [January 16th, 2026]
- Caixin: Digital RMB smart contracts differ from Ethereum smart contracts and are not built on a blockchain network. - Bitget - January 9th, 2026 [January 9th, 2026]
- Ethereum developer activity hits record high, with 8.7 million smart contracts deployed in Q4 2025 - Bitget - January 9th, 2026 [January 9th, 2026]
- Ethereum Deploys Record 8.7 Million Smart Contracts In Q4 2025, Breaking 2021 High - Yellow.com - January 4th, 2026 [January 4th, 2026]
- Ethereum Smart Contracts Shatter Records: 8.7M Deploy in Q4 - Live Bitcoin News - December 31st, 2025 [December 31st, 2025]
- What Are Smart Contracts? Transforming Digital Industries & Trust - Outlook India - December 31st, 2025 [December 31st, 2025]
- What Are Smart Contracts and How Do They Work? - Blockchain Council - December 27th, 2025 [December 27th, 2025]
- The Mechanics of Smart Contracts: From Conditions to Automatic Execution - vocal.media - December 22nd, 2025 [December 22nd, 2025]