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
- 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]
- Understanding Ethereums Role in Creating and Deploying Smart Contracts - aberdeennews.com - December 18th, 2025 [December 18th, 2025]
- Interpreting and vetting smart contracts: utilising blockchain manipulations and crypto currency fraud - Penningtons Manches Cooper - December 10th, 2025 [December 10th, 2025]
- Smart Contracts: Enhancing Security, Trust, and Automation in Modern Digital Platforms - vocal.media - December 5th, 2025 [December 5th, 2025]
- AI has successfully simulated the theft of $4.6 million and has learned to autonomously attack smart contracts. - PANews - December 5th, 2025 [December 5th, 2025]
- AI-Native Smart Contracts Are No Longer TheoryThey Just Became Real - Hackernoon - December 5th, 2025 [December 5th, 2025]
- How Do Smart Contracts Work And Why Are They Critical For Secure Blockchain Systems? - Outlook India - December 5th, 2025 [December 5th, 2025]
- How automation, smart contracts and AI are reshaping property law - lawnews.nz - December 2nd, 2025 [December 2nd, 2025]
- TBC: Revolutionizing Bitcoin With UTXO Smart Contracts and Cross-Chain Innovation - Bitcoin.com News - December 2nd, 2025 [December 2nd, 2025]
- What Are Smart Contracts In Crypto: Uses, Risks, And Benefits - Traders Union - December 2nd, 2025 [December 2nd, 2025]
- Blockchain and Smart Contracts Are Reshaping the Future of Online Casinos in Australia - Australian Manufacturing Forum - November 30th, 2025 [November 30th, 2025]
- DataVault AI licenses smart contracts tech to Wellgistics Health - Investing.com - November 26th, 2025 [November 26th, 2025]
- How Blockchain Security and Smart Contracts Are Helping Reduce Fraud and Increase Trust in Online Casinos - BlockchainReporter - November 23rd, 2025 [November 23rd, 2025]
- Certora Launches the First Safe AI Coding Platform for Smart Contracts By Chainwire - Investing.com - November 23rd, 2025 [November 23rd, 2025]
- AgriFi Democratizes Farming Profits through Tokenized Agriculture and Smart Contracts - StreetInsider - November 11th, 2025 [November 11th, 2025]
- Smart Contracts on Tron vs. Smart Contracts on Ethereum: Which Is the Best Choice? - The Gila Herald - November 11th, 2025 [November 11th, 2025]
- Game Changer For Crypto Smart Contracts - Sovereign Wealth Fund Institute | SWFI - November 11th, 2025 [November 11th, 2025]
- AI & Crypto 2025: Machine Learning, DeFi Innovation, and Smart Contracts with AI - Bitcoinsensus - November 11th, 2025 [November 11th, 2025]
- Klever Blockchain Update: KVM Becomes the New Execution Layer for Smart Contracts - The Defiant - November 3rd, 2025 [November 3rd, 2025]
- Noomez vs Other Presales: The Clear Advantages of $NNZs Audited Smart Contracts and Price Progression - Live Bitcoin News - November 3rd, 2025 [November 3rd, 2025]
- North Korean Hackers Are Using BNB And Ethereum Smart Contracts To 'Bulletproof' Crypto-Stealing Malware, Google Says - Yahoo Finance - October 28th, 2025 [October 28th, 2025]
- How Banks Can Fend Off the Twin Threat of Stablecoins and Smart Contracts to Business Payments - The Financial Brand - October 28th, 2025 [October 28th, 2025]
- Klever Blockchain Update: KVM Becomes the New Execution Layer for Smart Contracts - Brave New Coin - October 28th, 2025 [October 28th, 2025]
- Giggle Academy: Has never issued any tokens or smart contracts - Bitget - October 26th, 2025 [October 26th, 2025]
- AI-powered digital arbitration framework leveraging smart contracts and electronic evidence authentication - Nature - October 24th, 2025 [October 24th, 2025]
- Smart Contracts in Blockchain: What They Are and How They Work - Crypto.com - October 23rd, 2025 [October 23rd, 2025]
- North Korean hackers embedded malware in Ethereum and BNB smart contracts - Invezz - October 23rd, 2025 [October 23rd, 2025]
- Rewriting Blockchain Privacy: The Dawn of Private Smart Contracts with Zero Knowledge Proof - Digital Journal - October 21st, 2025 [October 21st, 2025]
- DPRK and EtherHiding: UNC5342 hides malware in smart contracts on Ethereum and BNB Smart Chain - Bitcoinsensus - October 19th, 2025 [October 19th, 2025]
- Smart Contracts on the Blockchain: What They Are, How They Work, and Examples - Nasscom - October 19th, 2025 [October 19th, 2025]
- What is EtherHiding? Google flags malware with crypto-stealing code in smart contracts - Cointelegraph - October 19th, 2025 [October 19th, 2025]
- UNC5142 Exploits Blockchain Smart Contracts to Distribute Info-Stealing Malware Across Windows and macOS - CXO Digitalpulse - October 19th, 2025 [October 19th, 2025]
- Nexchain Nears Final Integration Phase Before Testnet 2.0 Launch: Backend, Smart Contracts, Airdrop & More - Crypto Economy - October 17th, 2025 [October 17th, 2025]
- Hackers Abuse Blockchain Smart Contracts to Spread Malware via Infected WordPress Sites - The Hacker News - October 17th, 2025 [October 17th, 2025]
- North Korean Hackers Use EtherHiding to Hide Malware Inside Blockchain Smart Contracts - The Hacker News - October 17th, 2025 [October 17th, 2025]
- Introducing Smart Contracts to Federated Learning: How Flock is Reshaping AI Production Relationships? - Bitget - October 17th, 2025 [October 17th, 2025]
- Private Smart Contracts at Scale: Zero Knowledge Proof Is the dApp Platform You'll Wish You Saw Earlier - openPR.com - October 15th, 2025 [October 15th, 2025]
- DHS, CBP award $4.5B in new contracts under OBBB for Smart Wall construction along southwest border - The Gila Herald - October 15th, 2025 [October 15th, 2025]
- Bay Miner Unveils Innovative App with AI and Smart Contracts Driving Daily BTC and XRP Earnings - openPR.com - October 13th, 2025 [October 13th, 2025]
- How Ethereum Smart Contracts Work and Why They Matter - vocal.media - October 11th, 2025 [October 11th, 2025]
- *Ethereum is still the king of smart contracts and crypto tech.* --- Let me know if you want this - Binance - October 9th, 2025 [October 9th, 2025]
- Smart Contracts and the Crypto Economy Safeguarding Your Investments - OneSafe - October 7th, 2025 [October 7th, 2025]
- How is Avalanche Changing the Game with Smart Contracts? - OneSafe - October 7th, 2025 [October 7th, 2025]
- AI and Smart Contracts Drive Bay Miner Cloud Mining App for More Efficient Daily BTC and ETH Earnings - Azat TV - October 7th, 2025 [October 7th, 2025]
- The Avalanche ecosystem is growing rapidly the number of smart contracts has tripled! - Pintu - October 7th, 2025 [October 7th, 2025]
- Blockchain and Smart Contracts: Redefining Transparency in Online Gaming Platforms - Techloy - October 4th, 2025 [October 4th, 2025]
- Smart Contracts Software Market to Reach USD 21.4 billion - openPR.com - October 4th, 2025 [October 4th, 2025]
- Red Wings smart contracts just aged beautifully thanks to Wild - Octopus Thrower - October 2nd, 2025 [October 2nd, 2025]
- How Smart Contracts and Blockchain Transactions Are Revolutionizing Industries: Insights from Machi - OKX - September 28th, 2025 [September 28th, 2025]
- From Surfboards to Smart Contracts: The Relentless Rise of Juan Mari - Block Telegraph - September 23rd, 2025 [September 23rd, 2025]
- Hackers Just Found A Way To Hide Malware In Ethereum Smart Contracts And Your Crypto Wallet Could Be Next - Yahoo Finance - September 17th, 2025 [September 17th, 2025]
- Green Computing Power + Smart Contracts: EARN Mining Mobile Cloud Mining Ensures Sustainable Daily Settlement for BTC and XRP - Nation Thailand - September 13th, 2025 [September 13th, 2025]
- How Are Smart Contracts Transforming Decentralized Autonomous Organizations? - Nasscom - September 9th, 2025 [September 9th, 2025]
- Ethereum Smart Contracts Become Latest Hiding Spot For Malware - Mitrade - September 9th, 2025 [September 9th, 2025]
- Cybercriminals are trolling developers by hiding malware in Ethereum smart contracts - Cybernews - September 6th, 2025 [September 6th, 2025]
- How Hackers Use Ethereum Smart Contracts to Hide Malware in Plain Sight - Cointribune - September 6th, 2025 [September 6th, 2025]