Bull can `transferPosition()` to `address(0)` and the original order can be matched again
The contract used the bull's address being zero as the only sign that an order had already been matched, but a bull could transfer its position to the zero address, resetting that check. An attacker could then match the same order repeatedly and pull the premium and fees from victims' wallets each time.
Source: https://github.com/sherlock-audit/2022-11-bullvbear-judging/issues/114
Found by
bin2chen, aviggiano, carrot, KingNFT, imare, hansfriese, WATCHPUG, GimelSec, curiousapple, rvierdiiev, 0x52, neumo, Bahurum, dipp
Summary
Using bulls[uint(orderHash)] == address(0) to check whether the order is matched is insufficient, the bull can transferPosition to address(0) and the order can be matched again.
Vulnerability Detail
An order must not be matched more than once.
There is a check presented in the current implementation to prevent that: L760 require(bulls[uint(orderHash)] == address(0), "ORDER_ALREADY_MATCHED");.
However, this check can be easily bypassed by the bull, as they can transferPosition() to address(0) anytime.
Then the original order can be matched again.
Impact
Attacker can match the orders by bear makers multiple times, pulling order.premium + bearFees from the victims' wallet as many times as they want.
Code Snippet
Tool used
Manual Review
Recommendation
Consider using matchedOrders[contractId] to check if the order has been matched or not. Also, consider disallowing transferPosition() to address(0).
Discussion
datschill
PR fixing this issue : https://github.com/BullvBear/bvb-solidity/pull/1
datschill
PR fixing the transfer to 0x0 : https://github.com/BullvBear/bvb-solidity/pull/3
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 contract used a mutable position owner address as the matched-order flag instead of a dedicated boolean, and it allowed transferring the position to the zero address.
Impact
An attacker could match the same order multiple times, pulling the premium plus bear fees from victims' wallets on each match.
What the attacker needed
Attacker controls a bull position; order not yet matched
The fix
The project fixed it by tracking matched orders with a dedicated mapping and by disallowing transfers to the zero address, and the fix was confirmed.
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 is a program on a blockchain that holds and moves funds. This one tracked whether an order was already filled by checking whether a stored address was empty (the zero address). The owner of that position could deliberately send it to the zero address, making the contract think the order was never filled, so it could be filled again and again.
What is Business logic?
The application works as coded but not as intended: a negative price, a skipped payment step, a limit that can be crossed.