Here are three of the most common and impactful DeFi smart contract vulnerabilities, along with specific methods to detect them during code review or auditing.
1. Reentrancy
Description:
Reentrancy occurs when a smart contract calls an external contract (or a function within itself) before updating its own state. If the external contract is malicious or controlled by an attacker, it can re-enter the vulnerable function in the first call, executing it multiple times before the state is updated. This can drain funds, manipulate balances, or break invariants.
How to Detect It:
-
Look for the "Check-Effects-Interactions" (CEI) pattern violation:
- ✅ Safe: Check conditions → Update internal state (e.g.,
balance[msg.sender] -= amount) → Make external call (call.value(amount)). - ❌ Vulnerable: Check conditions → Make external call → Update internal state.
- ✅ Safe: Check conditions → Update internal state (e.g.,
- **Static Analysis Tools
Top comments (0)