If you have spent any time in the cryptocurrency space, you have probably seen headlines about DeFi protocols getting hacked for millions of dollars. On September 3, 2024, Penpie — a DeFi protocol built on Pendle Finance — became the latest victim, losing approximately $27 million to a reentrancy attack. But what exactly is a reentrancy attack, and why does it keep happening? This guide breaks it down in plain language.
The Basics
A reentrancy attack is a type of smart contract vulnerability where an attacker tricks a contract into sending funds or executing actions multiple times before the contract has finished updating its internal records. Think of it like a bank teller who starts processing your withdrawal but forgets to update your account balance before handing you the cash. If you keep asking for the same withdrawal before the teller updates the ledger, you can drain the vault.
In the context of blockchain and DeFi, smart contracts are self-executing programs that run on networks like Ethereum. These contracts hold and manage cryptocurrency on behalf of users. When a vulnerability exists in how a contract handles state changes — like updating a user’s balance — attackers can exploit the gap between action and record-keeping.
Reentrancy is not a new threat. The most famous crypto hack in history — the 2016 DAO attack that resulted in the theft of approximately $60 million worth of Ethereum — was a reentrancy exploit. Despite being a well-understood vulnerability for over eight years, protocols continue to fall victim to variations of this attack.
Why It Matters
Understanding reentrancy attacks matters for anyone who uses DeFi protocols. In 2024 alone, cryptocurrency losses from hacks and exploits have surpassed $1.2 billion, with reentrancy vulnerabilities being a recurring factor. The Penpie hack on September 3, 2024, demonstrated that even protocols built on established platforms like Pendle can harbor these vulnerabilities.
For everyday users, the implications are direct: funds deposited in vulnerable protocols can be stolen with no guarantee of recovery. The Penpie attacker quickly laundered stolen funds through Tornado Cash, making recovery extremely unlikely. With Bitcoin at approximately $57,431 and Ethereum at $2,420 at the time of the attack, even a relatively small percentage loss represents significant financial harm.
Getting Started Guide
Protecting yourself from reentrancy-related losses starts with understanding which protocols you trust with your funds. Here are practical steps every DeFi user should follow:
1. Check for audits. Before depositing funds into any DeFi protocol, verify that the smart contracts have been audited by reputable security firms. Look for audit reports from firms like Trail of Bits, OpenZeppelin, or Consensys Diligence. Keep in mind that audits reduce risk but do not eliminate it — Penpie had undergone security reviews.
2. Understand the protocol’s age and track record. Newer protocols carry higher risk because their code has been tested by fewer users and for a shorter time. Protocols that have been operating for months or years without incidents have a stronger safety track record.
3. Limit your exposure. Never invest more in any single DeFi protocol than you can afford to lose. Diversifying across multiple protocols and platforms reduces the impact of any single exploit.
4. Monitor your approvals. Use tools like Revoke.cash to regularly review and clean up token approvals you have granted to DeFi protocols. Remove approvals for protocols you are no longer actively using.
5. Follow security researchers. Many vulnerabilities are discovered and disclosed by independent security researchers before they are exploited. Following reputable security analysts on social media can provide early warning of potential risks.
Common Pitfalls
The most dangerous mistake DeFi users make is assuming that a protocol is safe simply because it is popular or has been audited. The history of DeFi hacks shows that both well-known and audited protocols can be exploited.
Another common error is granting unlimited token approvals. When you interact with a DeFi protocol, you often need to approve the contract to spend your tokens. Many users blindly approve unlimited amounts for convenience. This means that if the protocol is exploited, the attacker can potentially drain all of your approved tokens — not just what you deposited in the protocol.
Falling for phishing attacks is another major risk. In August 2024, phishing scams resulted in over $63 million in losses across more than 9,000 victims. Attackers create fake websites that mimic legitimate DeFi protocols and trick users into signing malicious transactions. Always verify URLs carefully before connecting your wallet.
Next Steps
If you are new to DeFi, start by learning the fundamentals of smart contract security. Understanding concepts like reentrancy, flash loans, and oracle manipulation will help you make more informed decisions about which protocols to use. Resources like the ConsenSys Smart Contract Best Practices guide and the Solidity documentation provide excellent starting points.
Consider using security-focused browser extensions that simulate transactions before you sign them. Tools like Wallet Guard and Pocket Universe can help you identify suspicious contract interactions before they execute.
Finally, stay informed. The DeFi security landscape evolves rapidly, and staying current on the latest threats and best practices is one of the most effective ways to protect your assets in this dynamic ecosystem.
Disclaimer: This article is for educational purposes only and does not constitute financial or investment advice. Always conduct your own research before engaging with any DeFi protocol or cryptocurrency investment.
Penpie losing 27M to a reentrancy bug in 2024 is wild. the DAO hack was literally this exact exploit in 2016 and people still ship contracts without checks-effects-interactions. we have 8 years of documentation on this
the bank teller analogy is perfect. the contract hands you the money before updating the balance sheet. you ask again and the balance still shows the old number. its not complicated its just boring so teams skip the audit
the bank teller analogy is good but misses the key point. Penpie had audits. the vulnerability was in a callback function that the audit didnt flag because the auditor tested components in isolation not the integration
the bank teller analogy is perfect. finally an explainer that doesnt assume you know solidity
27M gone because of a pattern identified in 2016. the DAO hack was literally this same attack vector. how many times does the industry need to learn the same lesson
Its wild that the same vulnerability class from 2016 still works in 2024. The tools are better but teams keep making the same mistake.
same class from 2016 but the attack surface got way bigger. more contracts, more composability, more paths for reentrancy. the tools improved but so did the complexity
same vulnerability class for 8 years and teams still ship reentrancy bugs. openzeppelin has guards for this built in, you have to actively bypass them to get exploited
openzeppelin ReentrancyGuard is literally one import. there is no excuse for a 27M exploit from a bug that has a 3-line fix
audit_burner literally one import and 27M gone. the gap between audited contracts and actual deployed code is where these exploits live
Fatima Al-Rashid tools improved but teams still skip them under shipping pressure. penpie had audits too if i remember right
should add rekt.news to the reading list at the end. best place to learn from real exploits
^ rekt is legit. their post-mortems taught me more about smart contract security than any course
rekt post-mortems should be required reading for anyone deploying smart contracts. the pattern recognition from studying real exploits is invaluable
checks-effects-interactions is literally day 1 of Solidity class. how does a Pendle adjacent protocol still miss this in 2024. 27M for a freshman mistake
the bank teller analogy is good but it undersells the flash loan angle. the attacker borrowed, exploited, and repaid in one tx. traditional reentrancy didnt have that lever
checks-effects-interactions is literally day one of solidity training. at this point reentrancy bugs are negligence not ignorance
nonce_rabbit_ CEI pattern has been documented since 2016. Penpie getting hit in 2024 with a reentrancy bug means they either skipped the audit or ignored it
OpenZeppelin ReentrancyGuard is literally one import and a modifier. teams that skip it deserve to get drained honestly
Pavel M. one import and a modifier. ReentrancyGuard has been in OpenZeppelin since 2017. skipping it in 2024 is professional negligence
negligence assumes they knew. plenty of exploited protocols inherit guards from forked code then strip them for gas optimization without realizing what they deleted
inherited guards stripped for gas is exactly it. the pendle wrappers forked from a base that had the modifier three layers up and nobody diffs their fork against upstream, they just ship whatever saves 200 gas
27M from a bug class that has free prevention tools available. DeFi security culture is still fundamentally broken
27M drained from a bug class that has free prevention tools. DeFi teams keep shipping unaudited changes and acting surprised when they get clapped
the teller analogy is fine but the real lesson is incentive design. penpie offered fat APY on a wrapper contract nobody stress tested for reentry, yield farmers aped first and read audits never