This repository has been archived by the owner on Mar 3, 2024. It is now read-only.
nobody2018 - When DestinationVault is at loss, LMPVault._withdraw may revert in some cases due to underflow #716
Labels
Duplicate
A valid issue that is a duplicate of an issue with `Has Duplicates` label
Escalation Resolved
This issue's escalations have been approved/rejected
Medium
A valid Medium severity issue
Reward
A payout will be made for this issue
nobody2018
medium
When DestinationVault is at loss, LMPVault._withdraw may revert in some cases due to underflow
Summary
[_calcUserWithdrawSharesToBurn](https://github.com/sherlock-audit/2023-06-tokemak/blob/main/v2-core-audit-2023-07-14/src/vault/libs/LMPDebt.sol#L231) is used to figure out how many shares we can burn from the destination as well as what our totalDebt deduction should be (totalDebt being a cached value). If its at a loss, they can only burn an amount proportional to their ownership of LMPVault.
totalDebtBurn
is the return value of this function, which is calculated based on the cached values. Since DestinationVault is at a loss,totalDebtBurn
represents past debts, which may be higher thantotalAssetsToPull
. This will cause the subtraction underflow in [L475](https://github.com/sherlock-audit/2023-06-tokemak/blob/main/v2-core-audit-2023-07-14/src/vault/LMPVault.sol#L475) and revert. Users cannot withdraw funds.Vulnerability Detail
This problem can occur when
totalIdle
has funds, but not enough to cover the funds the user wants to withdraw._calcUserWithdrawSharesToBurn
returns two values:sharesToBurn
andtotalDebtBurn
.totalDebtBurn
represents the past debt, andsharesToBurn
represents the share to be withdrawn in DestinationVault. When DestinationVault is at a loss, theassetPulled
bydestVault.withdrawBaseAsset(sharesToBurn, address(this))
may be less thantotalDebtBurn
. IftotalDebtBurn
is greater thaninfo.totalAssetsToPull
, then subtraction underflow may occur at L475. In other words, this condition is met:assetPulled < info.totalAssetsToPull < totalDebtBurn
. Because when i=1, theinfo.debtDecrease
andinfo.totalAssetsPulled
of L475 are equivalent tototalDebtBurn
andassetPulled
obtained when i=0 (L488-489).Impact
When DestinationVault is at a loss, users may not be able to withdraw funds due to underflow.
Code Snippet
https://github.com/sherlock-audit/2023-06-tokemak/blob/main/v2-core-audit-2023-07-14/src/vault/LMPVault.sol#L475
Tool used
Manual Review
Recommendation
Duplicate of #519
The text was updated successfully, but these errors were encountered: