Skip to content

Latest commit

 

History

History
70 lines (47 loc) · 3.86 KB

069.md

File metadata and controls

70 lines (47 loc) · 3.86 KB

Glamorous Plum Baboon

High

Potential Overflow in Shift Operations

Summary

The usage of masks and constants such as MAX_VALID_BORROW_CAP and MAX_VALID_SUPPLY_CAP involves large bit shift operations that may result in overflows. These overflows could compromise the contract's intended behavior, especially if the values are improperly validated or altered during future code changes.

Description

Bit shift operations (<<, >>) are used to manipulate binary representations of data, often for setting or extracting specific bits. In this codebase, masks and constants leverage large bit shifts for encoding limits. If these operations exceed the maximum allowable value for their respective data types (e.g., uint256), they can result in overflows. Such overflows can lead to incorrect values being used in calculations or stored, potentially introducing security vulnerabilities or operational inconsistencies.

Without validation to ensure the safety of bitwise operations and boundary conditions, future changes to constants or the introduction of new logic could unintentionally trigger this issue. Additionally, the absence of robust tests to capture regressions could lead to undetected issues during development.

Root Cause

The root cause lies in the improper handling or validation of bit shift operations when defining masks or constants. For example:

uint256 constant MAX_VALID_BORROW_CAP = 1 << 256;  // Unsafe: Shifts beyond uint256 boundaries
uint256 constant MAX_VALID_SUPPLY_CAP = 1 << 255; // Unsafe if misused or altered

https://github.com/sherlock-audit/2025-01-aave-v3-3/blob/main/aave-v3-origin/src/contracts/protocol/libraries/configuration/ReserveConfiguration.sol#L12-L65

Improper use of masks and bit positions in setter functions like setLtv, setLiquidationThreshold, and others https://github.com/sherlock-audit/2025-01-aave-v3-3/blob/main/aave-v3-origin/src/contracts/protocol/libraries/configuration/ReserveConfiguration.sol#L73-L77

https://github.com/sherlock-audit/2025-01-aave-v3-3/blob/main/aave-v3-origin/src/contracts/protocol/libraries/configuration/ReserveConfiguration.sol#L93-L102

Impact

  1. Overflow Risks: Overflows in shift operations can corrupt data representations, leading to incorrect results in contract logic.
  2. Operational Errors: Limits such as borrow caps or supply caps could be improperly calculated, resulting in unintended behaviors (e.g., allowing excess borrowing or supply).
  3. Security Vulnerabilities: Malicious actors could potentially exploit improper boundaries, leveraging the overflowed values to manipulate contract behavior.

Proof of Concept (PoC)

Consider the following snippet:

// Current implementation
uint256 constant MAX_VALID_BORROW_CAP = 1 << 256; // Causes overflow to 0
uint256 constant MAX_VALID_SUPPLY_CAP = 1 << 255; // Valid in uint256 but risky if misused

A test case demonstrating overflow:

function testOverflowInShiftOperations() public {
    uint256 borrowCap = 1 << 256; // This overflows to 0
    assert(borrowCap == 0);       // Assertion passes, showing overflow
}

This could lead to bypasses in contract logic where MAX_VALID_BORROW_CAP is used for boundary checks.

Recommended Mitigation

  1. Validation of Shift Operations: Ensure that bit shifts are within the valid range for the target data type (e.g., uint256 or uint8). For instance:
    require(shiftAmount < 256, "Shift amount exceeds uint256 boundary");
  2. Use Safe Constants: Avoid relying on hardcoded shifts that might overflow. Instead, calculate constants safely:
    uint256 constant MAX_VALID_BORROW_CAP = type(uint256).max >> 1; // Avoids overflow

By addressing these issues, the contract will mitigate the risks associated with bit shift operations, ensuring safer and more predictable behavior.