Precision loss in fee calculation due to order of operations
In the _calculateFeesUSD function of OperationalTreasury.sol, the fee calculation is performed in a way that may lead to precision loss due to Division Before Multiply.
In the _calculateFeesUSD function of OperationalTreasury.sol, the fee calculation is performed in a way that may lead to precision loss due to Division Before Multiply. The current implementation:
fees = price.mulDivRoundingUp(baseSetUp.protocolFees, FEES_UNIT);fees = (fees * amount).toDecimals(36, 18);
The issue arises because the protocol fees are divided by FEES_UNIT before being multiplied by the amount. This order of operations can result in rounding down of intermediate values, potentially leading to undercharging of fees.
To minimize precision loss, the calculation should be reordered. The recommended implementation should be:
fees = (price * amount).mulDivRoundingUp(baseSetUp.protocolFees, FEES_UNIT);fees = fees.toDecimals(36, 18);
Report provenance
Published by Pashov Audit Group, with Carlos (Bloqarl) participating as a contractor. The source report states that its fixes review was not fully completed; no final remediation disposition is recorded for this finding. Read the full report.