Here are three of the most common and critical DeFi smart contract vulnerabilities, along with specific methods for detecting them.
1. Reentrancy Attack
Description:
A reentrancy attack occurs when a smart contract makes an external call to an untrusted contract before updating its internal state. The external contract can then re-enter the vulnerable function, bypassing the state update and draining funds. This was famously exploited in the 2016 Ethereum DAO hack.
Vulnerability Pattern:
function withdraw() public {
require(balances[msg.sender] > 0, "Insufficient balance");
uint256 amount = balances[msg.sender];
(bool success, ) = msg.sender.call{value: amount}(""); // External call before state update
require(success, "Transfer failed");
balances[msg.sender] = 0; // State update after external call
}
**
Top comments (0)