Open sherlock-admin3 opened 8 months ago
1 comment(s) were left on this issue during the judging contest.
WangAudit commented:
looks like design decision
@cryptotechmaker This seems like medium. I think the excess wouldn't be material enough to consider high given it is also users responsibility to input a reasonable amount to repay shares
The protocol team fixed this issue in PR/commit https://github.com/Tapioca-DAO/Tapioca-bar/pull/369.
hyh
high
Operation residual is lost for the user of BBLeverage's and SGLLeverage's
sellCollateral()
Summary
sellCollateral()
sells the specified amount of collateral, then repays the debt. The proceedings can cover the debt with some excess amount. Moreover, as the market swaps are involved and the actual proceedings amount isn't known in advance, while there is an over collaterization present in any healthy loan, the usual going concern situation is to sell slightly more when the goal is to pay off the debt.Currently all the remainder of collateral sale will be left with the contract. It can be immediately stolen via
skim
option.Vulnerability Detail
Core issue is that all sale proceeding are now stay with the contract, but remainder handling logic isn't present, so the leftover amounts, which can be arbitrary big, are lost for user and left on the contract balance.
These funds are unaccounted and can be skimmed by a back-running attacker.
Impact
There is the only prerequisite of having a material amount of extra funds from collateral sale, which can happen frequently, so the probability is medium/high. Affected funds can be arbitrary big and are lost for the user, can be stolen by any attacker immediately via back-running.
Likelihood: Medium/High + Impact: High = Severity: High.
Code Snippet
All collateral sale proceedings are left with the contract instead of going to
from
:https://github.com/sherlock-audit/2024-02-tapioca/blob/main/Tapioca-bar/contracts/markets/bigBang/BBLeverage.sol#L126-L150
LeverageExecutors return the whole proceedings to sender, i.e. SGL or BB contract:
https://github.com/sherlock-audit/2024-02-tapioca/blob/main/Tapioca-bar/contracts/markets/leverage/AssetTotsDaiLeverageExecutor.sol#L91-L92
Previously it remained with
from
(the code is from the old snapshot):https://github.com/Tapioca-DAO/Tapioca-bar/blob/f15aa5143f3435b6efbcc19419d1a3b1d1388bdb/contracts/markets/leverage/AssetToRethLeverageExecutor.sol#L108-L114
So in the current implementation assets are left with the contract and
memoryData.shareOut - memoryData.shareOwed
residual will be removed from and not reimbursed to thefrom
:https://github.com/sherlock-audit/2024-02-tapioca/blob/main/Tapioca-bar/contracts/markets/bigBang/BBLeverage.sol#L144-L161
These funds will be frozen with the contract as the system accounting isn't updated either to reflect injection of
memoryData.shareOut - memoryData.shareOwed
amount ofasset
.This way anyone can steal them via
skim
option:https://github.com/sherlock-audit/2024-02-tapioca/blob/main/Tapioca-bar/contracts/markets/bigBang/BBCommon.sol#L128-L138
https://github.com/sherlock-audit/2024-02-tapioca/blob/main/Tapioca-bar/contracts/markets/singularity/SGLCommon.sol#L165-L177
Tool used
Manual Review
Recommendation
Consider sending back (via
yieldBox.depositAsset
) thememoryData.shareOut - memoryData.shareOwed
amount to the operating user.