sherlock-audit / 2024-05-beefy-cowcentrated-liquidity-manager-judging

5 stars 5 forks source link

Redundant_Constant #142

Closed sherlock-admin2 closed 2 months ago

sherlock-admin2 commented 2 months ago

Redundant_Constant

Low/Info issue submitted by petarP1998

Summary

The audit identified an inefficiency in the Path::hasMultiplePool function, where an unnecessary calculation is performed using the MULTIPLE_POOLS_MIN_LENGTH constant. This constant is exclusively used within the hasMultiplePools function, rendering it redundant. A suggestion was made to utilize the Path::numPools function instead, as it offers a more robust approach for the intended check.

Vulnerability Detail

The issue lies in the calculation of the minimum length required for a path containing two or more pools, represented by the MULTIPLE_POOLS_MIN_LENGTH constant. This constant is not utilized outside of the hasMultiplePools function, leading to redundancy in its definition. Consequently, the function's logic could be simplified by directly utilizing the numPools function, which accurately determines the number of pools in the path.

https://github.com/sherlock-audit/2024-05-beefy-cowcentrated-liquidity-manager/blob/main/cowcentrated-contracts/contracts/utils/Path.sol#L25-L27

Impact

While the impact is negligible in terms of functionality, the redundant calculation adds unnecessary complexity to the codebase. It may marginally affect performance and readability, albeit to a minimal extent.

Code Snippet

/// @dev The minimum length of an encoding that contains 2 or more pools
uint256 private constant MULTIPLE_POOLS_MIN_LENGTH = POP_OFFSET + NEXT_OFFSET;

/// @notice Returns true iff the path contains two or more pools
/// @param path The encoded swap path
/// @return True if path contains two or more pools, otherwise false
function hasMultiplePools(bytes memory path) internal pure returns (bool) {
    return path.length >= MULTIPLE_POOLS_MIN_LENGTH;
}

/// @notice Returns the number of pools in the path
/// @param path The encoded swap path
/// @return The number of pools in the path
function numPools(bytes memory path) internal pure returns (uint256) {
    // Ignore the first token address. From then on every fee and token offset indicates a pool.
    return ((path.length - ADDR_SIZE) / NEXT_OFFSET);
}

Tool used

Manual Review

Recommendation

It is recommended to remove the MULTIPLE_POOLS_MIN_LENGTH constant and directly utilize the numPools function within the hasMultiplePools function for a more streamlined and efficient implementation. This adjustment would enhance code readability and maintainability without compromising functionality.