Closed c4-bot-7 closed 3 months ago
cryptotechmaker (sponsor) confirmed
cryptotechmaker marked the issue as disagree with severity
dmvt marked the issue as primary issue
dmvt marked the issue as duplicate of #91
dmvt marked the issue as satisfactory
Lines of code
https://github.com/Tapioca-DAO/tapioca-periph/blob/032396f701be935b04a7e5cf3cb40a0136259dbc/contracts/Magnetar/modules/MagnetarOptionModule.sol#L151-L158
Vulnerability details
Description
exitPositionAndRemoveCollateral
function attempts to remove asset of user from Singularity market.It calls the removeAsset function of Singularity with the share variable, which represents the YieldBox shares of the repaid asset amount. However, the
removeAsset
function of Singularity uses a fraction of the lended part to be the repaid variable (see code snippet from gitmodule tapioca-bar).Due to removing with a parameter being the share amount (YieldBox shares of asset tokens), the contract will remove more assets than needed from the user in
exitPositionAndRemoveCollateral
. This results in the user losing funds when using this functionality becauseremoveAssetTo
can be this contract if the user attempts to withdraw after removal:For example, after depositing and accruing interest in the Singularity contract, Bob now has 100 asset fractions (base) and 1000 YieldBox shares of the asset (elastic). Bob calls
exitPositionAndRemoveCollateral
withwithdraw
flag set to true, expecting to remove his 100 asset shares and withdraw, but this function will pass 100 to theremoveAsset
function. Consequently, 100 asset fractions of Bob will be removed, which is equivalent to 1000 asset shares (more than the needed 900 shares). These shares are transferred to the Magnetar address to withdraw from YieldBox, so the redundant shares (900 shares) will be stuck in the contract.Impact
Users will lose their funds when using
exitPositionAndRemoveCollateral
function.Tools Used
Manual review
Recommended Mitigation Steps
Before calling
Singularity.removeAssets()
,exitPositionAndRemoveCollateral
function should convert from asset shares amount (YieldBox shares of asset tokens) to the fraction of the lent partAssessed type
Other