Here are three common DeFi smart contract vulnerabilities, along with specific detection methods for each:
1. Reentrancy Attacks
Description:
A reentrancy attack occurs when a smart contract makes an external call (e.g., sending ETH or tokens to another contract) before updating its internal state. A malicious contract can intercept this call and re-enter the vulnerable function before the state change is committed, allowing the attacker to drain funds repeatedly.
How to Detect:
-
Static Analysis with Slither/Oyente:
- Use tools like Slither (by Trail of Bits) to identify external calls (
call,transfer,delegatecall) that occur before state variable updates. - Look for patterns where
msg.senderis called or tokens are transferred beforebalance[msg.sender]is decremented.
- Use tools like Slither (by Trail of Bits) to identify external calls (
-
Manual Code Review:
- Apply the Checks-Effects-Interactions (CEI)
Top comments (0)