You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository has been archived by the owner on Mar 3, 2024. It is now read-only.
sherlock-admin opened this issue
Aug 30, 2023
· 0 comments
Labels
DuplicateA valid issue that is a duplicate of an issue with `Has Duplicates` labelHighA valid High severity issueRewardA payout will be made for this issue
in LMPVault._withdraw()
Erroneous overwriting of the old info.idleIncrease may result in a lower number
Vulnerability Detail
in LMPVault._withdraw()
The code to calculate info.idleIncrease is as follows.
function _withdraw(
uint256assets,
uint256shares,
addressreceiver,
addressowner
) internalvirtualreturns (uint256) {
uint256 idle = totalIdle;
WithdrawInfo memory info =WithdrawInfo({
currentIdle: idle,
assetsFromIdle: assets >= idle ? idle : assets,
totalAssetsToPull: assets - (assets >= idle ? idle : assets),
totalAssetsPulled: 0,
idleIncrease: 0,
debtDecrease: 0
});
// If not enough funds in idle, then pull what we need from destinationsif (info.totalAssetsToPull >0) {
uint256 totalVaultShares =totalSupply();
// Using pre-set withdrawalQueue for withdrawal order to help minimize user gasuint256 withdrawalQueueLength = withdrawalQueue.length;
for (uint256 i =0; i < withdrawalQueueLength; ++i) {
IDestinationVault destVault =IDestinationVault(withdrawalQueue[i]);
(uint256sharesToBurn, uint256totalDebtBurn) =_calcUserWithdrawSharesToBurn(
destVault,
shares,
info.totalAssetsToPull - Math.max(info.debtDecrease, info.totalAssetsPulled),
totalVaultShares
);
if (sharesToBurn ==0) {
continue;
}
uint256 assetPreBal = _baseAsset.balanceOf(address(this));
uint256 assetPulled = destVault.withdrawBaseAsset(sharesToBurn, address(this));
// Destination Vault rewards will be transferred to us as part of burning out shares// Back into what that amount is and make sure it gets into idle
@> info.idleIncrease += _baseAsset.balanceOf(address(this)) - assetPreBal - assetPulled;
info.totalAssetsPulled += assetPulled;
info.debtDecrease += totalDebtBurn;
// It's possible we'll get back more assets than we anticipate from a swap// so if we do, throw it in idle and stop processing. You don't get more than we've calculatedif (info.totalAssetsPulled > info.totalAssetsToPull) {
@> info.idleIncrease = info.totalAssetsPulled - info.totalAssetsToPull;
info.totalAssetsPulled = info.totalAssetsToPull;
break;
}
// No need to keep going if we have the amount we're looking for// Any overage is accounted for above. Anything lower and we need to keep going// slither-disable-next-line incorrect-equalityif (info.totalAssetsPulled == info.totalAssetsToPull) {
break;
}
}
}
.....
if info.totalAssetsPulled > info.totalAssetsToPull will execute the assignment info.idleIncrease = info.totalAssetsPulled - info.totalAssetsToPull;
But info.idleIncrease already has accumulated values before, directly overwriting the old ones will lose
You should use +=
function _withdraw(
uint256assets,
uint256shares,
addressreceiver,
addressowner
) internalvirtualreturns (uint256) {
...
if (info.totalAssetsPulled > info.totalAssetsToPull) {
- info.idleIncrease = info.totalAssetsPulled - info.totalAssetsToPull;
+ info.idleIncrease += info.totalAssetsPulled - info.totalAssetsToPull;
info.totalAssetsPulled = info.totalAssetsToPull;
break;
}
// No need to keep going if we have the amount we're looking for// Any overage is accounted for above. Anything lower and we need to keep going// slither-disable-next-line incorrect-equalityif (info.totalAssetsPulled == info.totalAssetsToPull) {
break;
}
}
}
sherlock-admin2
changed the title
Fluffy Shamrock Turkey - _withdraw() idleIncrease might be less
bin2chen - _withdraw() idleIncrease might be less
Oct 3, 2023
Sign up for freeto subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Labels
DuplicateA valid issue that is a duplicate of an issue with `Has Duplicates` labelHighA valid High severity issueRewardA payout will be made for this issue
bin2chen
medium
_withdraw() idleIncrease might be less
Summary
in
LMPVault._withdraw()
Erroneous overwriting of the old
info.idleIncrease
may result in a lower numberVulnerability Detail
in
LMPVault._withdraw()
The code to calculate
info.idleIncrease
is as follows.if
info.totalAssetsPulled > info.totalAssetsToPull
will execute the assignmentinfo.idleIncrease = info.totalAssetsPulled - info.totalAssetsToPull;
But
info.idleIncrease
already has accumulated values before, directly overwriting the old ones will loseYou should use
+=
Impact
_withdraw() idleIncrease might be less
Code Snippet
https://github.com/sherlock-audit/2023-06-tokemak/blob/main/v2-core-audit-2023-07-14/src/vault/LMPVault.sol#L494
Tool used
Manual Review
Recommendation
Duplicate of #5
The text was updated successfully, but these errors were encountered: