Skip to content
Business logic Audit finding Intermediate

Missing debt check lets users start a debt auction of non-existent debt

The debt auction function checks the available bad debt before settling it, so after settlement the remaining debt can fall below the minimum bid size, yet the auction still starts. An attacker could start an auction for non-existent debt, diluting the protocol token.

Saintcode_ Follow with T1MOH and falconhoof

Originally disclosed on Code4rena

Submitted by Saintcode_, also found by T1MOH and falconhoof

The AccountingEngine.sol contract serves as the protocol’s central component responsible for initializing both debt and surplus auctions. Debt auctions are consistently initiated with a predefined minimum bid referred to as debtAuctionBidSize. This is done to ensure that the protocol can only auction debt that is not currently undergoing an auction and is not locked within the debt queue, as articulated in the comment found on IAccountingEngine:248: “It can only auction debt that has been popped from the debt queue and is not already being auctioned”. This necessity prompts the check on AccountingEngine:181:

if (_params.debtAuctionBidSize > _unqueuedUnauctionedDebt(_debtBalance))

This check verifies that there is a sufficient amount of bad debt available to auction.

The issue stems in line 183, where _settleDebt is called, this aims to ensure that only bad debt is considered for the auction. However, if the remaining bad debt, after settlement, falls below the specified threshold (debtAuctionBidSize <= unqueuedUnauctionedDebt()), the auction still starts with an incorrect amount of bad debt coverage, diluting the protocol Token when it is not yet needed.

Impact

Non-existent debt gets auctioned when it is not necesary which dilutes the protocol token.

PoC

The attached Proof of Concept (PoC) demonstrates two test cases:

  • In the initial test case, a two-call flow is implemented. The “settleDebt” function must be externally triggered before initiating an auction. This design ensures that a check for insufficient debt occurs prior to creating an auction. Consequently, as after calling settleDebt there is inadequate debt, the operation will revert.
  • In the second case, the auctionDebt function is invoked directly. It is expected to behave in the same manner as in the first test case (because the funciton calls _settleDebt internally). However, in this second test case, the execution follows a different path. Rather than replicating the behavior of the initial test case by reverting not starting the auction, the execution succeeds, resulting in the creation of a debt auction even when there is no existing debt.

The following tests have been created using the protocol’s test suite:

First test case (original two call flow):

  function test_missing_insuficient_debt_check_part2() public {
    accountingEngine.modifyParameters("surplusTransferPercentage", abi.encode(1));
    accountingEngine.modifyParameters("extraSurplusReceiver", abi.encode(1));

    safeEngine.createUnbackedDebt(address(0), address(accountingEngine), rad(100 ether));

    _popDebtFromQueue(100 ether);

    accountingEngine.settleDebt(100 ether);

    vm.expectRevert();
    uint id = accountingEngine.auctionDebt();

  }

Second test case (vulnerability):

  function test_missing_insuficient_debt_check_part2() public {
    accountingEngine.modifyParameters("surplusTransferPercentage", abi.encode(1));
    accountingEngine.modifyParameters("extraSurplusReceiver", abi.encode(1));

    safeEngine.createUnbackedDebt(address(0), address(accountingEngine), rad(100 ether));

    _popDebtFromQueue(100 ether);

    uint id = accountingEngine.auctionDebt();

  }

Both test cases should revert and not let a user create a debt Auction under insufficient debt circumstances, but as stated on the report the second test case succeeds and creates the Auction.

Recommended Mitigation Steps

To mitigate this risk, I suggest introducing the check (_params.debtAuctionBidSize > _unqueuedUnauctionedDebt(_debtBalance)) after calling _settleDebt to ensure there exists enough amount of bad in the contract after the settling.

RaymondFam (Lookout) commented:

Seems like _params.debtAuctionBidSize > _unqueuedUnauctionedDebt(_debtBalance) check is well in place prior to settling the debt in the second case, but will let the sponsor look into it.

MiloTruck (Judge) commented:

Due to the misplacement of the _params.debtAuctionBidSize > _unqueuedUnauctionedDebt(_debtBalance) check before _settleDebt() is called, the protocol will create debt auctions even when the amount of bad debt is below params.debtAuctionBidSize. This leads to dilution of the protocol token as bidders can buy non-existent debt, thereby destabilizing the value of protocol’s token. As such, I agree with high severity.

pi0neerpat (OpenDollar) commented

Resolved here.


The original report as published on Code4rena, by Saintcode_. 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 check for sufficient bad debt is performed before the debt is settled, so the settlement can reduce the debt below the required threshold without re-checking.

Impact

The protocol could create debt auctions for non-existent debt, diluting the protocol token and destabilising its value.

What the attacker needed

Ability to call auctionDebt; some bad debt in the queue

The fix

The check for sufficient bad debt should be moved after the call to settle the debt, so the remaining debt is verified before starting the auction.

How it was found

  1. Create unbacked debt in the safe engine for the accounting engine.
  2. Pop the debt from the queue.
  3. Call auctionDebt directly, which internally settles the debt and then starts the auction despite insufficient remaining debt.

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.

A smart contract lets users auction off bad debt. It checks there is enough debt before it settles some of it, but settling reduces the debt, so the check can pass when there is not enough left. This means an auction can start for debt that does not exist, which can lower the value of the protocol's token.

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 from Open Dollar

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.