Core Contracts

Regnum Aurum Acquisition Corp
HardhatReal World AssetsNFT
77,280 USDC
View results
Submission Details
Severity: medium
Invalid

Denial of Service in Manager Removal Due to Unbounded Iteration in findManagerIndex

Summary

The StabilityPool contract uses an array (managerList) to track its managers. The removal process for a manager involves iterating over this array to find the manager's index via the findManagerIndex function. If the array grows very large, this unbounded iteration can consume excessive gas, potentially causing the transaction to run out of gas and revert. This issue poses a denial-of-service (DoS) risk during manager removal, which may disrupt administrative operations.

Vulnerability Details

How It Begins

  • Manager Removal Workflow:

    • The removeManager function calls a private helper _removeManagerFromList, which in turn calls findManagerIndex to locate the manager's index in the managerList array.

    • The findManagerIndex function uses a for loop to iterate over the entire array:

      function findManagerIndex(address manager) internal view returns (uint256) {
      // @info: dos could occur if managers list becomes so big
      for (uint256 i = 0; i < managerList.length; i++) {
      if (managerList[i] == manager) {
      return i;
      }
      }
      revert ManagerNotFound();
      }
  • Issue:

    • As the managerList array grows over time (e.g., if many managers are added), the for loop will require an increasing amount of gas to complete.

    • In extreme cases, the gas required to iterate over the array may exceed the block gas limit, causing the removal function to fail and effectively resulting in a DoS condition for manager removals.

Proof of Concept

Scenario Example

  1. Setup:

    • A large number of managers are added to the StabilityPool, causing managerList to grow significantly.

  2. Manager Removal Attempt:

    • When attempting to remove a manager, the findManagerIndex function must iterate over the entire large array.

    • The gas cost of this iteration could exceed the block gas limit, leading to an out-of-gas error and transaction reversion.

  3. Test Verification:

    • A test that simulates a large managerList and calls removeManager for one of the managers will eventually fail due to high gas consumption, demonstrating the DoS vulnerability.

How to Run the Test

  1. Create a Foundry Project:
    Open your terminal and run:

    forge init my-foundry-project
  2. Place Contract Files:
    Place all relevant contract files (e.g., StabilityPool.sol) in the src directory of your project.

  3. Create Test Directory:
    Create a directory named test adjacent to the src directory, and add a test file (e.g., StabilityPoolTest.t.sol) containing a test case that simulates adding a very large number of managers and then attempts to remove one. For example:

    function testManagerRemovalDoS() public {
    // Simulate adding a large number of managers
    for (uint256 i = 0; i < 5000; i++) {
    address manager = address(uint160(i + 1));
    stabilityPool.addManager(manager, 100);
    }
    // Attempt to remove a manager; expect out-of-gas or revert due to excessive gas usage
    vm.expectRevert();
    stabilityPool.removeManager(address(1));
    }
  4. Run the Test:
    In your terminal, execute:

    forge test --mt testManagerRemovalDoS -vv

    This command will run the specific test case and display verbose output, verifying that the unbounded iteration leads to a gas issue, indicating a potential DoS condition.

Impact

  • Denial of Service:
    The removal process for managers can become prohibitively expensive in terms of gas, effectively preventing the removal of managers when the list becomes too large.

  • Administrative Disruption:
    Inability to remove a manager could block critical administrative operations and negatively impact the protocol's governance and risk management.

  • System Scalability:
    This vulnerability hampers the scalability of the contract since it relies on an array for dynamic data that can grow indefinitely without efficient management.

Tools Used

  • Foundry

  • Manual Review

  • AI (ChatGPT, PHIND, github copilot)

Recommendations

  • Optimize Data Structures:
    Replace the array-based approach with a more efficient data structure (e.g., mapping with index tracking) that supports constant-time removals.

  • Limit the Number of Managers:
    Impose a cap on the number of managers to ensure that the array does not grow to an unmanageable size.

  • Batch Processing:
    Consider implementing batch removal or a pagination mechanism to handle large arrays without running into gas limits.

  • Refactor findManagerIndex:
    If the array must be used, optimize the iteration logic and consider early exits or caching mechanisms to reduce gas usage.

Implementing these recommendations will help mitigate the risk of DoS during manager removals and improve the overall efficiency and scalability of the StabilityPool contract.

Updates

Lead Judging Commences

inallhonesty Lead Judge 7 months ago
Submission Judgement Published
Invalidated
Reason: Non-acceptable severity

Appeal created

theirrationalone Submitter
7 months ago
inallhonesty Lead Judge
7 months ago
inallhonesty Lead Judge 6 months ago
Submission Judgement Published
Invalidated
Reason: Non-acceptable severity

Support

FAQs

Can't find an answer? Chat with us on Discord, Twitter or Linkedin.

Give us feedback!