Skip to content
Business logic Audit finding Intermediate

Nobody can buy the `TaxTokenReceipt` NFT from auction

The TaxTokenReceipt NFT contract overrides transferFrom to require that either the sender or receiver is a Debita contract (BorrowOrder, LendOrder, or Loan). When a loan is auctioned, the NFT is held by the Auction contract, which is not one of those, so nobody can buy it, locking the collateral and causing lenders to lose funds.

0x37 Follow with 0xPhantom2, KaplanLabs and 6 others

Originally disclosed on Sherlock

Source: https://github.com/sherlock-audit/2024-10-debita-judging/issues/388

Found by

0x37, 0xPhantom2, KaplanLabs, KiroBrejka, bbl4de, dhank, dimulski, tmotfl, xiaoming90

Summary

Nobody can buy the TaxTokenReceipt NFT from auction due to the overrided transferFrom function. The transferFrom function is overrided with the following checks:

JavaScript
function transferFrom(
        address from,
        address to,
        uint256 tokenId
    ) public virtual override(ERC721, IERC721) {
        bool isReceiverAddressDebita = IBorrowOrderFactory(borrowOrderFactory)
            .isBorrowOrderLegit(to) ||
            ILendOrderFactory(lendOrderFactory).isLendOrderLegit(to) ||
            IAggregator(Aggregator).isSenderALoan(to);
        bool isSenderAddressDebita = IBorrowOrderFactory(borrowOrderFactory)
            .isBorrowOrderLegit(from) ||
            ILendOrderFactory(lendOrderFactory).isLendOrderLegit(from) ||
            IAggregator(Aggregator).isSenderALoan(from);
        // Debita not involved --> revert
        require(
            isReceiverAddressDebita || isSenderAddressDebita,
            "TaxTokensReceipts: Debita not involved"
        );

This ensures that the transfer of the NFT, will go smoothly through the system, but one thing is missing. The thing is that if a borrower doesn't pay off his debt amount and the loan is auctioned, nobody will be able to buy the NFT off. This is because the transferFrom function requires for the from and to addresses to be either a BorrowOrder, LendOrder or a Loan to be able to transfer the receipt NFT. At the point when the NFT is in the Auction contract it will be too late because neither the Auction contract nor the msg.sender is or can be one of the listed. This means that it is impossible to get any amount of collateral token out of the NFT, which means that the lenders will experience a big loss of funds

Root Cause

The modifications of the ERC721::transferFrom function

Internal pre-conditions

TaxTokenReceipt being used as loan collateral

External pre-conditions

None

Attack Path

  1. User makes BorrowOrder with TaxTokenReceipt NFT as collateral
  2. The offer is matched and a loan is now created.
  3. Borrower doesn't pay his loan off
  4. Loan is auctioned and the NFT is transferred to the created auction (Up to this moment everything is going smoothly because at least one address in the sequence meets the criteria of being either a BorrowOrder, LoanOrder or a Loan)
  5. At this point there is no eligible address since the Auction address doesn't meet the criteria and the msg.sender is just unable to meet it since neither the BorrowOrder nor the LendOrder can call Auction::buyNFT function.

Impact

Lenders will experience big loss of funds, since the NFT can't be sold. Borrower will go off with their principle token and money that they should get in the form of NFT underlying are frozen forever.

PoC

No response

Mitigation

Add a check to the TaxTokenReceipt NFT that ensures that an auction is active (Has an index different than 0 in the auctionFactoryDebita::AuctionOrderIndex mapping) and it is part of the Debita system (as it is indeed part of the system)

Discussion

sherlock-admin2

The protocol team fixed this issue in the following PRs/commits: https://github.com/DebitaFinance/Debita-V3-Contracts/commit/77653c1b2b5aacdbf4ae340d50504e056b8d8540

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

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

The overridden transferFrom function only permits transfers involving BorrowOrder, LendOrder, or Loan contracts, but does not account for the Auction contract.

Impact

Lenders will experience big loss of funds, since the NFT can't be sold.

What the attacker needed

TaxTokenReceipt used as loan collateral; Borrower defaults on loan

The fix

The protocol team fixed this issue in a PR/commit.

How it was found

  1. User makes BorrowOrder with TaxTokenReceipt NFT as collateral
  2. The offer is matched and a loan is now created.
  3. Borrower doesn't pay his loan off
  4. Loan is auctioned and the NFT is transferred to the created auction
  5. At this point there is no eligible address since the Auction address doesn't meet the criteria

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.

This is a smart contract bug. The NFT representing a tax token receipt can only be transferred if one of the parties is a specific Debita contract. When a loan goes to auction, the NFT sits in the auction contract, which is not allowed, so no one can buy it and the lender cannot recover the collateral.

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 0x37

View all

79 more disclosed reports, best first.

More from Debita Finance V3

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.