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

Funds will get stuck forever in the Erc20Quest contract if withdrawFee() is called before withdrawRemainingTokens() #246

Closed
code423n4 opened this issue Jan 29, 2023 · 5 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 downgraded by judge Judge downgraded the risk level of this issue duplicate-122 satisfactory satisfies C4 submission criteria; eligible for awards

Comments

@code423n4
Copy link
Contributor

Lines of code

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

Vulnerability details

Impact

withdrawFee() is used for sending the protocol fees to protocolFeeRecipient. And withdrawRemainingTokens() is used for transferring nonClaimableTokens back to the Quest admin. In the withdrawRemainingTokens function, when calculating the amount of tokens to withdraw, the protocolFee() is deducted from it. But if the withdrawFee was already called there is no need to deduct it. Thus Quest admin loses tokens equal to protocolFee.

Proof of Concept

The unfortunate event happens as such:

  1. Quest has ended. Users and Admins are happy.
  2. Someone calls the withdrawFee() function and the protocol fees are sent to the address set by the factory contract. So the balance of the contract is less now.
  3. The Quest admin wakes up late and tries to withdraw the tokens which are not supposed to be claimed by anyone. The exact amount of tokens sent to him are calculated as follows:
uint256 nonClaimableTokens = IERC20(rewardToken).balanceOf(address(this)) - protocolFee() - unclaimedTokens;
  1. Here the formula deducts the protocolFee() once again, which is already deducted from the contract balance.
  2. Which means the Quest admin will loose tokens worth of protocolFee.

Tools Used

VS code, Manual analysis

Recommended Mitigation Steps

I suggest, once the protocol fees are withdrawn, it should be marked as such with a state variable. And then use this state variable to decide whether the protocolFee should be deducted from the contract balance.

@code423n4 code423n4 added 3 (High Risk) Assets can be stolen/lost/compromised directly bug Something isn't working labels Jan 29, 2023
code423n4 added a commit that referenced this issue Jan 29, 2023
@c4-judge
Copy link
Contributor

c4-judge commented Feb 5, 2023

kirk-baird marked the issue as duplicate of #42

@c4-judge
Copy link
Contributor

c4-judge commented Feb 6, 2023

kirk-baird marked the issue as not a duplicate

@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 duplicate of #61

@c4-judge c4-judge closed this as completed Feb 6, 2023
@c4-judge c4-judge added the satisfactory satisfies C4 submission criteria; eligible for awards label Feb 14, 2023
@c4-judge
Copy link
Contributor

kirk-baird marked the issue as satisfactory

@c4-judge c4-judge added 2 (Med Risk) Assets not at direct risk, but function/availability of the protocol could be impacted or leak value downgraded by judge Judge downgraded the risk level of this issue and removed 3 (High Risk) Assets can be stolen/lost/compromised directly labels Feb 23, 2023
@c4-judge
Copy link
Contributor

kirk-baird changed the severity to 2 (Med Risk)

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 downgraded by judge Judge downgraded the risk level of this issue duplicate-122 satisfactory satisfies C4 submission criteria; eligible for awards
Projects
None yet
Development

No branches or pull requests

2 participants