The UpliftOnlyExample contract contains a miscalculation in the lpTokenDepositValueChange variable within the onAfterRemoveLiquidity() function. The calculation fails to correctly apply fixed-point arithmetic by not scaling the change in deposit value with 1e18 before division, leading to a loss of precision. This results in incorrect fee calculations, potentially charging minWithdrawalFeeBps for changes less than 100% and a lower fee than intended for changes greater than or equal to 100%.
The issue arises from performing division before multiplication in the calculation of lpTokenDepositValueChange. This leads to a loss of precision due to integer division rounding down.
The current calculation
Here we can see that the division operation rounds down the result, causing lpTokenDepositValueChange to be zero for changes between 0% and 100%, and one for changes between 100% and 200%.
The subsequent multiplication by 1e18 in the fee calculation does not recover the lost precision from the initial division.
The lpTokenDepositValueChange becomes 0, leading to the application of minWithdrawalFeeBps instead of the intended uplift fee.
The lpTokenDepositValueChange rounds down, resulting in a much smaller fee than intended, potentially even less than minWithdrawalFeeBps.
Incorrect Fee Calculation: The miscalculation can lead to incorrect fee assessments, potentially undercharging users. If there is a positive growth (>=100%) in the deposit amount, the protocol may charge a very small fee for the remove liquidity operation. Conversely, it only applies the minWithdrawalFeeBps for growths less than 100%.
Due to this calculation issue, the protocol misses out on collecting appropriate fees for positive growth scenarios, leading to a loss of revenue.
Manual Review
Modify the calculation to apply multiplication by 1e18 before division to preserve precision:
Likelihood: High, every call to the function (withdraw) Impact: Low/Medium, uplift fees will be applied only when the price of one asset is doubled but fixed fees will still be collected.
The contest is live. Earn rewards by submitting a finding.
This is your time to appeal against judgements on your submissions.
Appeals are being carefully reviewed by our judges.