Skip to content
Business logic Audit finding Intermediate

User can borrow DOLA indefinitely without settling DBR deficit by keeping their debt close to the allowed maximum

A user can borrow DOLA without paying the required DBR deficit by keeping their collateral surplus small enough that no third party has an economic incentive to call forceReplenish. This allows the user to repay and withdraw all collateral while leaving an arbitrarily large DBR deficit.

Holmgren Follow

Originally disclosed on Code4rena

Submitted by Holmgren

A user can borrow DOLA interest-free. This requires the user to precisely manage their collateral. This issue might become especially troublesome if a Market is opened with some stablecoin as the collateral (because price fluctuations would become negligible and carefully managing collateral level would be easy).

This issue is harder to exploit (but not impossible) if gov takes responsibility for forcing replenishment, since gov has a stronger economic incentive than third parties.

Proof of Concept

If my calculations are correct, with the current gas prices it costs about $5 to call Market.forceReplenish(...). Thus there is no economic incentive to do so as long as a debtor’s DBR deficit is worth less than $5/replenishmentIncentive so probably around $100.

This is because replenishing cannot push a user’s debt under the water (https://github.com/code-423n4/2022-10-inverse/blob/main/src/Market.sol#L567) and a user can repay their debt without having settled the DBR deficit (https://github.com/code-423n4/2022-10-inverse/blob/main/src/Market.sol#L531).

So, assuming the current prices, a user can:

  1. Deposit some collateral
  2. Borrow close to the maximum allowed amount of DOLA
  3. Keep withdrawing or depositing collateral so that the collateral surplus does not exceed $100 (assuming current gas prices)
  4. repay() their debt at any time in the future.
  5. Withdraw all the collateral.

All this is possible with arbitrarily large DBR deficit because due to small collateral surplus at no point was it economical for a third party to forceReplenish() the user. If gov takes responsibility for forceReplenish()ing, the above procedure is still viable although the user has to maintain the collateral surplus at no more than around $5.

Recommended Mitigation Steps

Allow replenishing to push the debt under the water and disallow repaying the debt with an outstanding DBR deficit. E.g.:

diff --git a/src/Market.sol b/src/Market.sol
index 9585b85..d69b599 100644
--- a/src/Market.sol
+++ b/src/Market.sol
@@ -531,6 +531,7 @@ contract Market {
     function repay(address user, uint amount) public {
         uint debt = debts[user];
         require(debt >= amount, "Insufficient debt");
+        require(dbr.deficitOf(user) == 0, "DBR Deficit");
         debts[user] -= amount;
         totalDebt -= amount;
         dbr.onRepay(user, amount);
@@ -563,8 +564,6 @@ contract Market {
         uint replenishmentCost = amount * dbr.replenishmentPriceBps() / 10000;
         uint replenisherReward = replenishmentCost * replenishmentIncentiveBps / 10000;
         debts[user] += replenishmentCost;
-        uint collateralValue = getCollateralValueInternal(user);
-        require(collateralValue >= debts[user], "Exceeded collateral value");
         totalDebt += replenishmentCost;
         dbr.onForceReplenish(user, amount);
         dola.transfer(msg.sender, replenisherReward);

0xean (judge) commented:

This seems like a dust attack. Will leave open for sponsor review.

08xmt (Inverse) confirmed and commented:

Fixed in https://github.com/InverseFinance/FrontierV2/pull/24.


The original report as published on Code4rena, by Holmgren. Images and videos are our own copies; raw HTML is shown as text. View it on Code4rena.

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 forceReplenish function cannot push a user's debt below the collateral value, and repay does not check for an outstanding DBR deficit, so a user can avoid replenishment by keeping the collateral surplus small.

Impact

A user could borrow DOLA interest-free and leave an arbitrarily large DBR deficit, as long as the collateral surplus stays small enough that forceReplenish is not economically worthwhile.

What the attacker needed

A market with stablecoin collateral; ability to manage collateral precisely; gas costs make forceReplenish unprofitable

The fix

The fix was to allow replenishing to push debt under the water and to disallow repaying debt while a DBR deficit exists.

How it was found

  1. Deposit some collateral
  2. Borrow close to the maximum allowed amount of DOLA
  3. Keep withdrawing or depositing collateral so that the collateral surplus does not exceed $100
  4. repay() their debt at any time in the future
  5. Withdraw all the collateral

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 this lending system, borrowers are supposed to maintain a balance of DBR tokens to cover the interest on their loan. If they fall short, anyone can force them to top up, but doing so costs gas and only gives a small reward. The bug is that a borrower can keep their collateral just barely above the debt so that forcing a top-up is not worth the gas, then repay the loan and walk away without ever fixing the DBR shortfall.

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.

More by Holmgren

View all

1 more disclosed report, best first.

More from Inverse Finance contest

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Business logic flaws

The lesson behind this report.

The application works as coded but not as intended: a negative price, a skipped payment step, a limit that can be crossed.