Submitted by ladboy233
https://github.com/code-423n4/2023-11-betafinance/blob/0f1bb077afe8e8e03093c8f26dc0b7a2983c3e47/Omni_Protocol/src/OmniPool.sol#L331
https://github.com/code-423n4/2023-11-betafinance/blob/0f1bb077afe8e8e03093c8f26dc0b7a2983c3e47/Omni_Protocol/src/OmniPool.sol#L232
https://github.com/code-423n4/2023-11-betafinance/blob/0f1bb077afe8e8e03093c8f26dc0b7a2983c3e47/Omni_Protocol/src/OmniToken.sol#L81
https://github.com/code-423n4/2023-11-betafinance/blob/0f1bb077afe8e8e03093c8f26dc0b7a2983c3e47/Omni_Protocol/src/OmniPool.sol#L96
Borrower can abuse enterMarkets to force liquidator can pay more fund.
Liquidation process is in place to make sure the bad debt is paid, and when the liquidator repays the debt, they can seize the asset of the borrower as reward.
However, a bad user who does not want to repay the debt can force liquidator to pay more funds and even block liquidation.
When liquidating, this line of code is called:
For every pool market, the liquidator needs to pay the gas to call accrue interest
Note the function call:
For each pool market, at most the for accrue function for loop runs 255 interaction
The max trancheCount is uint8, but note there is no check for borrower to add pool market any time by calling enterMarkets.
The enterMarkets does not restrict the max number of market entered and does not validate if the borrower already has borrow position.
Before the liquidation happens, the borrower can select a lot of markets with high tranche count that does not accrue interest yet to enter the market.
Then liquidator has to pay the gas to run the for loop of accruing, which is clearly a loss of fund for liquidator.
The number of for loop iteration is :
This is an unbounded loop and can exceed the block limit.
The liquidator may not have incentive to liquidate once the gas paid for accruing exceeds the bonus, then bad debt is accruing and make the pool insolvent.
Proof of Concept:
Can add this test to TestOmniPool.t.sol
Basically, we construct 1000 markets.
First we comment out the bad users:
Then run the test:
The output is:
This means the liquidator pays 159429 amount of gas to liquidate the user, but if we uncomment the line of code pool.enterMarkets(0, newMarkets), the liquidator is forced to call accrue thousands of times in the loop.
We run the test again using the same comment.
The gas used is:
If the user call enter markets to enter more market, liquidator is likely to run out of gas.
As long as the user makes the liquidator feel like the gas cost of calling accrue is greater than liquidation seized asset, there will be no liquidation.
Validate the max number of entered market for borrower.
Do not allow user to add more market if the user has borrow position.
cccz (Judge) increased severity to Medium
See full discussion on severity here.
allenjlee (BetaFinance) confirmed
