Skip to content
Smart contracts Audit finding Intermediate

Attackers can use `reclaimContract()` to transfer assets in protocol to address(0)

The reclaimContract function transfers payment tokens to the address stored in bulls[contractId], which can be address(0) if the contract was never filled. An attacker can create a fake order that meets the expiry and unsettled conditions, causing the protocol to send assets to the zero address, resulting in a loss of funds.

Ruhum Follow with bin2chen, carrot and 5 others

Originally disclosed on Sherlock

Source: https://github.com/sherlock-audit/2022-11-bullvbear-judging/issues/127

Found by

Ruhum, bin2chen, carrot, kirk-baird, __141345__, hansfriese, GimelSec, 0x52

Summary

reclaimContract() would transfer payment tokens to bulls[contractId]. An attacker can make reclaimContract() transfer assets to address(0).

Vulnerability Detail

An attacker can use a fake order to trick reclaimContract(). The fake order needs to meet the following requirements:

  • block.timestamp > order.expiry.
  • !settledContracts[contractId].
  • !reclaimedContracts[contractId],.

The first one is easy to fulfilled, an attacker can decide the content of the fake order. And the others are all satisfied since the fake order couldn’t be settled or reclaimed before.

Thus, reclaimContract() would run this line: IERC20(order.asset).safeTransfer(bull, bullAssetAmount);. bull is address(0) since bulls[contractId] hasn’t been filled. If order.asset’s implementation doesn’t make sure to != address(0)(e.g., https://github.com/ConsenSys/Tokens/blob/fdf687c69d998266a95f15216b1955a4965a0a6d/contracts/eip20/EIP20.sol). The asset would be sent to address(0).

Solidity
    function reclaimContract(Order calldata order) public nonReentrant {
        bytes32 orderHash = hashOrder(order);

        // ContractId
        uint contractId = uint(orderHash);

        address bull = bulls[contractId];

        // Check that the contract is expired
        require(block.timestamp > order.expiry, "NOT_EXPIRED_CONTRACT");

        // Check that the contract is not settled
        require(!settledContracts[contractId], "SETTLED_CONTRACT");

        // Check that the contract is not reclaimed
        require(!reclaimedContracts[contractId], "RECLAIMED_CONTRACT");

        uint bullAssetAmount = order.premium + order.collateral;
        if (bullAssetAmount > 0) {
            // Transfer payment tokens to the Bull
            IERC20(order.asset).safeTransfer(bull, bullAssetAmount);
        }

        reclaimedContracts[contractId] = true;

        emit ReclaimedContract(orderHash, order);
    }

Impact

An attacker can use this vulnerability to transfer assets from BvB to address(0). It results in serious loss of funds.

Code Snippet

https://github.com/sherlock-audit/2022-11-bullvbear/blob/main/bvb-protocol/src/BvbProtocol.sol#L417-L443

Tool used

Manual Review

Recommendation

There are multiple solutions for this problem.

  1. check bulls[contractId] != address(0)
  2. check the order is matched matchedOrders[contractId].maker != address(0)

Discussion

datschill

PR fixing this issue : https://github.com/BullvBear/bvb-solidity/pull/4

jack-the-pug

Fix confirmed

The original report as published on Sherlock, by Ruhum. 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

Likely the function does not verify that the bull address is non-zero before transferring tokens.

Impact

An attacker can cause the protocol to transfer assets to address(0), resulting in a serious loss of funds.

What the attacker needed

None

The fix

The fix should add a check that the bull address is not the zero address, or verify that the order has been matched.

How it was found

  1. Create a fake order with an expiry in the past.
  2. Ensure the contract ID has not been settled or reclaimed.
  3. Call reclaimContract with the fake order.
  4. The function transfers the asset amount to address(0).

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 smart contract function that returns funds to a 'bull' (a participant) uses an address that might be empty (the zero address). If the contract was never matched, that address is zero. An attacker can craft a fake order that passes the checks, and the contract sends tokens to the zero address, where they are lost forever.

What is Smart contracts?

Flaws in on-chain code that let an attacker drain funds, freeze them or break the protocol's accounting.

More by Ruhum

View all

55 more disclosed reports, best first.

More from Bull v Bear

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Smart contract vulnerabilities

The lesson behind this report.

Flaws in on-chain code that let an attacker drain funds, freeze them or break the protocol's accounting.