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:
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
- User makes
BorrowOrderwithTaxTokenReceiptNFT as collateral - The offer is matched and a loan is now created.
- Borrower doesn't pay his loan off
- 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,LoanOrderor aLoan) - At this point there is no eligible address since the
Auctionaddress doesn't meet the criteria and themsg.senderis just unable to meet it since neither theBorrowOrdernor theLendOrdercan callAuction::buyNFTfunction.
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
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
- User makes BorrowOrder with TaxTokenReceipt NFT as collateral
- The offer is matched and a loan is now created.
- Borrower doesn't pay his loan off
- Loan is auctioned and the NFT is transferred to the created auction
- 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.