Failure to refund ICHI v2 farming reward tokens upon increasing farming position
Summary
ICHI v2 farming reward tokens are not refunded to the user when subsequently calling the IchiVaultSpell.openPositionFarm function to increase the farming position. Any other user with a farming position can steal those left behind ICHI v2 reward tokens.
Vulnerability Detail
A user can repeatedly call the IchiVaultSpell.openPositionFarm function for a given position to increase the farming position. Any existing WIchiFarm token collateral previously deposited as part of the position is taken out from the bank and burned via the WIchiFarm.burn function in line 241.
Burning the wrapped WIchiFarm ERC1155 tokens withdraws the underlying LP tokens from the Ichi farm and harvests ICHI v1 and v2 reward tokens (see WIchiFarm.sol#L128-L129). Those ICHI v2 tokens, along with the LP tokens, are then transferred to the spell contract.
The previously withdrawn LP tokens and the newly added LP tokens are then wrapped into WIchiFarm tokens to farm rewards, and deposited into the bank as collateral.
However, the ICHI v2 reward tokens harvested earlier are not refunded to the user but remain in the spell contract. Consequently, any user can steal these ICHI v2 reward tokens by closing their own farming position.
Impact
This vulnerability results in the loss of eligible ICHI v2 farming reward tokens for users who increase their farming position, which can then be stolen by others.
The current ICHI v2 token balance of the IchiVaultSpell contract is always refunded to the user when closing a farming position in line 404. Any left behind ICHI v2 tokens from other users (which are accumulated in this contract due to the aforementioned issue) can be stolen.
berndartmueller
high
Failure to refund
ICHI
v2 farming reward tokens upon increasing farming positionSummary
ICHI
v2 farming reward tokens are not refunded to the user when subsequently calling theIchiVaultSpell.openPositionFarm
function to increase the farming position. Any other user with a farming position can steal those left behindICHI
v2 reward tokens.Vulnerability Detail
A user can repeatedly call the
IchiVaultSpell.openPositionFarm
function for a given position to increase the farming position. Any existingWIchiFarm
token collateral previously deposited as part of the position is taken out from the bank and burned via theWIchiFarm.burn
function in line 241.Burning the wrapped
WIchiFarm
ERC1155 tokens withdraws the underlying LP tokens from the Ichi farm and harvestsICHI
v1 and v2 reward tokens (see WIchiFarm.sol#L128-L129). ThoseICHI
v2 tokens, along with the LP tokens, are then transferred to the spell contract.The previously withdrawn LP tokens and the newly added LP tokens are then wrapped into
WIchiFarm
tokens to farm rewards, and deposited into the bank as collateral.However, the
ICHI
v2 reward tokens harvested earlier are not refunded to the user but remain in the spell contract. Consequently, any user can steal these ICHI v2 reward tokens by closing their own farming position.Impact
This vulnerability results in the loss of eligible
ICHI
v2 farming reward tokens for users who increase their farming position, which can then be stolen by others.Code Snippet
spell/IchiVaultSpell.sol#L241
IchiVaultSpell.closePositionFarm
The current
ICHI
v2 token balance of theIchiVaultSpell
contract is always refunded to the user when closing a farming position in line 404. Any left behindICHI
v2 tokens from other users (which are accumulated in this contract due to the aforementioned issue) can be stolen.Tool used
Manual Review
Recommendation
Consider refunding the ICHI v2 token (
ICHI
) rewards to the user at the end of theIchiVaultSpell.openPositionFarm
function:Additionally, as stated in the docs, deduct performance fees from the
ICHI
v2 reward tokens as necessary.Duplicate of #158