DEV Community

Nexus Intelligence Research
Nexus Intelligence Research

Posted on

DeFi Smart Contract Vulnerabilities Audit Guide

Here are three specific DeFi smart contract vulnerabilities commonly identified in audit reports, described with technical precision suitable for a professional security audit document.

1. Reentrancy via Unchecked External Calls

CWE-841: Improper Enforcement of Behavioral Workflow

Description:

The withdraw() function in the lending pool contract allows users to retrieve their deposited assets. The contract updates the user’s internal balance record before executing the external call to transfer ETH or ERC-20 tokens. Because the external call (msg.sender.transfer(amount)) triggers the user’s fallback or receive function, a malicious contract can re-enter the withdraw() function before the original execution context completes.

Example Vulnerable Snippet (Solidity):


solidity
function withdraw(uint256 amount) external {
    require(balances[msg.sender] >= amount, "Insufficient balance");
    balances[msg.sender] -= amount; // State change BEFORE external
Enter fullscreen mode Exit fullscreen mode

Top comments (0)