Failure to withdraw Ichi vault LP tokens to the user
Summary
A user is able to specify an amount amountLpWithdraw to withdraw ICHI vault LP tokens from their owned position directly to the user. However, due to a bug in the calculation of the amount of LP tokens to withdraw, the requested tokens are not transferred to the user and instead remain stuck in the spell contract.
Vulnerability Detail
The IchiVaultSpell.closePosition function first withdraws lpTakeAmt collateral (ICHI vault LP tokens) from the bank that was previously deposited when opening the position.
The closePosition function allows a user to specify an amount amountLpWithdraw of ICHI vault LP tokens to withdraw and to transfer back to the caller (user). This parameter is passed on to the IchiVaultSpell.withdrawInternal function.
In the IchiVaultSpell.withdrawInternal function, the amount of ICHI vault LP tokens to withdraw is calculated in step 2 by subtracting the specified amountLpWithdraw parameter from the current ICHI vault LP token balance (collateral that have been withdrawn previously from the bank - see IchiVaultSpell.closePosition#L355).
If a non-zero value is provided as amountLpWithdraw, the amount of ICHI vault LP tokens to withdraw from the ICHI vault will be correspondingly lower.
The remaining ICHI vault LP tokens, which are not used to withdraw from the ICHI vault, remain in the spell contract and are not refunded to the caller.
It is worth noting that any other user or MEV bot can create a new ICHI vault spell position and withdraw those leftover ICHI vault LP tokens by closing the position.
In contrast, the Alpha Homora SushiswapSpellV1 implementation refunds (transfers) any LP tokens intended to be withdrawn by the user (amtLPWithdraw) in line 338.
Impact
ICHI vault LP tokens intended to be withdrawn and transferred to the user (caller) are not transferred to the user and remain stuck in the spell contract. The user lost those LP tokens.
berndartmueller
high
Failure to withdraw Ichi vault LP tokens to the user
Summary
A user is able to specify an amount
amountLpWithdraw
to withdraw ICHI vault LP tokens from their owned position directly to the user. However, due to a bug in the calculation of the amount of LP tokens to withdraw, the requested tokens are not transferred to the user and instead remain stuck in the spell contract.Vulnerability Detail
The
IchiVaultSpell.closePosition
function first withdrawslpTakeAmt
collateral (ICHI vault LP tokens) from the bank that was previously deposited when opening the position.The
closePosition
function allows a user to specify an amountamountLpWithdraw
of ICHI vault LP tokens to withdraw and to transfer back to the caller (user). This parameter is passed on to theIchiVaultSpell.withdrawInternal
function.In the
IchiVaultSpell.withdrawInternal
function, the amount of ICHI vault LP tokens to withdraw is calculated in step 2 by subtracting the specifiedamountLpWithdraw
parameter from the current ICHI vault LP token balance (collateral that have been withdrawn previously from the bank - seeIchiVaultSpell.closePosition#L355
).If a non-zero value is provided as
amountLpWithdraw
, the amount of ICHI vault LP tokens to withdraw from the ICHI vault will be correspondingly lower. The remaining ICHI vault LP tokens, which are not used to withdraw from the ICHI vault, remain in the spell contract and are not refunded to the caller.It is worth noting that any other user or MEV bot can create a new ICHI vault spell position and withdraw those leftover ICHI vault LP tokens by closing the position.
In contrast, the Alpha Homora
SushiswapSpellV1
implementation refunds (transfers) any LP tokens intended to be withdrawn by the user (amtLPWithdraw
) in line 338.Impact
ICHI vault LP tokens intended to be withdrawn and transferred to the user (caller) are not transferred to the user and remain stuck in the spell contract. The user lost those LP tokens.
Code Snippet
spell/IchiVaultSpell.closePosition
spell/IchiVaultSpell.sol#L294-L295
Tool used
Manual Review
Recommendation
Consider refunding the remaining Ichi vault LP tokens using
doRefund(address(vault));
at the end of theIchiVaultSpell.withdrawInternal
function.Duplicate of #151