ERC1155Quest
contract owner could withdraw all users rewards when the quest has ended, if users don't claim a reward before the end
#298
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-528
edited-by-warden
satisfactory
satisfies C4 submission criteria; eligible for awards
Lines of code
https://github.com/rabbitholegg/quest-protocol/blob/8c4c1f71221570b14a0479c216583342bd652d8d/contracts/Erc1155Quest.sol#L54
Vulnerability details
Impact
When the quest ended, the
ERC1155Quest
contract owner could withdraw all remaining tokens, including users' reward tokens which are not claimed before the end. Because of that, if the user wants to claim their rewards after the quest end and after theERC1155Quest
contract owner calls a functionwithdrawRemainingTokens
it will get an error that there are not enough tokens at theERC1155Quest
contract and not possible to claim a reward.On the other side, in the
ERC20Quest
contract by lines Erc20Quest.sol#L84:L86 there is calculation how many tokens are not claimed, so the contract owner will get the difference between current contract balance and not claimed rewards. Because of that calculation, users could claim their reward after theERC20Quest
ended and the contract owner calls a functionwithdrawRemainingTokens
.Proof of Concept
Add two tests in
Erc1155Quest.spec.ts
As seen from the first test, if the account
firstAddress
claims reward before the owner callswithdrawRemainingTokens
, all will be good, andfirstAddress
will have 1 unit of reward token, and the contract owner will have 99 units.But, if a contract owner calls
withdrawRemainingTokens
before the accountfirstAddress
claim rewards, he will get all reward tokens (he will have 100 units), and on the other side,firstAddress
will get errorERC1155: insufficient balance for transfer
.Tools Used
VSCode, Hardhat, Solidity Visual Developer
Recommended Mitigation Steps
In the
ERC1155Quest.sol
contract (function Erc1155Quest.sol#L54):uint unclaimedRewards = questFactoryContract.getNumberMinted(questId) - redeemedTokens;
IERC1155(rewardToken).balanceOf(address(this), rewardAmountInWeiOrTokenId) - unclaimedRewards
The text was updated successfully, but these errors were encountered: