No one can sell `TaxTokensReceipts` NFT receipt to the buy order
The TaxTokensReceipt NFT contract overrides transferFrom to only allow transfers involving borrow orders, lend orders, or loans, but not buy orders. As a result, holders cannot sell their TaxTokensReceipt NFTs to a buy order, breaking that feature.
0x37 Follow with KiroBrejka, bbl4de and 2 others
Originally disclosed on Sherlock
Source: https://github.com/sherlock-audit/2024-10-debita-judging/issues/560
The protocol has acknowledged this issue.
Found by
0x37, KiroBrejka, bbl4de, dimulski, xiaoming90
Summary
No response
Root Cause
No response
Internal pre-conditions
No response
External pre-conditions
No response
Attack Path
The TaxTokensReceipts NFT receipt exist to allow FOT to be used within the Debita ecosystem. If users have any tokens that charge a tax/fee on transfer, they must deposit them into the TaxTokensReceipts NFT receipt and use the NFT within the Debita ecosystem.
The new Debita protocol has a new feature called "Buy Order" or "Limit Order" that allows users to create buy orders, providing a mechanism for injecting liquidity to purchase specific receipts at predetermined ratios. The receipts include the TaxTokensReceipts NFT receipt.
Assume that Bob creates a new Buy Order to purchase TaxTokensReceipts NFT receipt. Alice, the holder of TaxTokensReceipts NFT receipt, decided to sell it to Bob's Buy Order. Thus, she called the buyOrder.sellNFT() function, and Line 99 below will attempt to transfer Alice's TaxTokensReceipts NFT receipt to the Buy Order contract.
File: buyOrder.sol
092: function sellNFT(uint receiptID) public {
093: require(buyInformation.isActive, "Buy order is not active");
094: require(
095: buyInformation.availableAmount > 0,
096: "Buy order is not available"
097: );
098:
099: IERC721(buyInformation.wantedToken).transferFrom(
100: msg.sender,
101: address(this),
102: receiptID
103: );
However, the transfer will always revert because the transfer function has been overwritten, as shown below. The transfer function has been overwritten to only allow the transfer to proceed if the to or from involves the following three (3) contracts:
- Borrow Order Contract
- Lend Order Contract
- Loan Contract
Since neither the Buy Order contract nor the seller (Alice) is the above three contracts, the transfer will always fail. Thus, there is no way for anyone to sell their TaxTokensReceipts NFT receipt to the buy order. Thus, this feature is effectively broken.
File: TaxTokensReceipt.sol
093: function transferFrom(
094: address from,
095: address to,
096: uint256 tokenId
097: ) public virtual override(ERC721, IERC721) {
098: bool isReceiverAddressDebita = IBorrowOrderFactory(borrowOrderFactory)
099: .isBorrowOrderLegit(to) ||
100: ILendOrderFactory(lendOrderFactory).isLendOrderLegit(to) ||
101: IAggregator(Aggregator).isSenderALoan(to);
102: bool isSenderAddressDebita = IBorrowOrderFactory(borrowOrderFactory)
103: .isBorrowOrderLegit(from) ||
104: ILendOrderFactory(lendOrderFactory).isLendOrderLegit(from) ||
105: IAggregator(Aggregator).isSenderALoan(from);
106: // Debita not involved --> revert
107: require(
108: isReceiverAddressDebita || isSenderAddressDebita,
109: "TaxTokensReceipts: Debita not involved"
110: );
Impact
Medium. Core protocol functionality (Buy Order/Limit Order) is broken.
PoC
No response
Mitigation
Buy Order contract must be authorized to transfer TaxTokensReceipt NFT as it is also part of the Debita protocol.
function transferFrom(
address from,
address to,
uint256 tokenId
) public virtual override(ERC721, IERC721) {
bool isReceiverAddressDebita = IBorrowOrderFactory(borrowOrderFactory)
.isBorrowOrderLegit(to) ||
ILendOrderFactory(lendOrderFactory).isLendOrderLegit(to) ||
+ IBuyOrderFactory(buyOrderFactory).isBuyOrderLegit(to) ||
IAggregator(Aggregator).isSenderALoan(to);
bool isSenderAddressDebita = IBorrowOrderFactory(borrowOrderFactory)
.isBorrowOrderLegit(from) ||
ILendOrderFactory(lendOrderFactory).isLendOrderLegit(from) ||
+ IBuyOrderFactory(buyOrderFactory).isBuyOrderLegit(from) ||
IAggregator(Aggregator).isSenderALoan(from);
// Debita not involved --> revert
require(
isReceiverAddressDebita || isSenderAddressDebita,
"TaxTokensReceipts: Debita not involved"
);
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 transferFrom function in TaxTokensReceipt.sol only permits transfers where the sender or receiver is a borrow order, lend order, or loan contract, omitting buy order contracts.
Impact
The buy order feature is broken for TaxTokensReceipt NFTs, as no one can sell such NFTs to a buy order.
What the attacker needed
A buy order for TaxTokensReceipt exists; user holds a TaxTokensReceipt NFT
The fix
The transferFrom function should also allow transfers where the sender or receiver is a legitimate buy order contract.
How it was found
- Bob creates a buy order for TaxTokensReceipt NFTs.
- Alice, holding a TaxTokensReceipt NFT, calls sellNFT on the buy order contract.
- The buy order contract attempts to transfer the NFT from Alice to itself.
- The transfer reverts because neither Alice nor the buy order contract is an authorised Debita contract.
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 where a special NFT (a receipt for tokens that charge a fee on transfer) can only be moved between certain contracts. The code forgot to include one type of contract (buy orders), so trying to sell the NFT to a buy order always fails.
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.