Funds will get stuck forever in the Erc20Quest contract if withdrawFee() is called before withdrawRemainingTokens() #246
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#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 thewithdrawRemainingTokens
function, when calculating the amount of tokens to withdraw, theprotocolFee()
is deducted from it. But if thewithdrawFee
was already called there is no need to deduct it. Thus Quest admin loses tokens equal toprotocolFee
.Proof of Concept
The unfortunate event happens as such:
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.protocolFee()
once again, which is already deducted from the contract balance.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.The text was updated successfully, but these errors were encountered: