Amount of tokens returned (nonClaimableTokens
) in withdrawRemainingTokens() is incorrect if withdrawFee() has been called
#252
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
Lines of code
https://github.com/rabbitholegg/quest-protocol/blob/8c4c1f71221570b14a0479c216583342bd652d8d/contracts/Erc20Quest.sol#L85
Vulnerability details
Impact
If withdrawFee() has been called, then the value of
nonClaimableTokens
in withdrawRemainingTokens() is incorrect. When this happens, the quest owner will get less tokens then they are supposed to when they call withdrawRemainingTokens()Proof of Concept
https://github.com/rabbitholegg/quest-protocol/blob/8c4c1f71221570b14a0479c216583342bd652d8d/contracts/Erc20Quest.sol#L85
Consider this line of code. Let the current balance = b.
If withdrawFee() is called immediately before withdrawRemainingTokens(), the caller (quest owner) will get
b - protocolFee() - protocolFee() - unclaimedTokens
tokens back (since balance after withdrawFee isb - protocolFee()
)If withdrawRemainingTokens() is not preceded by withdrawFee(), the caller (quest owner) will get
b - protocolFee() - unclaimedTokens
tokens backTools Used
VSCode
Recommended Mitigation Steps
Maintain a counter initialized to 0 (say protocolFeeCount). Set it to receiptRedeemers() at the end of withdrawFee().
https://github.com/rabbitholegg/quest-protocol/blob/8c4c1f71221570b14a0479c216583342bd652d8d/contracts/Erc20Quest.sol#L97
Then, in protocolFee(), this line should be changed to
return ((receiptRedeemers() - protocolFeeCount)* rewardAmountInWeiOrTokenId * questFee) / 10_000;
The text was updated successfully, but these errors were encountered: