Skip to content
Business logic Audit finding Intermediate

sendCollateralTo is unchecked in closeLoan() , which can cause user’s collateral NFT to be frozen

The closeLoan function transfers a collateral NFT to an arbitrary address using transferFrom, which does not check if the recipient can handle ERC721 tokens. If the recipient is a contract that cannot receive NFTs, the token becomes permanently stuck.

WatchPug Follow

Originally disclosed on Code4rena

Submitted by WatchPug, also found by berndartmueller, Dravee, hake, jah, and minhquanym

NFTLoanFacilitator.sol#L116-L126

function closeLoan(uint256 loanId, address sendCollateralTo) external override notClosed(loanId) {
    require(IERC721(borrowTicketContract).ownerOf(loanId) == msg.sender,
    "NFTLoanFacilitator: borrow ticket holder only");

    Loan storage loan = loanInfo[loanId];
    require(loan.lastAccumulatedTimestamp == 0, "NFTLoanFacilitator: has lender, use repayAndCloseLoan");

    loan.closed = true;
    IERC721(loan.collateralContractAddress).transferFrom(address(this), sendCollateralTo, loan.collateralTokenId);
    emit Close(loanId);
}

The sendCollateralTo will receive the collateral NFT when closeLoan() is called. However, if sendCollateralTo is a contract address that does not support ERC721, the collateral NFT can be frozen in the contract.

As per the documentation of EIP-721:

A wallet/broker/auction application MUST implement the wallet interface if it will accept safe transfers.

Ref: EIP-721

Recommended Mitigation Steps

Change to:

function closeLoan(uint256 loanId, address sendCollateralTo) external override notClosed(loanId) {
    require(IERC721(borrowTicketContract).ownerOf(loanId) == msg.sender,
    "NFTLoanFacilitator: borrow ticket holder only");

    Loan storage loan = loanInfo[loanId];
    require(loan.lastAccumulatedTimestamp == 0, "NFTLoanFacilitator: has lender, use repayAndCloseLoan");

    loan.closed = true;
    IERC721(loan.collateralContractAddress).safeTransferFrom(address(this), sendCollateralTo, loan.collateralTokenId);
    emit Close(loanId);
}

wilsoncusack (Backed Protocol) acknowledged, but disagreed with Medium severity and commented:

We use transferFrom and _mint instead of the safe versions to save gas. We think it is a reasonable expectation that users calling this should know what they are doing. We feel this is OK especially because other major protocols like Uniswap do this (Uniswap/NonfungiblePositionManager.sol#L156).

gzeon (judge) commented:

I believe Med Risk is a fair assessment given the mixed/inconsistent usage of safeTransferFrom and transferFrom in the contract.


The original report as published on Code4rena, by WatchPug. 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

The function uses transferFrom instead of safeTransferFrom, so it does not verify that the recipient contract implements the ERC721 receiver interface.

Impact

A user's collateral NFT could become permanently frozen if sent to a contract that cannot handle ERC721 tokens.

What the attacker needed

User calls closeLoan with a contract address; contract does not support ERC721

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 you close a loan, the contract sends your collateral NFT to an address you specify. The code uses a basic transfer method that does not check if the receiving address is able to handle NFTs. If you accidentally send it to a contract that cannot accept NFTs, the token gets stuck there forever.

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 WatchPug

View all

197 more disclosed reports, best first.

More from Papr contest

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.