Here are three common DeFi smart contract vulnerabilities, along with specific detection methods and tools:
1. Reentrancy
Description:
An attacker calls a contract function that sends ETH or tokens to an external contract (e.g., transfer or call). Before the state update (e.g., balance deduction) is completed, the external contract re-enters the same function, allowing the attacker to manipulate state multiple times.
How to Detect:
-
Static Analysis Tools:
-
Slither: Use the
reentrancydetector. It flags functions that perform external calls (call,delegatecall,send,transfer) before updating state variables.
-
Slither: Use the
python
# Example Slither output
[Medium] Reentrancy in Function:
- Contract: `MyToken`
- Function: `withdraw(uint256)`
- External call: `address.transfer(amount)`
Top comments (0)