Skip to content
Business logic Audit finding Intermediate

withdrawNftWithInterest() possible take away other Lien’s NFT

The withdrawNftWithInterest function allowed a lender to withdraw an NFT even when another lien on the same NFT was active, because it only checked that the caller was the lender and did not verify that the lien had no active loan. An attacker could take away another lien's NFT, causing loss of the NFT and funds.

bin2chen Follow with rbserver, d3e4 and 1 other

Originally disclosed on Code4rena

Submitted by bin2chen, also found by rbserver, d3e4, and minhquanym

Proof of Concept

withdrawNftWithInterest() is used to retrieve NFT. The only current restriction is if you can transfer out of NFT, it means an inactive loan.

    function withdrawNftWithInterest(Lien calldata lien, uint256 lienId) external override validateLien(lien, lienId) {
        if (msg.sender != lien.lender) {
            revert Errors.Unauthorized();
        }

        // delete lien
        delete liens[lienId];

        // transfer NFT back to lender
        /// @dev can withdraw means NFT is currently in contract without active loan,
        /// @dev the interest (if any) is already accured to lender at NFT acquiring time
        IERC721(lien.collection).safeTransferFrom(address(this), msg.sender, lien.tokenId);
...

However, the current protocol does not restrict the existence of only one Lien in the same NFT.

For example, the following scenario.

  1. Alice transfers NFT_A and supply Lien[1].
  2. Bob executes sellNftToMarket().
  3. Jack buys NFT_A from the market.
  4. Jack transfers NFT_A and supply Lien[2].
  5. Alice executing withdrawNftWithInterest(1) is able to get NFTA successfully (because step 4 NFTA is already in the contract). This results in the deletion of lien[1], and Lien[2]‘s NFT_A is transferred away.

The result is: Jack’s NFT is lost and Bob’s funds are also lost.

Recommended Mitigation Steps

Need to determine whether there is a Loan

    function withdrawNftWithInterest(Lien calldata lien, uint256 lienId) external override validateLien(lien, lienId) {
        if (msg.sender != lien.lender) {
            revert Errors.Unauthorized();
        }

+       require(lien.loanStartTime == 0,"Active Loan");

Assessed type

Context

adriro (warden) commented:

Nice finding

wukong-particle (Particle) confirmed and commented:

Fixed.


The original report as published on Code4rena, by bin2chen. 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 did not verify that the lien had no active loan before transferring the NFT, allowing withdrawal even when another lien on the same NFT was active.

Impact

Jack's NFT is lost and Bob's funds are also lost.

What the attacker needed

Multiple liens on the same NFT; attacker is a lender

The fix

The function should check that the lien has no active loan before allowing withdrawal.

How it was found

  1. Alice transfers NFT_A and supplies Lien[1].
  2. Bob executes sellNftToMarket().
  3. Jack buys NFT_A from the market.
  4. Jack transfers NFT_A and supplies Lien[2].
  5. Alice executes withdrawNftWithInterest(1) and gets NFT_A, deleting Lien[1] and taking Lien[2]'s NFT_A.

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.

In this system, people can lend NFTs and borrow against them. A function meant to return an NFT to its lender did not check if the NFT was currently being used as collateral for another loan. So a lender could take back an NFT that was still securing someone else's loan, leaving that other person without their 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 bin2chen

View all

139 more disclosed reports, best first.

More from Particle Leverage AMM Protocol Invitational

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.