Category: Coding Mistakes
The utilizationFee is divided by an extra PRECISION_6
Medium Impact
Medium Severity
High Likelihood
Description
When a trade is opened, the function getOpeningFee is used to calculate the dynamic opening fee. This opening fee consists of a baseFee and utilizationFee. The utilization fee is calculated in the function _getUtilizationOpeningFee. The else-if case of the function divides the utilizationFee by an extra PRECISION_6, leading to a value much smaller than expected:
function _getUtilizationOpeningFee(uint16 pairIndex, uint256 takerAmount, uint256 usageOi, uint256 oiCap)
private
view
returns (uint256)
{
uint256 utilizationFee;
uint256 usageAmount = usageOi + takerAmount;
uint256 thresholdOi = pairOpeningFees[pairIndex].utilizationThresholdP
* oiCap / 100 / PRECISION_2;
if (usageOi > thresholdOi) {
utilizationFee = takerAmount * pairOpeningFees[pairIndex].usageFeeP
* (usageOi + takerAmount / 2 - thresholdOi)
/ (100 * oiCap * (PRECISION_6
- pairOpeningFees[pairIndex].utilizationThresholdP
* uint32(PRECISION_2))
);
} else if (usageAmount > thresholdOi) {
utilizationFee = pairOpeningFees[pairIndex].usageFeeP
* (usageOi + takerAmount - thresholdOi)
/ (200 * oiCap * (PRECISION_6
- pairOpeningFees[pairIndex].utilizationThresholdP
* uint32(PRECISION_2))
)
* (usageAmount - thresholdOi) / PRECISION_6;
}
return utilizationFee;
}Impact
The returned value of utilizationFee would be much smaller than expected in the else-if case.
Recommendations
Remove the division by PRECISION_6.
Remediation
This issue has been acknowledged by Ostium Labs, and a fix was implemented in commit db8d5a4a↗.