Lack of slippage protection leads to loss of protocol funds
The protocol's liquidity removal and token swap functions lacked slippage protection, using zero as the minimum output amount. An attacker could front-run these transactions to manipulate prices, causing the protocol to suffer heavy slippage and lose funds.
0x6a70 Follow with 0x73696d616f, 0xjoi and 12 others
Originally disclosed on Sherlock
Source: https://github.com/sherlock-audit/2024-08-cork-protocol-judging/issues/66
Found by
0x6a70, 0x73696d616f, 0xjoi, 0xnbvc, 4b, 4gontuk, Abhan1041, MohammedRizwan, Pheonix, StraawHaat, alphacipher, boringslav, ivanonchain, sakshamguruji, vinica_boy
Summary
There is no slippage protection while removing liquidity and swap tokens from AMM.
Vulnerability Detail
There are 2 intances where slippage protection is missing which are as below:
- When LV token holder redeem before expiry
vaultLib::redeemEarlyfunction is called in which_liquidateLpPartialfunction and in that_redeemCtDsAndSellExcessCtis called. In_redeemCtDsAndSellExcessCtfunction CT tokens are swapped for RA tokens in AMM as below:
...
ra += ammRouter.swapExactTokensForTokens(ctSellAmount, 0, path, address(this), block.timestamp)[1];
...
As stated above, swapExactTokensForTokens function's 2nd parameter is 0 which shows that there is no slippage protection for this
swap and also deadline is block.timestamp.
- In
vaultLib::_liquidateLpPartialfunction__liquidateUncheckedis called in which liquidity is removed from AMM of RA-CT token pair by burning LP tokens of protocol as below:
...
(raReceived, ctReceived) =
ammRouter.removeLiquidity(raAddress, ctAddress, lp, 0, 0, address(this), block.timestamp);
...
As stated above, removeLiquidity function's 4th & 5th parameter is 0 which shows that there is no slippage protection for this swap and also deadline is block.timestamp.
In such cases, an attacker can frontrun the transaction by seeing it in the mempool and manipulate the price such that protocol transaction have to bear heavy slippage which will leads to loss of protocol funds.
Also, there is block.timestamp as deadline so malicious node can prevent transaction to execute temporary and execute the transaction when there is high slippage which will also leads to loss of protocol funds.
Impact
Loss of protocol funds which will reduce the yield of users.
Code Snippet
Tool used
Manual Review
Recommendation
Protocol should implement slippage protection and set deadline while removing liquidity and also swap from AMM.
Discussion
ziankork
Yes this is a valid issue, we've already fixed this prior to our trading competition except for the deadline vulnerability.
v-kirilov
#75 is a duplicate of this one!
sherlock-admin2
The protocol team fixed this issue in the following PRs/commits: https://github.com/Cork-Technology/Depeg-swap/pull/76
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 contract called swap and removeLiquidity functions with a minimum output amount of zero, providing no slippage protection.
Impact
The protocol could lose funds due to slippage, reducing user yield.
What the attacker needed
Attacker can see pending transactions; attacker can manipulate AMM price
The fix
The protocol was fixed by implementing slippage protection and setting a deadline for liquidity removal and swaps.
How it was found
- Attacker observes a pending transaction that will swap tokens or remove liquidity with zero slippage protection.
- Attacker front-runs by manipulating the AMM price.
- The protocol's transaction executes at the manipulated price, suffering heavy slippage and loss of funds.
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 a program trades tokens, it can set a minimum amount it will accept to avoid getting a bad deal. Here, the program did not set any minimum, so an attacker could change the price just before the trade and make the program lose money.
What is Smart contracts?
Flaws in on-chain code that let an attacker drain funds, freeze them or break the protocol's accounting.