BBLeverage::sellCollateral is unusable due to wrong asset deposit attempt in YieldBox
The sellCollateral function in BBLeverage attempts to deposit the wrong asset identifier into YieldBox after swapping collateral for the underlying asset, causing the transaction to always revert. This makes the function unusable, preventing users from leveraging up on a borrow position.
Source: https://github.com/sherlock-audit/2024-02-tapioca-judging/issues/42
Found by
0xadrii, bin2chen, cergyk, duc
Summary
sellCollateral enable to leverage up on a borrow position in a BigBang market. However the endpoint is unusable as is due to collateralId used to deposit in YieldBox, instead of assetId
Vulnerability Detail
We can see here that after withdrawing collateral, and swapping it for asset, BBLeverage::sellCollateral attempts to deposit collateralId into YieldBox:
https://github.com/sherlock-audit/2024-02-tapioca/blob/main/Tapioca-bar/contracts/markets/bigBang/BBLeverage.sol#L149
Which will always revert, since at that point we always have asset and not collateral.
This function is thus unusable
Impact
The function BBLeverage::sellCollateral will always revert and is unusable
Code Snippet
Tool used
Manual Review
Recommendation
Change the deposit to use assetId, as is correctly done in SGLLeverage:
- yieldBox.depositAsset(collateralId, address(this), address(this), 0, memoryData.shareOut); // TODO Check for rounding attack?
+ yieldBox.depositAsset(assetId, address(this), address(this), 0, memoryData.shareOut); // TODO Check for rounding attack?
Discussion
cryptotechmaker
Same for SGLLeverage.sellCollateral
cryptotechmaker
Fixed in https://github.com/Tapioca-DAO/Tapioca-bar/pull/352
sherlock-admin4
The protocol team fixed this issue in PR/commit https://github.com/Tapioca-DAO/Tapioca-bar/pull/352.
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 code uses collateralId instead of assetId when depositing into YieldBox after swapping collateral for the underlying asset.
Impact
The function sellCollateral will always revert and is unusable.
What the attacker needed
None
The fix
The deposit should use assetId instead of collateralId, as done in SGLLeverage; the protocol team fixed this issue.
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.
In a smart contract, a function that is supposed to sell collateral and deposit the proceeds uses the wrong identifier for the asset, so it always fails. This means users cannot use that feature at all.
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.