Closed c4-bot-8 closed 8 months ago
Picodes marked the issue as primary issue
Picodes marked issue #221 as primary and marked this issue as a duplicate of 221
Picodes marked the issue as partial-25
This report doesn't discuss why such an attack is possible and the root cause of the issue
Picodes marked the issue as not a duplicate
Picodes marked the issue as duplicate of #937
Picodes marked the issue as unsatisfactory: Invalid
Picodes marked the issue as unsatisfactory: Invalid
Picodes marked the issue as unsatisfactory: Invalid
Lines of code
https://github.com/code-423n4/2024-01-salty/blob/main/src/pools/Pools.sol#L100
Vulnerability details
Impact
An attacker can steal funds which first depositor added with
sandwich-attack
. Generally, when a user adds liquidity to the pool, tokens are deposited as current rate.But in case of first deposit, full amount of tokens provided by user is deposited and pool's rate becomes the rate in which the user deposited.
By using this, an attacker can steal funds from first depositor with
sandwich-attack
.An attacker who has been looking pending transactions deposits little funds as large deviated rate from Uniswap with
front-running
before the user's deposit. Then, user's deposition transaction is run and pool's liquidity becomes much larger but pool's rate keeps large deviated from real.Then, the attacker adds transaction to swap and he can acquire much benefits from user's funds.
Proof of Concept
Liquidity.sol#_depositLiquidityAndIncreaseShare
function which is called when a user adds liquidity to the pool is as follows.Pools.sol#addLiquidity
function which is called on L102 is as follows.The
_addLiquidity()
function which is called on L153, 155 is as follows.As we can see above, full amount of tokens is deposited in first deposit and then tokens are deposited as rate of current reserve.
By using this, an attacker can steal funds with sandwiching first deposit.
For example,
We say that a user deposits first to [WBTC/WETH] pool and the current rate in Uniswap is
1:1000
. And we assume that the user deposits [100e18/100_000e18].An attacker deposits [1e18/1000] with front-running before the user. Then, current rate of the pool becomes [1e15:1] so the user deposits only [100e18/100_000] and remained eth is refunded.
Then, the attacker adds transaction to swap
100_000 wei
in this pool and steals most amount ofbtc
.Tools Used
Manual Review
Recommended Mitigation Steps
We have to modify logic for adding liquidity so that a user sets minimum and maximum rate in which funds are deposited, and in case of out-of-range it has to be reverted.
Assessed type
MEV