This repository has been archived by the owner on May 26, 2023. It is now read-only.
obront - LP tokens are not sent back to withdrawing user #151
Labels
Has Duplicates
A valid issue with 1+ other issues describing the same vulnerability
High
A valid High severity issue
Reward
A payout will be made for this issue
Sponsor Confirmed
The sponsor acknowledged this issue is valid
Will Fix
The sponsor confirmed this issue will be fixed
obront
high
LP tokens are not sent back to withdrawing user
Summary
When users withdraw their assets from
IchiVaultSpell.sol
, the function unwinds their position and sends them back their assets, but it never sends them back the amount they requested to withdraw, leaving the tokens stuck in the Spell contract.Vulnerability Detail
When a user withdraws from
IchiVaultSpell.sol
, they either callclosePosition()
orclosePositionFarm()
, both of which make an internal call towithdrawInternal()
.The following arguments are passed to the function:
strategies
array, which specifies the Ichi vault in questionIn order to accomplish these goals, the contract does the following...
doTakeCollateral(strategies[strategyId].vault, lpTakeAmt);
Converts the non-borrowed token that was withdrawn in the borrowed token (not copying the code in, as it's not relevant to this issue).
Withdraw the underlying token from Compound.
doWithdraw(collToken, amountShareWithdraw);
doRepay(borrowToken, amountRepay);
_validateMaxLTV(strategyId);
Crucially, the step of sending the remaining LP tokens to the user is skipped, even though the function specifically does the calculations to ensure that
amountLpWithdraw
is held back from being taken out of the vault.Impact
Users who close their positions and choose to keep LP tokens (rather than unwinding the position for the constituent tokens) will have their LP tokens stuck permanently in the IchiVaultSpell contract.
Code Snippet
https://github.com/sherlock-audit/2023-02-blueberry/blob/main/contracts/spell/IchiVaultSpell.sol#L276-L330
Tool used
Manual Review
Recommendation
Add an additional line to the
withdrawInternal()
function to refund all LP tokens as well:doRefund(borrowToken); doRefund(collToken); + doRefund(address(vault));
The text was updated successfully, but these errors were encountered: