withdrawRemainingTokens() in the Erc1155Quest withdraws all tokens and does not consider the amount of unclaimed tokens #678
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
satisfactory
satisfies C4 submission criteria; eligible for awards
Lines of code
https://github.com/rabbitholegg/quest-protocol/blob/8c4c1f71221570b14a0479c216583342bd652d8d/contracts/Erc1155Quest.sol#L56-L62
Vulnerability details
Impact
The
withdrawRemainingTokens()
function in theErc1155Quest
contract does not consider the amount of unclaimed tokens. When the owner calls the function when the quest has ended, all tokens belonging to the contract will be withdrawn. Any user who has not yet used their receipt to claim their token(s) will no longer be able to claim them since all tokens has been withdrawn by the owner, leaving their receipts useless.Proof of Concept
The following test can be added in
quest-protocol/test/Erc1155Quest.spec.ts
to theclaim()
group (https://github.com/rabbitholegg/quest-protocol/blob/8c4c1f71221570b14a0479c216583342bd652d8d/test/Erc1155Quest.spec.ts#L199)The command
yarn hardhat test --grep "leaves no tokens behind"
can be used to run the testRecommended Mitigation Steps
Note that the
Erc20Quest
contract considers the unclaimed token amount and ensures this amount will be kept in the contract to allow users to claim their tokens even afterwithdrawRemainingTokens()
has been called, as can be seen on lines 84-86 inErc20Quest
(https://github.com/rabbitholegg/quest-protocol/blob/8c4c1f71221570b14a0479c216583342bd652d8d/contracts/Erc20Quest.sol#L84-L86)A similiar calculation should be introduced to
withdrawRemainingTokens()
in theErc1155Quest
contract.The text was updated successfully, but these errors were encountered: