Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Quest owner can withdraw funds before the quest has ended #49

Closed
code423n4 opened this issue Jan 26, 2023 · 4 comments
Closed

Quest owner can withdraw funds before the quest has ended #49

code423n4 opened this issue Jan 26, 2023 · 4 comments
Labels
2 (Med Risk) Assets not at direct risk, but function/availability of the protocol could be impacted or leak value bug Something isn't working unsatisfactory does not satisfy C4 submission criteria; not eligible for awards

Comments

@code423n4
Copy link
Contributor

Lines of code

https://github.com/rabbitholegg/quest-protocol/blob/8c4c1f71221570b14a0479c216583342bd652d8d/contracts/Erc20Quest.sol#L78-L87

Vulnerability details

Impact

The withdrawRemainingTokens() function is supposed to allow the quest owner to withdraw any remaining funds after the quest has ended. But, the function is callable at any time. The owner is able to withdraw the tokens before any user has minted a receipt or claimed their reward. Since these rewards are used as a form of payment for finishing a quest, this results in a loss of funds for users.

Proof of Concept

The withdrawRemainingTokens() function implements no check to prevent the owner from calling it before the endTime was reached:

    function withdrawRemainingTokens(address to_) public override onlyOwner {
        super.withdrawRemainingTokens(to_);

        uint unclaimedTokens = (receiptRedeemers() - redeemedTokens) * rewardAmountInWeiOrTokenId;
        uint256 nonClaimableTokens = IERC20(rewardToken).balanceOf(address(this)) - protocolFee() - unclaimedTokens;
        IERC20(rewardToken).safeTransfer(to_, nonClaimableTokens);
    }
  1. Alice creates a quest
  2. Alice funds the quest with 100,000 tokens and starts it
  3. Alice calls withdrawRemainingTokens() right after starting it to withdraw 80,000 tokens (20,000 are reserved for the protocol and thus not accessible)

Users will be able to claim their receipts until the remaining 20,000 tokens are distributed. That means that only 1/4 of the users are able to withdraw their rewards. Additionally, the protocol won't be able to claim their fees either since there are no funds left in the contract.

Tools Used

none

Recommended Mitigation Steps

Add the following check to withdrawRemainingRewards():

require(block.timestamp > endTime);
@code423n4 code423n4 added 2 (Med Risk) Assets not at direct risk, but function/availability of the protocol could be impacted or leak value bug Something isn't working labels Jan 26, 2023
code423n4 added a commit that referenced this issue Jan 26, 2023
@c4-judge c4-judge closed this as completed Feb 3, 2023
@c4-judge
Copy link
Contributor

c4-judge commented Feb 3, 2023

kirk-baird marked the issue as duplicate of #42

@kirk-baird
Copy link

This issue is invalid. The check exists in super.withdrawRemainingTokens() here which has the modifier onlyAdminWithdrawAfterEnd

@c4-judge c4-judge reopened this Feb 6, 2023
@c4-judge
Copy link
Contributor

c4-judge commented Feb 6, 2023

kirk-baird marked the issue as not a duplicate

@c4-judge c4-judge closed this as completed Feb 6, 2023
@c4-judge c4-judge added the unsatisfactory does not satisfy C4 submission criteria; not eligible for awards label Feb 6, 2023
@c4-judge
Copy link
Contributor

c4-judge commented Feb 6, 2023

kirk-baird marked the issue as unsatisfactory:
Invalid

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
2 (Med Risk) Assets not at direct risk, but function/availability of the protocol could be impacted or leak value bug Something isn't working unsatisfactory does not satisfy C4 submission criteria; not eligible for awards
Projects
None yet
Development

No branches or pull requests

3 participants