Destination Vault rewards are not added to idleIncrease when info.totalAssetsPulled > info.totalAssetsToPull
In the LMPVault contract, when a withdrawal pulls more assets than needed, the code overwrites the idleIncrease value instead of adding to it, so Destination Vault rewards are not recorded. These unrecorded rewards become frozen in the contract because the recover function cannot extract the base asset.
0x73696d616f Follow with 0xbepresent, Aymen0909 and 17 others
Originally disclosed on Sherlock
Source: https://github.com/sherlock-audit/2023-06-tokemak-judging/issues/5
Found by
0x73696d616f, 0xbepresent, Aymen0909, Ch_301, Kalyan-Singh, TangYuanShen, berndartmueller, bin2chen, bitsurfer, carrotsmuggler, duc, lemonmon, nobody2018, p0wd3r, pengun, rvierdiiev, saidam017, talfao, warRoom, xiaoming90
Destination Vault rewards are not added to idleIncrease when info.totalAssetsPulled > info.totalAssetsToPull in _withdraw of LMPVault.
This result in rewards not being recorded by LMPVault and ultimately frozen in the contract.
Vulnerability Detail
In the _withdraw function, Destination Vault rewards will be first recorded in info.IdleIncrease by info.idleIncrease += _baseAsset.balanceOf(address(this)) - assetPreBal - assetPulled;.
But when info.totalAssetsPulled > info.totalAssetsToPull, info.idleIncrease is directly assigned as info.totalAssetsPulled - info.totalAssetsToPull, and info.totalAssetsPulled is assetPulled without considering Destination Vault rewards.
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 calculated
if (info.totalAssetsPulled > info.totalAssetsToPull) {
info.idleIncrease = info.totalAssetsPulled - info.totalAssetsToPull;
info.totalAssetsPulled = info.totalAssetsToPull;
break;
}
For example,
// preBal == 100 pulled == 10 reward == 5 toPull == 6
// idleIncrease = 115 - 100 - 10 == 5
// totalPulled(0) += assetPulled == 10 > toPull
// idleIncrease = totalPulled - toPull == 4 < reward
The final info.idleIncrease does not record the reward, and these assets are not ultimately recorded by the Vault.
Impact
The final info.idleIncrease does not record the reward, and these assets are not ultimately recorded by the Vault.
Meanwhile, due to the recover function's inability to extract the baseAsset, this will result in no operations being able to handle these Destination Vault rewards, ultimately causing these assets to be frozen within the contract.
Code Snippet
Tool used
Manual Review
Recommendation
info.idleIncrease = info.totalAssetsPulled - info.totalAssetsToPull; -> info.idleIncrease += info.totalAssetsPulled - info.totalAssetsToPull;
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
Likely the code uses an assignment (=) instead of an addition assignment (+=) when updating idleIncrease in the branch where totalAssetsPulled exceeds totalAssetsToPull, overwriting previously accumulated rewards.
Impact
Destination Vault rewards are not recorded by the vault and become frozen in the contract, as the recover function cannot extract the base asset.
What the attacker needed
Withdrawal triggers totalAssetsPulled > totalAssetsToPull
The fix
The code should use += instead of = when updating idleIncrease in that branch, so rewards are added rather than overwritten.
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.
When you withdraw from a vault, sometimes you get extra rewards. The code is supposed to add these rewards to a running total called idleIncrease. But in a specific case, it replaces the total instead of adding to it, so the rewards are lost from the accounting and get stuck in the contract.
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.