Part 2

Zaros
PerpetualsDEXFoundrySolidity
70,000 USDC
View results
Submission Details
Severity: medium
Valid

Out-of-Bounds Error in configureConnectedVaults Function in library Market

Summary

The function configureConnectedVaults is intended to add vault IDs to the connectedVaults array, which is stored as an EnumerableSet.UintSet[].

However, the function incorrectly accesses an index using connectedVaults.length, which will cause an out-of-bounds error because:

  1. connectedVaults.length is not a valid index for appending new elements.

  2. The array needs to be explicitly expanded before accessing a new index.

Vulnerability Details

function configureConnectedVaults(Data storage self, uint128[] memory vaultsIds) internal {
EnumerableSet.UintSet[] storage connectedVaults = self.connectedVaults;
// add the vauls ids to a new UintSet instance in the connectedVaults array
for (uint256 i; i < vaultsIds.length; i++) {
connectedVaults[connectedVaults.length].add(vaultsIds[i]);
}
}

Using connectedVaults[connectedVaults.length] will cause an out-of-bounds error since the array does not expand dynamically when accessing an index that has not been explicitly initialized.

Solidity arrays do not auto-expand when assigned to connectedVaults[connectedVaults.length].

This access only works for an already allocated index, if connectedVaults.length is equal to the current size, it does not point to a valid memory slot, causing a runtime error.

Impact

Since the function cannot execute properly, no vaults can be added, breaking protocol functionality.

Tools Used

Manual Review

Recommendations

Explicitly Push New Elements to connectedVaults Before Accessing Them

Updates

Lead Judging Commences

inallhonesty Lead Judge 5 months ago
Submission Judgement Published
Validated
Assigned finding tags:

`Market::configureConnectedVaults` Will Always Fail with Array Out of Bounds Error

Support

FAQs

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