Skip to content
Business logic Audit finding Intermediate

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.

0xDjango Follow

Originally disclosed on Code4rena

Submitted by 0xDjango

LiquidityPool.sol#L790-L792

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 wei of shares
  • User A waits 1 week (Current withdrawal fee = 5%)
  • User B deposits, receives 1 wei of shares, current withdrawal fee = 10%
  • User B immediately transfers 1 wei of 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


The original report as published on Code4rena, by 0xDjango. Images and videos are our own copies; raw HTML is shown as text. View it on Code4rena.

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

  1. User A has 100 wei of shares and waits 1 week, so their withdrawal fee is 5%.
  2. User B deposits and receives 1 wei of shares, with a current withdrawal fee of 10%.
  3. User B immediately transfers 1 wei of shares to User A.
  4. User A's withdrawal fee increases negligibly, but their lastActionTimestamp is reset to now.
  5. 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.

More by 0xDjango

View all

23 more disclosed reports, best first.

More from Backd Tokenomics contest

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Business logic flaws

The lesson behind this report.

The application works as coded but not as intended: a negative price, a skipped payment step, a limit that can be crossed.