Griefer can extend period of higher withdrawal fees
The withdrawal fee decay timer is reset whenever a user receives LP tokens, even a tiny amount. An attacker can send 1 wei of LP tokens to another user to reset their lastActionTimestamp, extending the time they must wait for their withdrawal fee to decrease.
Submitted by 0xDjango
The _updateUserFeesOnDeposit() function in LiquidityPool.sol is used to update a user’s withdrawal fees after an action such as deposit, transfer in, etc. The withdrawal fee decays toward a minimum withdrawal fee over a period of 1 or 2 weeks (discussed with developer). Since anyone can transfer lp tokens to any user, a griefer can transfer 1 wei of lp tokens to another user to reset their lastActionTimestamp used in the withdrawal fee calculation.
The developers nicely weight the updated withdrawal fee by taking the original balance/original fee vs the added balance/added fee. The attacker will only be able to extend the runway of the withdrawal fee cooldown by resetting the lastActionTimestamp for future calculations. Example below:
Proof of Concept
Assumptions:
- MinWithdrawalFee = 0% //For easy math
- MaxWithdrawalFee = 10%
- timeToWait = 2 weeks
Steps
- User A has
100 weiof shares - User A waits 1 week (Current withdrawal fee = 5%)
- User B deposits, receives
1 weiof shares, current withdrawal fee = 10% - User B immediately transfers
1 weiof shares to User A
Based on the formula to calculated User A’s new feeRatio:
uint256 newFeeRatio = shareExisting.scaledMul(newCurrentFeeRatio) +
shareAdded.scaledMul(feeOnDeposit);
In reality, User A’s withdrawal fee will only increase by a negligible amount since the shares added were very small in proportion to the original shares. We can assume user A’s current withdrawal fee is still 5%.
The issue is that the function then reset’s User A’s lastActionTimestamp to the current time. This means that User A will have to wait the maximum 2 weeks for the withdrawal fee to reduce from 5% to 0%. Effectively the cooldown runway is the same length as the original runway length, so the decay down to 0% will take twice as long.
meta.lastActionTimestamp = uint64(_getTime());
Recommended Mitigation Steps
Instead of resetting lastActionTimestamp to the current time, scale it the same way the feeRatio is scaled. I understand that this would technically not be the timestamp of the last action, so the variable would probably need to be renamed.
chase-manning (Backd) confirmed and resolved
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
How it worked
Root cause
The function that updates fees on deposit resets the lastActionTimestamp to the current time regardless of the size of the deposit, instead of scaling it proportionally.
Impact
A griefer can extend the period during which another user pays higher withdrawal fees, potentially doubling the cooldown time.
What the attacker needed
Attacker has LP tokens; victim has LP tokens; attacker can transfer LP tokens to victim
The fix
The lastActionTimestamp should be scaled proportionally to the fee ratio change, rather than reset to the current time.
How it was found
- User A has 100 wei of shares and waits 1 week, so their withdrawal fee is 5%.
- User B deposits and receives 1 wei of shares, with a current withdrawal fee of 10%.
- User B immediately transfers 1 wei of shares to User A.
- User A's withdrawal fee increases negligibly, but their lastActionTimestamp is reset to now.
- User A must now wait the full 2 weeks for the fee to decay from 5% to 0%, doubling the total wait time.
Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
When you deposit into this pool, your withdrawal fee starts high and slowly goes down over time. The timer for that fee reduction resets whenever you receive any LP tokens, even a tiny amount. An attacker can send you a tiny amount to reset your timer, making you wait longer for lower fees.
What is Business logic?
The application works as coded but not as intended: a negative price, a skipped payment step, a limit that can be crossed.