The current fee calculation logic in the onAfterRemoveLiquidity which is called during removeLiquidityProportional function suffers from precision loss when calculating the uplift value (lpTokenDepositValueChange). As a result, when there is a significant price increase (e.g., 90%), the calculated lpTokenDepositValueChange becomes 0 due to integer division, leading to the application of the minWithdrawalFeeBps instead of the intended uplift fee. This allows users to avoid paying appropriate fees during withdrawal, causing revenue loss and protocol instability.
The calculation of lpTokenDepositValueChange uses integer division:
If localData.lpTokenDepositValueNow and localData.lpTokenDepositValue differ only slightly, the result of the division rounds down to 0 due to Solidity's truncation of decimal values in integer division.
The logic subsequently interprets lpTokenDepositValueChange <= 0, applying the minimal withdrawal fee (minWithdrawalFeeBps) instead of the correct uplift fee based on the actual price increase.
Setup:
A user deposits liquidity, creating LP tokens with an initial deposit value (lpTokenDepositValue).
Price Increase:
The pool value increases by a significant percentage (e.g., 90%).
Withdrawal:
During withdrawal, the fee calculation rounds lpTokenDepositValueChange down to 0 due to integer precision loss.
The user is charged the minimal withdrawal fee instead of the uplift fee.
Loss of Protocol Revenue:
Users avoid paying accurate fees for uplift in pool value, causing revenue loss.
Exploitation Risk:
Attackers can exploit this flaw to minimize fees in scenarios of significant price increases.
manual analysis
Update the onAfterRemoveLiquidity localData.lpTokenDepositValueChange calculation as follows
then
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.