-
Notifications
You must be signed in to change notification settings - Fork 2
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
Erc20Quest.sol: withdrawRemainingTokens function calculates wrong amount after protocol fees are withdrawn #61
Comments
kirk-baird marked the issue as duplicate of #42 |
kirk-baird marked the issue as not a duplicate |
kirk-baird marked the issue as primary issue |
waynehoover marked the issue as sponsor confirmed |
kirk-baird changed the severity to 3 (High Risk) |
kirk-baird marked issue #122 as primary and marked this issue as a duplicate of 122 |
kirk-baird marked the issue as satisfactory |
kirk-baird changed the severity to 2 (Med Risk) |
Lines of code
https://github.com/rabbitholegg/quest-protocol/blob/8c4c1f71221570b14a0479c216583342bd652d8d/contracts/Erc20Quest.sol#L81-L87
Vulnerability details
Impact
The
Erc20Quest.withdrawRemainingTokens
function (https://github.com/rabbitholegg/quest-protocol/blob/8c4c1f71221570b14a0479c216583342bd652d8d/contracts/Erc20Quest.sol#L81-L87) is used to withdraw all remaining reward tokens once theendTime
is reached.The issue is that this function incorporates the
protocolFee
into its calculation.The
protocolFee
however can already be paid out when theErc20Quest.withdrawRemainingTokens
function is called. There is no mechanism by whichErc20Quest.withdrawFee()
must be called afterErc20Quest.withdrawRemainingTokens
.At the very least this results in a withdrawn amount that is too small if protocol fees have been withdrawn before.
However the fact that protocol fees are subtracted that are not in the contract anymore can also make the calculation underflow which causes an amount up to the protocol fees to be stuck in the contract.
Proof of Concept
The calculation to determine the amount of tokens to withdraw is this:
https://github.com/rabbitholegg/quest-protocol/blob/8c4c1f71221570b14a0479c216583342bd652d8d/contracts/Erc20Quest.sol#L85
Assume the following:
In this situation all 40 USDC should be withdrawn because there are no
unclaimedTokens
and theprotocolFee
is already paid out.However the calculation reverts which causes the 40 USDC to be stuck in the contract.
Tools Used
VSCode
Recommended Mitigation Steps
I discussed this issue with the sponsor and it was decided that probably the best solution is to save the yet to be paid fees in a
uint
variable that is subtracted from when fees are paid out.This variable is added to when receipts are minted.
This solution also requires a modification of the data flow, i.e. the quest contract must know when a new receipt is minted.
The sponsor mentioned that this will be investigated as part of a broader refactoring of the data flow.
The text was updated successfully, but these errors were encountered: