Skip to content
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

Calling Erc1155Quest.withdrawRemainingTokens function for an ERC1155 quest can possibly withdraw rewards that are associated with minted RabbitHole receipts #443

Closed
code423n4 opened this issue Jan 30, 2023 · 5 comments
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

Comments

@code423n4
Copy link
Contributor

Lines of code

https://github.com/rabbitholegg/quest-protocol/blob/main/contracts/Erc1155Quest.sol#L54-L63

Vulnerability details

Impact

The Erc20Quest.withdrawRemainingTokens function prevents the Erc20Quest contract's owner from withdrawing the unclaimed reward token amounts that are associated with the minted RabbitHole receipts after the quest is ended. However, this is not the case for the following Erc1155Quest.withdrawRemainingTokens function. After the ERC1155 quest is ended, if the rewards for some minted RabbitHole receipts are not withdrawn yet, calling the Erc1155Quest.withdrawRemainingTokens function by the Erc1155Quest contract's owner can transfer these unclaimed reward token amounts to the specified to_ address even though such owner has no malicious intent. Afterwards, regaining these deserved reward token amounts can be troublesome to the affected RabbitHole receipt holders, especially these who need to use their reward tokens in a timely manner.

https://github.com/rabbitholegg/quest-protocol/blob/main/contracts/Erc1155Quest.sol#L54-L63

    function withdrawRemainingTokens(address to_) public override onlyOwner {
        super.withdrawRemainingTokens(to_);
        IERC1155(rewardToken).safeTransferFrom(
            address(this),
            to_,
            rewardAmountInWeiOrTokenId,
            IERC1155(rewardToken).balanceOf(address(this), rewardAmountInWeiOrTokenId),
            '0x00'
        );
    }

Proof of Concept

Please append the following test in the withdrawRemainingTokens() describe block in quest-protocol\test\Erc1155Quest.spec.ts. This test will pass to demonstrate the described scenario.

    it.only('Calling withdrawRemainingTokens function for an ERC1155 quest can possibly withdraw rewards that are associated with minted RabbitHole receipts', async () => {
      // quest contract owns 100 reward tokens and owner owns no reward tokens
      expect(await deployedSampleErc1155Contract.balanceOf(deployedQuestContract.address, rewardAmount)).to.equal(100)
      expect(await deployedSampleErc1155Contract.balanceOf(owner.address, rewardAmount)).to.equal(0)

      // firstAddress owns a RabbitHole receipt but does not claim the associated rewards yet
      await deployedRabbitholeReceiptContract.mint(firstAddress.address, questId)
      await deployedQuestContract.start()

      await ethers.provider.send('evm_increaseTime', [20000])

      // owner calls withdrawRemainingTokens function after quest is ended
      await deployedQuestContract.connect(owner).withdrawRemainingTokens(owner.address)

      // all of the 100 reward tokens are transferred from quest contract to owner while firstAddress has not claimed any rewards yet
      expect(await deployedSampleErc1155Contract.balanceOf(deployedQuestContract.address, rewardAmount)).to.equal(0)
      expect(await deployedSampleErc1155Contract.balanceOf(owner.address, rewardAmount)).to.equal(100)

      // firstAddress is unable to claim rewards for its RabbitHole receipt
      await expect(
        deployedQuestContract.connect(firstAddress).claim()
      ).to.be.revertedWith('ERC1155: insufficient balance for transfer')

      await ethers.provider.send('evm_increaseTime', [-20000])
    })

Tools Used

VSCode

Recommended Mitigation Steps

The Erc1155Quest.withdrawRemainingTokens function can be updated to not allow any withdrawals of the unclaimed reward token amounts that are associated with the minted RabbitHole receipts so it becomes consistent with the Erc20Quest.withdrawRemainingTokens function.

@code423n4 code423n4 added 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 labels Jan 30, 2023
code423n4 added a commit that referenced this issue Jan 30, 2023
@c4-judge c4-judge closed this as completed Feb 6, 2023
@c4-judge
Copy link
Contributor

c4-judge commented Feb 6, 2023

kirk-baird marked the issue as duplicate of #42

@c4-judge c4-judge added downgraded by judge Judge downgraded the risk level of this issue QA (Quality Assurance) Assets are not at risk. State handling, function incorrect as to spec, issues with clarity, syntax and removed 2 (Med Risk) Assets not at direct risk, but function/availability of the protocol could be impacted or leak value labels Feb 10, 2023
@c4-judge
Copy link
Contributor

kirk-baird changed the severity to QA (Quality Assurance)

@c4-judge c4-judge reopened this Feb 10, 2023
@c4-judge c4-judge added 3 (High Risk) Assets can be stolen/lost/compromised directly and removed downgraded by judge Judge downgraded the risk level of this issue QA (Quality Assurance) Assets are not at risk. State handling, function incorrect as to spec, issues with clarity, syntax labels Feb 10, 2023
@c4-judge
Copy link
Contributor

This previously downgraded issue has been upgraded by kirk-baird

@c4-judge
Copy link
Contributor

kirk-baird marked the issue as satisfactory

@c4-judge c4-judge added the satisfactory satisfies C4 submission criteria; eligible for awards label Feb 14, 2023
@c4-judge c4-judge added 2 (Med Risk) Assets not at direct risk, but function/availability of the protocol could be impacted or leak value downgraded by judge Judge downgraded the risk level of this issue and removed 3 (High Risk) Assets can be stolen/lost/compromised directly labels Feb 23, 2023
@c4-judge
Copy link
Contributor

kirk-baird changed the severity to 2 (Med Risk)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
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
Projects
None yet
Development

No branches or pull requests

2 participants