Summary
There is a discrepancy between the LibMath.mulDivOrMax
function logic and the corresponding comment.
Vulnerability Details
The LibMath.mulDivOrMax
returns type(uint256).max
in case of potential overflow. But the corresponding comment mentions another logic.
>> * @notice Calculates floor(x * y / denominator) with full precision. Throws if result overflows a uint256 or denominator == 0
* @dev Original credit to Remco Bloemen under MIT license (https:
* with further edits by Uniswap Labs also under MIT license.
*/
function mulDivOrMax(uint256 x, uint256 y, uint256 denominator) internal pure returns (uint256 result) {
unchecked {
uint256 prod0;
uint256 prod1;
assembly {
let mm := mulmod(x, y, not(0))
prod0 := mul(x, y)
prod1 := sub(sub(mm, prod0), lt(mm, prod0))
}
if (prod1 == 0) {
return prod0 / denominator;
}
>> if (denominator <= prod1) return type(uint256).max;
Impact
Discrepancy between code and comments can lead to difficulties and mistakes during protocol maintenance.
Tools used
Manual Review
Recommendations
Consider changing the comment on the correct one.
- * @notice Calculates floor(x * y / denominator) with full precision. Throws if result overflows a uint256 or denominator == 0
+ * @notice Calculates floor(x * y / denominator) with full precision. Returns type(uint256).max if result overflows a uint256. Throws if denominator == 0