Assessment reports>Y2K Finance>Low findings>The function ,_removeVaults, returns early
Category: Coding Mistakes

The function _removeVaults returns early

Low Severity
Low Impact
Medium Likelihood

Description

The function _removeVaults is a helper function that removes vaults from the vaultList. While removing the vaults, it runs two loops, but the return statement is inside the first loop, due to which this function returns after the first iteration of the first loop. The intended functionality is to return after both the loops are finished.

Impact

The _removeVaults function would return early, and all the vaults will not be removed from the list as intended.

Recommendations

Move the two lines outside of the loop:

    function _removeVaults(
        address[] memory vaults
    ) internal returns (address[] memory newVaultList) {
        uint256 removeCount = vaults.length;
        newVaultList = vaultList;

        for (uint256 i; i < newVaultList.length; ) {
            for (uint j; j < removeCount; ) {
                if (vaults[j] == newVaultList[i]) {
                    // Deleting the removeVault from the list
                    if (j == removeCount) {
                        delete vaults[j];
                        removeCount--;
                    } else {
                        if (vaults.length > 1) {
                            vaults[j] = vaults[removeCount];
                            delete vaults[removeCount];
                        } else delete vaults[j];
                        removeCount--;
                    }
                    // Deleting the vault from the newVaultList list
                    if (
                        newVaultList[i] == newVaultList[newVaultList.length - 1]
                    ) {
                        delete newVaultList[i];
                    } else {
                        newVaultList[i] = newVaultList[newVaultList.length - 1];
                        delete newVaultList[newVaultList.length - 1];
                    }
                }
                unchecked {
                    j++;
                }
            }
            unchecked {
                i++;
            }

-            vaultList = newVaultList;
-            return newVaultList;
        }
+            vaultList = newVaultList;
+            return newVaultList;
    }

Remediation

The issue was fixed in commit 945734b and 6bd136c.

Zellic © 2024Back to top ↑