Skip to content
DoS Audit finding Intermediate

Lenders and borrowers can not claim liquidation token after NFT collateral auction sold

The function getDataByReceipt reverts when the receipt token has been burned, which happens after the auction buyer withdraws the veNFT. This prevents lenders and the borrower from claiming the liquidation token after the NFT collateral auction is sold.

0xc0ffEE Follow

Originally disclosed on Sherlock

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

Found by

0xc0ffEE

Summary

The incorrect logic in function veNFTAerodrome::getDataByReceipt() will cause the lenders and borrowers unable to claim liquidation token after the NFT auction sold

Root Cause

  • The function DebitaV3Loan::claimCollateralAsNFTLender() allows the lenders to claim the liquidation token after the NFT collateral auction is sold.
  • The function DebitaV3Loan::claimCollateralNFTAsBorrower() allows the borrower to claim the liquidation token in case partial default
  • The 2 functions above call veNFTAerodrome::getDataByReceipt() to retrieve the liquidation token's decimals to calculate the payment amount
  • These 2 flows above can be reverted because of unhandled case in the function veNFTAerodrome::getDataByReceipt(). The mentioned unhandled case is when there is no owner of the receipt token, such that ownerOf(receiptID) reverts because of non-exist token.
Solidity
    function getDataByReceipt(
        uint receiptID
    ) public view returns (receiptInstance memory) {
        veNFT veContract = veNFT(nftAddress);
        veNFTVault vaultContract = veNFTVault(s_ReceiptID_to_Vault[receiptID]);
        uint nftID = vaultContract.attached_NFTID();
        IVotingEscrow.LockedBalance memory _locked = veContract.locked(nftID);
        uint _decimals = ERC20(_underlying).decimals();
        address manager = vaultContract.managerAddress();
@>        address currentOwnerOfReceipt = ownerOf(receiptID);
        receiptInstance memory receiptData = receiptInstance({
            receiptID: receiptID,
            attachedNFT: nftID,
            lockedAmount: uint(int(_locked.amount)),
            lockedDate: _locked.end,
            decimals: _decimals,
            vault: address(vaultContract),
            underlying: _underlying,
            OwnerIsManager: manager == currentOwnerOfReceipt
        });
        return receiptData;
    }
Solidity
    function ownerOf(uint256 tokenId) public view virtual returns (address) {
        return _requireOwned(tokenId);
    }
...
    function _requireOwned(uint256 tokenId) internal view returns (address) {
        address owner = _ownerOf(tokenId);
        if (owner == address(0)) {
@>            revert ERC721NonexistentToken(tokenId);
        }
        return owner;
    }

This state can be reached when the auction buyer withdraws veNFT by calling veNFTVault::withdraw(), which will burn the receipt token

Solidity
    function withdraw() external nonReentrant {
        IERC721 veNFTContract = IERC721(veNFTAddress);
        IReceipt receiptContract = IReceipt(factoryAddress);
        uint m_idFromNFT = attached_NFTID;
        address holder = receiptContract.ownerOf(receiptID);

        // RECEIPT HAS TO BE ON OWNER WALLET
        require(attached_NFTID != 0, "No attached nft");
        require(holder == msg.sender, "Not Holding");
        receiptContract.decrease(managerAddress, m_idFromNFT);

        delete attached_NFTID;

        // First: burn receipt
@>        IReceipt(factoryAddress).burnReceipt(receiptID);
        IReceipt(factoryAddress).emitWithdrawn(address(this), m_idFromNFT);
        // Second: send them their NFT
        veNFTContract.transferFrom(address(this), msg.sender, m_idFromNFT);
    }
Solidity
    function burnReceipt(uint id) external onlyVault {
@>        _burn(id);
    }

Internal pre-conditions

No response

External pre-conditions

No response

Attack Path

  • A borrower deposits veNFT to veNFTVault by calling veNFTAerodrome::deposit(), effectively receives a Receipt token
  • The borrower creates borrow offer with the above Receipt token as collateral
  • The borrow offer is matched with many lend offers
  • The borrower does not pay debt for all lend offers before the deadline and a lender calls createAuctionForCollateral to create an auction for the collateral
  • Auction is sold
  • The auction buyer, now the current holder of the Receipt token, decides to withdraw the veNFT from the vault by calling veNFTVault::withdraw()
  • At this time, both borrower and lenders can not claim liquidation token

Impact

  • Loss of liquidation for both lenders and borrower

PoC

Update the test testDefaultAndAuctionCall in file test/fork/Loan/ltv/OracleOneLenderLoanReceipt.t.sol as below:

Solidity

    function testDefaultAndAuctionCall() public {
        MatchOffers();
        uint256[] memory indexes = allDynamicData.getDynamicUintArray(1);
        indexes[0] = 0;
        vm.warp(block.timestamp + 8640010);
        DebitaV3LoanContract.createAuctionForCollateral(0);
        DutchAuction_veNFT auction = DutchAuction_veNFT(DebitaV3LoanContract.getAuctionData().auctionAddress);
        DutchAuction_veNFT.dutchAuction_INFO memory auctionData = auction.getAuctionData();

        vm.warp(block.timestamp + (86400 * 10) + 1);

        address buyer = 0x5C235931376b21341fA00d8A606e498e1059eCc0;
        deal(AERO, buyer, 100e18);
        vm.startPrank(buyer);

        AEROContract.approve(address(auction), 100e18);
        auction.buyNFT();
        vm.stopPrank();
        address ownerOfNFT = receiptContract.ownerOf(receiptID);


        // buyer withdraws NFT
        vm.startPrank(ownerOfNFT);
        address vaultAddress = receiptContract.s_ReceiptID_to_Vault(receiptID);
        veNFTVault vault = veNFTVault(vaultAddress);
        vault.withdraw();

        // lender claim liquidation token
        vm.stopPrank();
        vm.expectRevert();
        DebitaV3LoanContract.claimCollateralAsLender(0);
    }

Run the test and console shows:

Bash
Ran 1 test for test/fork/Loan/ltv/OracleOneLenderLoanReceipt.t.sol:DebitaAggregatorTest
[PASS] testDefaultAndAuctionCall() (gas: 3381044)

Mitigation

1/ Update the function getDataByReceipt() to handle the case non-exist token, instead of reverting 2/ OR update the logic to fetch the decimals in functions claimCollateralAsNFTLender and claimCollateralNFTAsBorrower

Discussion

sherlock-admin2

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

The original report as published on Sherlock, by 0xc0ffEE. 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

Likely, the function getDataByReceipt calls ownerOf on a receipt token that may have been burned, causing a revert instead of handling the non-existent token case.

Impact

Lenders and the borrower lose their liquidation proceeds because they cannot claim the tokens after the auction.

What the attacker needed

Borrower uses veNFT as collateral; loan defaults and auction is created; auction is sold; buyer withdraws veNFT

The fix

The protocol team fixed this issue by updating the function to handle non-existent tokens or by fetching decimals differently.

How it was found

  1. Borrower deposits veNFT into veNFTVault and receives a receipt token.
  2. Borrower creates a borrow offer using the receipt token as collateral.
  3. Borrow offer is matched with lend offers.
  4. Borrower defaults and a lender creates an auction for the collateral.
  5. Auction is sold and the buyer withdraws the veNFT, burning the receipt token.
  6. Lenders and borrower attempt to claim liquidation token but the transaction reverts.

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.

When a borrower uses an NFT as collateral, the system gives them a receipt token. If the loan defaults, the NFT is auctioned and the buyer can withdraw the NFT, which destroys the receipt token. Later, when lenders or the borrower try to claim their share of the sale, the system tries to read data from the destroyed receipt token and fails, so they cannot get their money.

What is DoS?

A request that exhausts resources or crashes a component. Many programs forbid testing it; reports usually show it from code, not by attacking.

More by 0xc0ffEE

View all

27 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.

Denial of service

The lesson behind this report.

A request that exhausts resources or crashes a component. Many programs forbid testing it; reports usually show it from code, not by attacking.