Skip to content
Business logic Audit finding Intermediate

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.

0xadrii Follow with bin2chen, cergyk and 1 other

Originally disclosed on Sherlock

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:

Diff
-        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?

https://github.com/sherlock-audit/2024-02-tapioca/blob/main/Tapioca-bar/contracts/markets/singularity/SGLLeverage.sol#L135

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.

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

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.

More by 0xadrii

View all

30 more disclosed reports, best first.

More from Tapioca

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Business logic flaws

The lesson behind this report.

The application works as coded but not as intended: a negative price, a skipped payment step, a limit that can be crossed.