Users could get some DOLA even if they are on liquidation position
The forceReplenish function checked a user's collateral value against their debt without applying the collateral factor, so a user already in liquidation could still call it to cover their accrued DBR fees and receive more DOLA. This could also push a healthy debt into liquidation.
Submitted by Ch_301
Users able to invoke forceReplenish() when they are on liquidation position.
Proof of Concept
On Market.sol ==> forceReplenish()
On this line
uint collateralValue = getCollateralValueInternal(user);
getCollateralValueInternal(user) only return the value of the collateral
function getCollateralValueInternal(address user) internal returns (uint) {
IEscrow escrow = predictEscrow(user);
uint collateralBalance = escrow.balance();
return collateralBalance * oracle.getPrice(address(collateral), collateralFactorBps) / 1 ether;
So if the user have 1.5 wETH at the price of 1 ETH = 1600 USD
It will return 1.5 * 1600 and this value is the real value we can’t just check it directly with the debt like this
require(collateralValue >= debts[user], "Exceeded collateral value");
This is no longer over collateralized protocol.
The value needs to be multiplied by collateralFactorBps / 10000
- So depending on the value of
collateralFactorBpsandliquidationFactorBpsthe user could be in the liquidation position but he is able to invokeforceReplenish()to cover all theirdueTokensAccrued[user]onDBR.soland get moreDOLA - or it will lead a healthy debt to be in the liquidation position after invoking
forceReplenish() -
Recommended Mitigation Steps
Use getCreditLimitInternal() rather than getCollateralValueInternal().
I believe this warden may be correct in the fact that we should actually be adding the
collateralFactorinto the check.
While increasing debt beyond the Credit limit do risk creating bad debt, this bad debt is owed entirely to the protocol. If one wanted to minimise the amount of bad debt created this way, it would be possible to change the line to
getCollateralValueInternal() * (10000 - liquidationIncentiveBps) / 10000;, as this would also slightly reduce the amount of bad debt paid out to force replenishers as incentives.
08xmt (Inverse) confirmed and commented:
https://github.com/InverseFinance/FrontierV2/pull/17.
Added a variant of this solution: https://github.com/code-423n4/2022-10-inverse-findings/issues/419#issuecomment-1313694712.
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 check used the raw collateral value instead of the credit limit that accounts for the collateral factor.
Impact
A user in liquidation could still get more DOLA and have their fees covered, and a healthy debt could be pushed into liquidation; the bad debt created is owed to the protocol.
What the attacker needed
A position in liquidation or near the limit
The fix
The check should use getCreditLimitInternal() instead of getCollateralValueInternal(), and the project added a variant of this solution.
How it was found
- Have a position that is already in liquidation.
- Call forceReplenish().
- The function checks the raw collateral value against the debt, which passes.
- The user's dueTokensAccrued are covered and they receive more DOLA.
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.
In a lending protocol, you can only borrow up to a fraction of your collateral's value, called the collateral factor. The forceReplenish function mistakenly compared the full collateral value to the debt, ignoring that fraction, so someone already undercollateralised could still use it to get more DOLA and have their fees covered.
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.