Yield of LiquidityReserve can be stolen
The yield from LiquidityReserve is distributed instantly when a user calls instantUnstakeReserve, and liquidity can be added and removed without penalty. An attacker could sandwich the user's call by adding liquidity before and removing it after, thereby capturing most of the fee that would otherwise go to existing liquidity providers.
Submitted by Picodes
Impact
Using sandwich attacks and JIT (Just-in-time liquidity), the yield of LiquidityReserve could be extracted for liquidity providers.
Proof of Concept
The yield of LiquidityReserve is distributed when a user calls instantUnstakeReserve() in Staking. Then, in instantUnstake, totalLockedValue increases with the fee paid by the user withdrawing. The fee is shared between all liquidity providers as they all see the value of their shares increase.
Therefore, an attacker could do the following sandwich attack when spotting a call to instantUnstakeReserve().
- In a first tx before the user call, borrow a lot of
stakingTokenandaddLiquidity - The user call to
instantUnstakeReserve()leading to a fee of sayx\ - In a second tx after the user call,
removeLiquidityand repay the loan, taking a large proportion of the user fee
The problem here is that you can instantly add and remove liquidity without penalty, and that the yield is instantly distributed.
Recommended Mitigation Steps
To mitigate this, you can
- store the earned fees and distribute them across multiple blocks to make sure the attack wouldn’t be worth it
- add a small fee when removing liquidity, which would make the attack unprofitable
- prevent users from withdrawing before X blocks or add a locking mechanism
0xean (Yieldy) disagreed with severity and commented:
This is not unique to the protocol and is a vulnerability in almost all of the LP designs that are prevalent today. There is no loss of user funds here either.
Would downgrade to Low or QA.
In standard cases of JIT, for example in a DEX, the attacker takes a risk as the liquidity he adds is used during the swap, and this liquidity is useful for the protocol as leads to a better price for the user, which is not the case here
@Picodes - that is fair but the liquidity is still useful and I still don’t see how this qualifies as high severity. Eventually it would mean that the liquidity reserve would need less liquidity parked in it if JITers always where hitting it.
To me it’s high because: (correct me if I am missing things)
- JIT is not useful here at all for the protocol, the liquidity they bring is not useful as does not get locked. It’s totally risk free, and as you said it’s a commun attack so it’s likely that someone uses it
- It leads to a loss of LP funds: Assume there is 100k unlocked in the pool, and someone
instantUnstake100k, it’ll lock all the LP liquidity. But if someone JITs this, the fees will go to the attacker and not the LP which provided the service by accepting to have its liquidity locked.- From a protocol point of view, LPing becomes unattractive as all the fees are stolen, breaking the product design
Agree going to leave this as high. Any whale that does a large unstake will be susceptible to having more of the fee’s eroded to a predatory sandwich attack which provides no value to the system.
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
Likely the design allows instant addition and removal of liquidity without penalty, and fees are distributed immediately, enabling just-in-time liquidity attacks.
Impact
The attacker could steal the yield that would otherwise go to liquidity providers, reducing their returns and making liquidity provision less attractive.
What the attacker needed
Attacker can borrow large amount of stakingToken; victim calls instantUnstakeReserve
The fix
The protocol should store earned fees and distribute them over multiple blocks, add a small fee for removing liquidity, or prevent withdrawal before a certain number of blocks.
How it was found
- Borrow a large amount of stakingToken and add liquidity before the victim's call.
- The victim calls instantUnstakeReserve, generating a fee.
- Remove liquidity and repay the loan after the victim's call, capturing most of the fee.
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 someone unstakes early, they pay a fee that is shared among everyone who has provided liquidity to the pool. Because you can add and remove liquidity instantly with no penalty, an attacker can quickly add a large amount just before the fee is paid and remove it just after, taking most of the fee for themselves. This leaves the honest liquidity providers with less reward.
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.