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.
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).
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
Tool used
Manual Review
Recommendation
There are multiple solutions for this problem.
- check
bulls[contractId] != address(0) - 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
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
- Create a fake order with an expiry in the past.
- Ensure the contract ID has not been settled or reclaimed.
- Call reclaimContract with the fake order.
- 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.