Skip to content

Latest commit

 

History

History
89 lines (62 loc) · 4.42 KB

076.md

File metadata and controls

89 lines (62 loc) · 4.42 KB

Glamorous Plum Baboon

High

Reentrancy Vulnerabilities in State-Dependent Functions

Summary

The ValidationLogic:validateSupply, ValidationLogic:validateWithdraw, ValidationLogic:validateBorrow, and ValidationLogic:validateRepay functions are vulnerable to potential reentrancy attacks because they rely on state-dependent values like supplyCap, scaledTotalSupply, and debt. If external calls are made before or during state changes, especially when interacting with non-reentrant tokens, reentrancy attacks could be exploited to manipulate state inconsistencies and cause unauthorized actions.


Description

The aforementioned functions perform critical validation checks based on reserve state variables (supplyCap, scaledTotalSupply, debt, etc.) to determine whether the operation should be allowed. However, due to the absence of reentrancy protection mechanisms, if these functions or related ones indirectly invoke external calls (e.g., transferring tokens or calling external contracts), an attacker could exploit reentrancy to manipulate the contract state.

For example: i, During a validateWithdraw, an attacker could trigger reentrant calls to manipulate scaledTotalSupply or supplyCap to bypass the validation logic. ii, Similarly, during a validateBorrow, an attacker could reenter to adjust their debt and bypass debt threshold validation.

This type of vulnerability is particularly concerning if these functions are used in conjunction with external calls or non-reentrant tokens.


Root Cause

The root cause lies in the lack of reentrancy protection for the functions that rely on state-dependent values and the potential for external calls to occur during execution. Below are the lines of concern for each function:

i, validateSupply: Usage of supplyCap and scaledTotalSupply in validation logic ii,validateWithdraw: Dependency on scaledTotalSupply to determine supply thresholds iii, validateBorrow: Dependency on debt and other reserve state variables iv, validateRepay: Involves state checks for debt repayment


https://github.com/sherlock-audit/2025-01-aave-v3-3/blob/main/aave-v3-origin/src/contracts/protocol/libraries/logic/ValidationLogic.sol#L66-L88


https://github.com/sherlock-audit/2025-01-aave-v3-3/blob/main/aave-v3-origin/src/contracts/protocol/libraries/logic/ValidationLogic.sol#L96-L128


https://github.com/sherlock-audit/2025-01-aave-v3-3/blob/main/aave-v3-origin/src/contracts/protocol/libraries/logic/ValidationLogic.sol#L287-L309


Impact

If exploited, reentrancy vulnerabilities could lead to the following impacts:

  1. Unauthorized withdrawals or borrows exceeding supply caps or debt thresholds.
  2. Manipulation of reserve state values, causing the protocol to enter an inconsistent or exploitable state.
  3. Financial loss to the protocol and its users due to malicious exploitation of validation logic.

Proof of Concept (PoC)

Below is a simplified PoC illustrating how reentrancy could exploit validateWithdraw:

  1. An attacker supplies assets to the protocol and obtains a supply balance.
  2. The attacker initiates a withdraw transaction.
  3. Before scaledTotalSupply is updated or validated, the attacker triggers a reentrant call using a token contract that calls back into the protocol, supplying additional tokens or withdrawing tokens.
  4. The state values (scaledTotalSupply) are manipulated during the reentrant call, allowing the attacker to withdraw more than their legitimate share.

Code snippet:

contract ReentrantToken {
    function transfer(address to, uint256 amount) public returns (bool) {
        if (!reentered) {
            reentered = true;
            protocol.validateWithdraw(amount); // Reentrancy trigger
        }
        return true;
    }
}

Recommended Mitigation

  1. Use a Reentrancy Guard: Add the ReentrancyGuard modifier from OpenZeppelin’s library to the affected functions (validateSupply, validateWithdraw, validateBorrow, validateRepay) to prevent nested calls.

    function validateWithdraw(uint256 amount) external nonReentrant {
        // Validation logic here
    }
  2. Minimize External Calls: Structure the contract logic to perform external calls only after all state changes are completed.

By implementing the above measures, Aave protocol can mitigate the risk of reentrancy attacks and ensure the robustness of its validation logic.