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
- 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]
- Malicious npm Packages Exploit Ethereum Smart Contracts to Target Crypto Developers - The Hacker News - September 5th, 2025 [September 5th, 2025]
- Ethereum Smart Contracts Abused to Hide npm Malware - Bitcoinsensus - September 5th, 2025 [September 5th, 2025]
- Hackers Use Ethereum Smart Contracts to Hide Malware in npm Packages - CoinCentral - September 5th, 2025 [September 5th, 2025]
- Hackers find new way to hide malware in Ethereum smart contracts - Cointelegraph - September 5th, 2025 [September 5th, 2025]
- AI, Blockchain, and smart contracts: Why Utah businesses cant afford to wait - Utah Business - September 5th, 2025 [September 5th, 2025]
- A Blockchain Framework Using Proof of Authority and Smart Contracts for Ethical and Secure Healthcare Asset Management - Frontiers - September 5th, 2025 [September 5th, 2025]
- Ethereum (ETH) News: Attackers Are Now Using Ether Smart Contracts to Mask Malware - CoinDesk - September 5th, 2025 [September 5th, 2025]
- News Explorer ReversingLabs Uncovered NPM Packages Using Ethereum Smart Contracts to Disseminate Malware in a GitHub Campaign - Decrypt - September 5th, 2025 [September 5th, 2025]
- Researchers Find Ethereum Smart Contracts Used to Deliver Malware - Crypto Economy - September 5th, 2025 [September 5th, 2025]
- Ethereum News Today: Malware Hiding in Ethereum Smart Contracts Rears Its Head - AInvest - September 5th, 2025 [September 5th, 2025]
- New Way to Hide Hacking Software in Ethereum Smart Contracts - Happy Coin News - September 5th, 2025 [September 5th, 2025]
- Ethereum smart contracts infected with the virus are distributed via NPM and GitHub - ITC.ua - September 5th, 2025 [September 5th, 2025]
- The Evolution of NFT Smart Contracts: From Art to Real-World Assets - Vocal - September 3rd, 2025 [September 3rd, 2025]
- Bitcoin Gets Ethereum-Style Smart Contracts with BRC-2.0 Upgrade - The Defiant - September 3rd, 2025 [September 3rd, 2025]
- How Do Limitations Affect The Use Of Smart Contracts In Finance? - Outlook India - September 3rd, 2025 [September 3rd, 2025]
- Google Unveils Layer 1 Chain for Banks with Python-based Smart Contracts - The Defiant - August 29th, 2025 [August 29th, 2025]
- The Role of Smart Contracts in Decentralized Applications - Vocal - August 29th, 2025 [August 29th, 2025]
- DeFi and NFT: The Dual Impact of Smart Contracts on Blockchain - Vocal - August 29th, 2025 [August 29th, 2025]
- Ethereum News Today: Ethereum's Wall Street Takeover: Why Banks Bet Big on Smart Contracts - AInvest - August 29th, 2025 [August 29th, 2025]
- What Role Do Smart Contracts And Governance Tokens Play In DAOs? - Outlook India - August 29th, 2025 [August 29th, 2025]
- Ethereum News Today: Ethereum's Smart Contracts Outpace Bitcoin in AI Finance Race - AInvest - August 27th, 2025 [August 27th, 2025]
- Ethereum News Today: The Battle of Blockchain Philosophies: Speed vs. Security in Smart Contracts - AInvest - August 26th, 2025 [August 26th, 2025]
- AI-Driven Smart Contracts in Crypto: Navigating Legal Risks and Seizing Strategic Opportunities - AInvest - August 24th, 2025 [August 24th, 2025]
- How Transforming Industries in 2025: The Power of Smart Contracts - Vocal - August 22nd, 2025 [August 22nd, 2025]
- Flow Q2 DeFi Report: Record growth in TVL, smart contracts, and Disney partnership - FXStreet - August 22nd, 2025 [August 22nd, 2025]
- Institutional Capital's New Playground: Why Ethereum's Smart Contracts Are Winning Over Bitcoin - AInvest - August 22nd, 2025 [August 22nd, 2025]
- Federal Reserve Examines Tokenization, Smart Contracts, and AI for Payments - CoinCentral - August 22nd, 2025 [August 22nd, 2025]
- Sports Stars and Smart Contracts: How BlockDAG and ADA Are Rewriting the Crypto Playbook - AInvest - August 22nd, 2025 [August 22nd, 2025]
- Fed is studying tokenization, smart contracts, and AI in payments, says Governor Waller - Crypto Briefing - August 20th, 2025 [August 20th, 2025]
- Fed's Waller: Fed researching tokenization, smart contracts, and AI in payments - MSN - August 20th, 2025 [August 20th, 2025]
- Before Ethereum Had Smart Contracts, It Had Believers Lyno AI Finds Its Own Early Supporters - Live Bitcoin News - August 20th, 2025 [August 20th, 2025]
- Fed Seeks Tech-Driven Payment Revolution: AI, Stablecoins, and Smart Contracts Take Center Stage - AInvest - August 20th, 2025 [August 20th, 2025]
- Ethereum News Today: Ethereum's Smart Contracts Rewrite FinanceInstitutional Bet on Blockchain's Future - AInvest - August 20th, 2025 [August 20th, 2025]
- Smart contracts have dumb insurance, and it's hurting the industry - Cointelegraph - August 20th, 2025 [August 20th, 2025]
- XRP News Today: SolMining Launches XRP-Powered Smart Contracts for Passive Income with Fixed Returns - AInvest - August 9th, 2025 [August 9th, 2025]
- Threat Actors Exploit Smart Contracts to Drain Over $900K from Crypto Wallets - gbhackers.com - August 7th, 2025 [August 7th, 2025]
- Powering Trust: The Secure, Automated, and Transparent Technology Behind Sunny Minings XRP Smart Contracts - StreetInsider - August 6th, 2025 [August 6th, 2025]
- Sunny Mining : From Airdrop Rewards to Smart Contracts - The Profit Toolkit of XRP Mining - openPR.com - August 3rd, 2025 [August 3rd, 2025]
- AMMs Reshape DeFi Trading with Smart Contracts and Liquidity Pools - AInvest - August 1st, 2025 [August 1st, 2025]
- Unlocking The Power: How Smart Contracts Drive The Utility And Flexibility Of Crypto Tokens - Outlook India - August 1st, 2025 [August 1st, 2025]
- Stellar XLM Targets $3.43 by 2031 Driven by Smart Contracts and Deflationary Model - AInvest - August 1st, 2025 [August 1st, 2025]
- By 2025, over 60% of global food supply chains will use blockchain-based smart contracts for traceability. - Farmonaut - August 1st, 2025 [August 1st, 2025]
- Smart contracts and staking arrive on Bitcoins base layer - Cointelegraph - July 30th, 2025 [July 30th, 2025]
- [LIVE] Ten Years of Ethereum: From Smart Contracts to a Global Financial Layer - Cryptonews - July 30th, 2025 [July 30th, 2025]
- Ethereum (ETH) Launch Anniversary: Impact on Smart Contracts, DeFi, and Trading Strategies in 2025 - Blockchain News - July 30th, 2025 [July 30th, 2025]
- [LIVE] Ten Years of Ethereum: From Smart Contracts to a Global Financial Layer - TradingView - July 30th, 2025 [July 30th, 2025]
- Ethereum News Today: Ethereum ETFs Attract $1.85B Inflows 25-Fold Bitcoin as Institutions Shift to Smart Contracts and Regulatory Clarity - AInvest - July 28th, 2025 [July 28th, 2025]
- Beyond the XRP Price Boom: JAMining's Smart Contracts Offer Overlooked Stability in Crypto Income - International Business Times Australia - July 24th, 2025 [July 24th, 2025]
- Zama And OpenZeppelin Team Up To Deliver Confidential Smart Contracts For Institutions - BlockchainReporter - July 24th, 2025 [July 24th, 2025]
- How Smart Contracts Are Transforming 21st Century Business Operations - Vocal - July 22nd, 2025 [July 22nd, 2025]
- Which sectors are fastest adopting smart contracts development, and how can we access these markets - Vocal - July 20th, 2025 [July 20th, 2025]