Burning WIchiFarm wrapped ICHI vault LP tokens can possibly revert due to insufficient balance of ICHI v2 tokens
Note: This issue is only applicable if the stIchi and enIchi values have their precision increased to 18 decimals. In the current implementation, those values are incorrectly in 9 decimals! The issue has been reported as a separate issue. Nevertheless, I consider this a valid issue, and due to the dependence on the other issue, I'm reporting it as Medium severity.
Summary
Calculating the eligible user rewards with a higher precision of 18 decimals can cause the token transfer to revert as fewer farming rewards have been received before (due to the ICHI v1 token using 9 decimals and the ICHI v2 token using 18 decimals).
Vulnerability Detail
Closing an ICHI vault spell farming position burns the wrapped ICHI vault LP tokens (WIchiFarm ERC-1155 tokens). Farming rewards are harvested from the ICHI farm (see contract on Etherscan) and received as ICHIv1 tokens.
Those received ICHIv1 tokens are then converted to v2 tokens in line 134. The conversion simply multiplies the ICHIv1 token amount by 1e9 (9 decimals) to scale the value to 18 decimals.
The user's share of eligible ICHI v2 reward tokens is calculated as the delta of enIchi and stIchi. However, those two values are in 18 decimal precision (once corrected, as noted in a separate issue). As the harvested ICHIv1 tokens are scaled to 18 decimals, there is a slight precision loss and truncation.
For example, consider the very simplified foundry example:
rewardV1: 10000000
rewardV1 converted to V2: 10000000000000000
rewardV2: 10000000100000000
Error: a == b not satisfied [uint]
Expected: 10000000000000000
Actual: 10000000100000000
The amount uses a precision of 18 decimals and therefore the rewardV2 value is more precise than the rewardV1 value.
The ICHI v2 token transfer in line 147 can therefore potentially revert due to insufficient balance, caused by the precision and truncation issue.
Impact
Unwrapping WIchiFarm tokens will revert due to transferring more ICHI v2 tokens than available. The last user to burn those tokens (while closing a Ichi vault spell position) will be unable to do so and will be unable to close the position. The isolated collateral will be locked.
Consider checking the current balance of ICHI v2 tokens before trying to transfer more than available and capping the transfer amount to the current balance.
berndartmueller
medium
Burning
WIchiFarm
wrapped ICHI vault LP tokens can possibly revert due to insufficient balance of ICHI v2 tokensSummary
Calculating the eligible user rewards with a higher precision of 18 decimals can cause the token transfer to revert as fewer farming rewards have been received before (due to the
ICHI
v1 token using 9 decimals and theICHI
v2 token using 18 decimals).Vulnerability Detail
Closing an ICHI vault spell farming position burns the wrapped ICHI vault LP tokens (
WIchiFarm
ERC-1155 tokens). Farming rewards are harvested from the ICHI farm (see contract on Etherscan) and received asICHI
v1 tokens.The
ICHI
v1 ERC-20 token uses 9 decimals (see token on Etherscan), whereas theICHI
v2 ERC-20 token uses 18 decimals (see token on Etherscan).Those received
ICHI
v1 tokens are then converted to v2 tokens in line 134. The conversion simply multiplies theICHI
v1 token amount by1e9
(9 decimals) to scale the value to 18 decimals.The user's share of eligible
ICHI
v2 reward tokens is calculated as the delta ofenIchi
andstIchi
. However, those two values are in 18 decimal precision (once corrected, as noted in a separate issue). As the harvestedICHI
v1 tokens are scaled to 18 decimals, there is a slight precision loss and truncation.For example, consider the very simplified foundry example:
The result:
The
amount
uses a precision of 18 decimals and therefore therewardV2
value is more precise than therewardV1
value.The
ICHI
v2 token transfer in line 147 can therefore potentially revert due to insufficient balance, caused by the precision and truncation issue.Impact
Unwrapping
WIchiFarm
tokens will revert due to transferring more ICHI v2 tokens than available. The last user to burn those tokens (while closing a Ichi vault spell position) will be unable to do so and will be unable to close the position. The isolated collateral will be locked.Code Snippet
wrapper/WIchiFarm.sol#L143-L144
Tool used
Manual Review
Recommendation
Consider checking the current balance of
ICHI
v2 tokens before trying to transfer more than available and capping the transfer amount to the current balance.Duplicate of #319