Skip to content
Business logic Audit finding Intermediate

Bulls that are unable to receive NFTs will not be able to claim them later

The protocol stores NFTs for bulls that cannot receive them, but the only withdrawal function sends the NFT back to the same address, which will fail again. Thus, a bull contract that cannot accept NFTs will never be able to claim the NFT, leaving it stuck in the protocol.

cccz Follow with bin2chen, carrot and 7 others

Originally disclosed on Sherlock

Source: https://github.com/sherlock-audit/2022-11-bullvbear-judging/issues/4

Found by

cccz, bin2chen, carrot, 0xmuxyz, hansfriese, WATCHPUG, GimelSec, obront, rvierdiiev, 0xadrii

Summary

A lot of care has been taken to ensure that, if a bull has a contract address that doesn't accept ERC721s, the NFT is saved to withdrawableCollectionTokenId for later withdrawal. However, because there is no way to withdraw this token to a different address (and the original address doesn't accept NFTs), it will never be able to be claimed.

Vulnerability Detail

To settle a contract, the bear calls settleContract(), which sends their NFT to the bull, and withdraws the collateral and premium to the bear.

Solidity
try IERC721(order.collection).safeTransferFrom(bear, bull, tokenId) {}
catch (bytes memory) {
    // Transfer NFT to BvbProtocol
    IERC721(order.collection).safeTransferFrom(bear, address(this), tokenId);
    // Store that the bull has to retrieve it
    withdrawableCollectionTokenId[order.collection][tokenId] = bull;
}

uint bearAssetAmount = order.premium + order.collateral;
if (bearAssetAmount > 0) {
    // Transfer payment tokens to the Bear
    IERC20(order.asset).safeTransfer(bear, bearAssetAmount);
}

In order to address the case that the bull is a contract that can't accept NFTs, the protocol uses a try-catch setup. If the transfer doesn't succeed, it transfers the NFT into the contract, and sets withdrawableCollectionTokenId so that the specific NFT is attributed to the bull for later withdrawal.

However, assuming the bull isn't an upgradeable contract, this withdrawal will never be possible, because their only option is to call the same function safeTransferFrom to the same contract address, which will fail in the same way.

Solidity
function withdrawToken(bytes32 orderHash, uint tokenId) public {
    address collection = matchedOrders[uint(orderHash)].collection;

    address recipient = withdrawableCollectionTokenId[collection][tokenId];

    // Transfer NFT to recipient
    IERC721(collection).safeTransferFrom(address(this), recipient, tokenId);

    // This token is not withdrawable anymore
    withdrawableCollectionTokenId[collection][tokenId] = address(0);

    emit WithdrawnToken(orderHash, tokenId, recipient);
}

Impact

If a bull is a contract that can't receive NFTs, their orders will be matched, the bear will be able to withdraw their assets, but the bull's NFT will remain stuck in the BVB protocol contract.

Code Snippet

https://github.com/sherlock-audit/2022-11-bullvbear/blob/main/bvb-protocol/src/BvbProtocol.sol#L394-L406

https://github.com/sherlock-audit/2022-11-bullvbear/blob/main/bvb-protocol/src/BvbProtocol.sol#L450-L462

Tool used

Manual Review

Recommendation

There are a few possible solutions:

  • Add a to field in the withdrawToken function, which allows the bull to withdraw the NFT to another address
  • Create a function similar to transferPosition that can be used to transfer owners of a withdrawable NFT
  • Decide that you want to punish bulls who aren't able to receive NFTs, in which case there is no need to save their address or implement a withdrawToken function

Discussion

datschill

PR fixing another issue, removing the withdrawToken() method : https://github.com/BullvBear/bvb-solidity/pull/14

datschill

This issue isn't High, because in the default behavior, no smart contract can match an Order. So for a Bull to be a smart contract, the user needs to match an order (as a maker or a taker) with an EOA, then transfer his position to a smart contract. This would be kind of a poweruser move, so we consider that he should be aware that his smart contract should handle NFT reception. Whatsoever, the issue is fixed thanks to the PR#14, the user will be able to transfer his position to whatever EOA or smart contract he wants before calling reclaimContract() to retrieve ERC20 assets or ERC721.

jack-the-pug

Fix confirmed. The bull who wish to withdraw the NFT to another address shall call transferPosition() before reclaimContract().

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

The withdrawal function only allows sending the NFT to the original recipient, with no option to specify a different address.

Impact

If a bull is a contract that cannot receive NFTs, the NFT remains stuck in the protocol contract, though the issue is considered low severity because such a setup requires a power user and the fix allows transferring the position before reclaiming.

What the attacker needed

Bull is a contract that cannot receive NFTs; bull's position is transferred to that contract

The fix

The issue was fixed by removing the withdrawToken function and allowing the bull to transfer their position to another address before reclaiming.

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 bull (the party receiving an NFT) is a smart contract that cannot accept NFTs, the protocol holds the NFT for them. But the only way to get it back is to send it to the same contract, which will fail again. So the NFT is stuck 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 cccz

View all

104 more disclosed reports, best first.

More from Bull v Bear

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.