XO-Incorrect type for rounding argument in scaleByBases function.
Summary
The scaleByBases function expects the third argument to be a rounding mode. TheMathUpgradeable.Rounding type is an enum that represents the different rounding modes. The uint256 type can also be used to represent a rounding mode. The rounding argument in the scaleByBases function is of type MathUpgradeable.Rounding. However, the rounding argument should be of type uint256. This is because the mulDiv function expects the third argument to be a rounding mode. The uint256 type is compatible with the mulDiv function, and it can be used to represent a rounding mode.
Vulnerability Detail
/**
* @notice Scale value by bases
* @param sourceValue Value of the source to scale
* @param sourceBase Base of the source, e.g., 1e18
* @param targetBase Base of the target, e.g., 1e6
* @param rounding Rounding mode that is `Up` or `Down`
* @return Value of the target
*/
function scaleByBases(
uint256 sourceValue,
uint256 sourceBase,
uint256 targetBase,
MathUpgradeable.Rounding rounding
) internal pure returns (uint256) {
return sourceValue.mulDiv(targetBase, sourceBase, rounding);
}
}
there is a vulnerability in thescaleByBases function, ThemulDiv function expects the first and third arguments to be the same type. the targetBase and sourceBase arguments are of type uint256, while the rounding argument is of type MathUpgradeable``.Rounding. This will cause a type error when the function is called.
The correct type for the rounding argument is uint256. This is because the mulDiv function expects the third argument to be a rounding mode. The MathUpgradeable.Rounding type is an enum that represents the different rounding modes, the uint256 type can also be used to represent a rounding mode.
Impact
The vulnerability could cause the function to return incorrect results.
XDZIBEC
medium
XO-Incorrect type for rounding argument in scaleByBases function.
Summary
scaleByBases
function expects the third argument to be a rounding mode. TheMathUpgradeable
.Rounding type is anenum
that represents the different rounding modes. The uint256
type can also be used to represent a rounding mode. The rounding argument in thescaleByBase
s function is of typeMathUpgradeable
.Rounding. However, the rounding argument should be of type uint256. This is because the mulDiv function expects the third argument to be a rounding mode. The uint256 type is compatible with the mulDiv function, and it can be used to represent a rounding mode.Vulnerability Detail
scaleByBases
function, ThemulDiv
function expects the first and third arguments to be the same type. thetargetBase
andsourceBase
arguments are of typeuint256
, while the rounding argument is of typeMathUpgradeable``.Rounding
. This will cause a type error when the function is called. The correct type for the rounding argument isuint256
. This is because themulDiv
function expects the third argument to be a rounding mode. TheMathUpgradeable
.Rounding type is anenum
that represents the different rounding modes, theuint256
type can also be used to represent a rounding mode.Impact
Code Snippet
Tool used
Manual Review
Recommendation
rounding
argument touint256
, this will ensure that themulDiv
function can be called without any errors.