Skip to content
Business logic Audit finding Intermediate

Buyer on secondary NFT market can lose fund if they buy a NFT that is already used to claim the reward

A buyer on a secondary NFT marketplace can purchase an NFT that has already been used to claim a reward, leaving them unable to claim that reward themselves. The seller can front-run the buyer's purchase by claiming the reward first, so the buyer loses the expected value.

ladboy233 Follow with CodingNameKiki, adriro and 6 others

Originally disclosed on Code4rena

Submitted by ladboy233, also found by CodingNameKiki, adriro, StErMi, Tricko, rbserver, 0xmrhoodie, 0x4non, and ElKu

https://github.com/rabbitholegg/quest-protocol/blob/8c4c1f71221570b14a0479c216583342bd652d8d/contracts/Quest.sol#L113

Let us look closely into the Quest.sol#claim function

/// @notice Allows user to claim the rewards entitled to them
/// @dev User can claim based on the (unclaimed) number of tokens they own of the Quest
function claim() public virtual onlyQuestActive {
	if (isPaused) revert QuestPaused();

	uint[] memory tokens = rabbitHoleReceiptContract.getOwnedTokenIdsOfQuest(questId, msg.sender);

	if (tokens.length == 0) revert NoTokensToClaim();

	uint256 redeemableTokenCount = 0;
	for (uint i = 0; i < tokens.length; i++) {
		if (!isClaimed(tokens[i])) {
			redeemableTokenCount++;
		}
	}

	if (redeemableTokenCount == 0) revert AlreadyClaimed();

	uint256 totalRedeemableRewards = _calculateRewards(redeemableTokenCount);
	_setClaimed(tokens);
	_transferRewards(totalRedeemableRewards);
	redeemedTokens += redeemableTokenCount;

	emit Claimed(msg.sender, totalRedeemableRewards);
}

After the NFT is used to claim, the _setClaimed(token) is called to mark the NFT as used to prevent double claiming.

/// @notice Marks token ids as claimed
/// @param tokenIds_ The token ids to mark as claimed
function _setClaimed(uint256[] memory tokenIds_) private {
	for (uint i = 0; i < tokenIds_.length; i++) {
		claimedList[tokenIds_[i]] = true;
	}
}

The NFT is also tradeable in the secondary marketplace. I would like to make a reasonable assumption that user wants to buy the NFT because they can use the NFT to claim the reward, which means after the reward is claimed, the NFT lose value.

Consider the case below:

  1. User A has 1 NFT, has he can use the NFT to claim 1 ETH reward.
  2. User A place a sell order in opensea and sell the NFT for 0.9 ETH.
  3. User B see the sell order and find it a good trae, he wants to buy the NFT.
  4. User B submit a buy order, User A at the same time submit the claimReward transaction.
  5. User A’s transaction executed first, reward goes to User A, then User B transaction executed, NFT ownership goes to User B, but user B find out that the he cannot claim the reward becasue the reward is already claimed by User A.

User A can intentionally front-run User B’s buy transaction by monitoring the mempool in polygon using the service

https://www.blocknative.com/blog/polygon-mempool

Or it could be just two users submit transactions at the same time and User A’s claim transaction happens to execute first.

Recommended Mitigation Steps

Disable NFT transfer and trade once the NFT is used to claim the reward.

waynehoover (RabbitHole) acknowledged


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

Likely the NFT remains transferable after it has been used to claim a reward, so a buyer cannot tell whether the reward is still available.

Impact

A buyer could pay for an NFT whose reward has already been claimed, losing the expected reward value; the report notes this can happen by front-running or by chance.

What the attacker needed

NFT is tradeable on a secondary market; seller can claim before buyer's purchase; buyer expects to claim the reward

How it was found

  1. User A owns an NFT that can claim a reward.
  2. User A lists the NFT for sale on a secondary marketplace.
  3. User B submits a buy order for the NFT.
  4. User A submits a claim transaction at the same time.
  5. User A's claim executes first, so the reward goes to User A.
  6. User B's buy executes next, but User B cannot claim the reward because it is already claimed.

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.

An NFT is a digital token that can be bought and sold. In this system, owning a particular NFT lets you claim a reward, but once claimed, that NFT cannot be used again. If someone sells you an NFT after they have already claimed its reward, you pay for something that no longer gives you the reward.

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 ladboy233

View all

47 more disclosed reports, best first.

More from RabbitHole Quest Protocol 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.