Skip to content
DoS Audit finding Intermediate

DOS risk if enough tokens are minted in Quest.claim can lead, at least, to transaction fee lost

The claim function iterates over all tokens a user owns for a quest, which can exceed the block gas limit if a user accumulates many tokens, causing the transaction to fail. An attacker can grief a user by sending them many tokens, forcing them to lose gas fees when claiming.

carlitox477 Follow with trustindistrust, ArmedGoose and 24 others

Originally disclosed on Code4rena

Submitted by carlitox477, also found by trustindistrust, ArmedGoose, libratus, luxartvinsec, adriro, 0xRobocop, UdarTeam, betweenETHlines, manikantanynala97, minhquanym, lukris02, cryptojedi88, horsefacts, glcanvas, glcanvas, Atarpara, simon135, mookimgo, gzeon, IllIllI, p4st13r4, thekmj, evan, Tointer, 0xbepresent, and ladboy233

https://github.com/rabbitholegg/quest-protocol/blob/8c4c1f71221570b14a0479c216583342bd652d8d/contracts/Quest.sol#L99 https://github.com/rabbitholegg/quest-protocol/blob/8c4c1f71221570b14a0479c216583342bd652d8d/contracts/RabbitHoleReceipt.sol#L117-L133

claim function can be summaraized in next steps:

  1. Check that the quest is active
  2. Check the contract is not paused
  3. Get tokens corresponding to msg.sender for questId using rabbitHoleReceiptContract.getOwnedTokenIdsOfQuest: DOS
  4. Check that msg.sender owns at least one token
  5. Count non claimed tokens
  6. Check there is at least 1 unclaimed token
  7. Calculate redeemable rewards: _calculateRewards(redeemableTokenCount);
  8. Set all token to claimed state
  9. Update redeemedTokens
  10. Emit claim event

The problem with this functions relays in its dependency on RabbitHoleReceipt.getOwnedTokenIdsOfQuest. It’s behaviour can be summarized in next steps:

  1. Get queried balance (claimingAddress_)
  2. Get claimingAddress_ owned tokens
  3. Filter tokens corresponding to questId_
  4. Return token of claimingAddress_ corresponding to questId_

If a user actively participates in multiple quests and accumulates a large number of tokens, the claim function may eventually reach the block gas limit. As a result, the user may be unable to successfully claim their earned tokens.

Impact

It can be argued that function ERC721.burn can address the potential DOS risk in the claim process. However, it is important to note the following limitations and drawbacks associated with this approach:

  1. Utilizing ERC721.burn does not prevent the user from incurring network fees if a griefer, who has already claimed their rewards, sends their tokens to the user with the intent of causing a DOS and inducing loss of gas.
  2. If the user has not claimed any rewards from their accumulated tokens, they will still be forced to burn at least some of their tokens, resulting in a loss of these assets.

Proof of Concept

Griefing

  1. Alice has took part in many quests, and want to recieve her rewards, so she call Quest.claim() function
  2. Bob also has already claimed many rewards from many quest, and decide to frontrun alice an send her all his tokens to DOS her
  3. Alice run out of gas, she lose transaction fees.

Lose of unclaimed rewards

  1. Alice always takes part in many quests, but never claims her rewards. She trusts RabbitHole protocol and is waiting to have much more rewards to claim in order to save some transaction fees.
  2. When Alice decide to call claim function she realizes that she has run out of gas.

Then, Alice can only burn some of her tokens to claim at least some rewards.

Code

Code sample

Recommended Mitigation steps

If a user can send a token list by parameter to claim function, then this vector attack can be mitigated.

To do this add next function to RabbitHoleReceipt.sol:

function checkTokenCorrespondToQuest(uint tokenId, string memory questId_) external view returns(bool){
    return keccak256(bytes(questIdForTokenId[tokenId])) == keccak256(bytes(questId_));
}

Then modify Quest.claim:

// Quest.sol
-   function claim() public virtual onlyQuestActive {
+   function claim(uint[] memory tokens) public virtual onlyQuestActive {
        if (isPaused) revert QuestPaused();

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

        // require(tokens.length > 0)
        if (tokens.length == 0) revert NoTokensToClaim();

        uint256 redeemableTokenCount = 0;
        for (uint i = 0; i < tokens.length; i++) {
            // Check that the token correspond to this quest
            require(rabbitHoleReceiptContract.checkTokenCorrespondToQuest(tokens[i],questId))

-           if (!isClaimed(tokens[i])) {
+           if (!isClaimed(tokens[i]) && rabbitHoleReceiptContract.checkTokenCorrespondToQuest(tokens[i],questId)) {
                redeemableTokenCount++;
            }
        }

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

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

        emit Claimed(msg.sender, totalRedeemableRewards);
    }

kirk-baird (judge) decreased severity to Medium

waynehoover (RabbitHole) acknowledged


The original report as published on Code4rena, by carlitox477. 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 claim function processes an unbounded array of token IDs, which can grow without limit and exceed the block gas limit.

Impact

A user may be unable to claim rewards and lose gas fees, and may be forced to burn tokens to claim at least some rewards.

What the attacker needed

Attacker has many tokens; victim has many tokens; attacker can frontrun victim

The fix

The claim function should accept a list of token IDs as a parameter so the user controls which tokens are processed, avoiding an unbounded loop.

How it was found

  1. Alice participates in many quests and accumulates many tokens.
  2. Bob, who has already claimed rewards, frontruns Alice and sends her all his tokens.
  3. Alice calls claim and runs out of gas, losing transaction fees.

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 claim rewards, the contract looks at every token you own for that quest. If you have too many tokens, the list becomes so long that the transaction runs out of gas and fails. Someone else can send you many tokens to make this happen, and you lose the fee you paid for the failed transaction.

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 carlitox477

View all

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

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.