DeFiFoundry
60,000 USDC
View results
Submission Details
Severity: medium
Invalid

Incorrect Bound Handling in `GlobalConfigurationBranch::getAccountsWithActivePositions` Leading to Underflow

Summary

The getAccountsWithActivePositions function retrieves account IDs with active positions between a specified lower and upper bound. There is an issue where if upperBound is less than lowerBound, it can cause an underflow, leading to potential errors.

Vulnerability Details

Impact

Proof of Impact and Vulnerability: If upperBound is less than lowerBound:

  • Underflow: The subtraction upperBound - lowerBound can cause an underflow, resulting in an excessively large array or exception.

  • Loop Malfunction: The for loop for (uint256 i = lowerBound; i <= upperBound; i++) will not work correctly, leading to errors.

Example Scenario: If lowerBound is 10 and upperBound is 5, upperBound - lowerBound + 1 causes an underflow, potentially leading to contract reversion or an unexpected array size.

Tools Used

Manual review

Recommendations

To fix this issue, add a validation check to ensure upperBound is greater than or equal to lowerBound:

//@audit what of if upperBound is less than lowerBound? underflow? for loop will be messed up for sure
function getAccountsWithActivePositions(
uint256 lowerBound,
uint256 upperBound
)
external
view
returns (uint128[] memory accountsIds)
{
require(upperBound >= lowerBound, "upperBound must be greater than or equal to lowerBound");
GlobalConfiguration.Data storage globalConfiguration = GlobalConfiguration.load();
accountsIds = new uint128[](upperBound - lowerBound + 1);
// for loop identifies the accountsIdWithActivePositions between lowerBound (0) and upperBound
uint256 index = 0;
for (uint256 i = lowerBound; i <= upperBound; i++) {
accountsIds[index] = uint128(globalConfiguration.accountsIdsWithActivePositions.at(i));
index++;
}
}

}

Updates

Lead Judging Commences

inallhonesty Lead Judge
10 months ago
inallhonesty Lead Judge 10 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.