A user can grief the protocol to lose funds, by preventing his position from getting liquidated and ultimately making his collateral insolvent #255
Labels
3 (High Risk)
Assets can be stolen/lost/compromised directly
bug
Something isn't working
duplicate-312
satisfactory
satisfies C4 submission criteria; eligible for awards
Lines of code
https://github.com/code-423n4/2024-01-salty/blob/main/src/staking/StakingRewards.sol#L67
Vulnerability details
Impact
The main impact of this vulnerability is that liquidators will not be able to liquidate the positions. And as time passes on, this bad debt will ultimately make the collaterals insolvent. This will affect the protocol, as it will lose funds.
In
CollateralAndLiquidity
contract, when a user deposits collateral throughdepositCollateralAndIncreaseShare
, he can borrow USDS. Let's assume that the user has borrowed X amt of USDS which is maximum amount he can borrow against his deposited collateral.One thing to note here is that when
depositCollateralAndIncreaseShare
is called, it will trigger a cooldown period (currently 1 hour). This is a security mechanism to prevent reward hunting. Now the user can't increase or decrease his shares for 1 hour.Now say the market has crashed, and the price of WETH and WBTC has gone down. Due to this, the user's position has also become liquidateble. So, a liquidator calls
liquidateUser
to liquidate the user's position. This will remove the liquidity and decrease the user's share.But the user can prevent his position from getting liquidated, by frontrunning the
liquidateUser
function call and depositing 101 wei of WETH and WBTC using thedepositCollateralAndIncreaseShare
function first. Now as thedepositCollateralAndIncreaseShare
function will get executed first because of front-running, so this will trigger the cooldown period of 1 hour. Now after this transaction, theliquidateUser
function will get executed, but it will revert because of the cooldown period. That is because, theliquidateUser
function calls_decreaseUserShare
function which will check ifblock.timestamp >= user.cooldownExpiration
, and as this will be false, so the transaction will revert.Now the user can continue preventing his position from liquidation, by front-running liquidators, or he can submit 101 wei after every
stakingConfig.modificationCooldown()
time, so that the cooldown period never expires.In the meantime, the price of WETH and WBTC may go further down, which may make the position insolvent. This means that the protocol will surely lose funds.
Proof of Concept
A test case is presented below, representing how the functions would be executed when front-run. It is a representation , i.e I have not showcased how to do the front-run by analysing mempool , and have simply shown the order of execution of the functions when front-runned.
Tools Used
Manula review
Recommended Mitigation Steps
Cooldown period should not affect liquidation process. Make exception.
Assessed type
Timing
The text was updated successfully, but these errors were encountered: