It doesn't handle fee-on-transfer/deflationary tokens
The protocol assumes that the full amount of a transferred token arrives at the contract, so with fee-on-transfer or deflationary tokens it receives less than it records. Users then cannot call settleContract or reclaimContract because the contract lacks enough tokens to pay out.
Source: https://github.com/sherlock-audit/2022-11-bullvbear-judging/issues/130
Found by
cccz, Ruhum, pashov, tives, Tomo, hansfriese, GimelSec, rvierdiiev, Zarf, 0v3rf10w, dipp
Summary
The protocol doesn't handle fee-on-transfer/deflationary tokens, users will be unable to call settleContract and reclaimContract due to not enough assets in the contract.
Though the protocol uses allowedAsset to set the asset as supported as payment, we can't guarantee that the allowed non-deflationary token will always not become a deflationary token, especially upgradeable tokens (for example, USDC).
Vulnerability Detail
Assume that A token is a deflationary token, and it will take 50% fee when transferring tokens. And the protocol only set 4% fee.
If a user is bear and call mathOrder with order.premium = 100, the takerPrice will be 100 + 100*4% = 104 but the protocol will only get 104 * 50% = 52 tokens in L354.
Same problem in order.collateral, the user will be unable to call settleContract because the contract doesn't have enough A tokens.
Impact
The protocol will be unable to pay enough tokens to users when users want to call settleContract or reclaimContract.
Code Snippet
https://github.com/sherlock-audit/2022-11-bullvbear/blob/main/bvb-protocol/src/BvbProtocol.sol#L354 https://github.com/sherlock-audit/2022-11-bullvbear/blob/main/bvb-protocol/src/BvbProtocol.sol#L358
Tool used
Manual Review
Recommendation
Use balanceAfter - balanceBefore:
uint256 balanceBefore = deflationaryToken.balanceOf(address(this));
deflationaryToken.safeTransferFrom(msg.sender, address(this), takerPrice);
uint256 balanceAfter = deflationaryToken.balanceOf(address(this));
premium = (balanceAfter - balanceBefore) - bearFees;
Discussion
datschill
PR fixing this issue : https://github.com/BullvBear/bvb-solidity/pull/8
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 credits the requested transfer amount rather than measuring the actual change in its token balance, so fee-on-transfer tokens leave it short.
Impact
The protocol will be unable to pay enough tokens to users when users want to call `settleContract` or `reclaimContract`.
What the attacker needed
A supported token that takes a transfer fee; token becomes deflationary after listing
The fix
The fix was confirmed after measuring the contract's balance before and after the transfer and using the difference.
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.
Some tokens take a cut every time they are moved, so the receiver gets less than the sender sent. This protocol records the full amount as if nothing was taken, so later it tries to pay out more tokens than it actually holds. That makes the payout functions fail.
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.