Too few ICHI v2 farming reward tokens transferred to the user due to incorrect decimal precision
Summary
The burn function in the WIchiFarm contract transfers too few ICHIv2 farming reward tokens to the caller due to using 9 decimals instead of 18 decimals for the ICHIv2 token.
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.
To calculate the user's share of eligible ICHIv2 reward tokens, the reward per share accumulator stIchiPerShare at the time of minting the WIchiFarm token and the current enIchiPerShare accumulator is used.
However, those accumulator values are in 9 decimals precision (please see the ichiFarmV2.harvest function for proof that pool.accIchiPerShare uses 9 decimals, otherwise the ICHI token transfer would fail due to inflated _pendingIchi). Given that amount is in 18 decimals, the calculation of stIchi and enIchi in lines 143 and 144 will result in a value with 9 decimals precision.
As previously mentioned, the ICHIv2 token uses 18 decimals. Therefore, too few ICHIv2 tokens are transferred.
Impact
Users will receive substantially fewer ICHI v2 farming reward tokens than expected.
berndartmueller
high
Too few
ICHI
v2 farming reward tokens transferred to the user due to incorrect decimal precisionSummary
The
burn
function in theWIchiFarm
contract transfers too fewICHI
v2 farming reward tokens to the caller due to using 9 decimals instead of 18 decimals for theICHI
v2 token.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.To calculate the user's share of eligible
ICHI
v2 reward tokens, the reward per share accumulatorstIchiPerShare
at the time of minting theWIchiFarm
token and the currentenIchiPerShare
accumulator is used.However, those accumulator values are in 9 decimals precision (please see the
ichiFarmV2.harvest
function for proof thatpool.accIchiPerShare
uses 9 decimals, otherwise theICHI
token transfer would fail due to inflated_pendingIchi
). Given thatamount
is in 18 decimals, the calculation ofstIchi
andenIchi
in lines 143 and 144 will result in a value with 9 decimals precision.As previously mentioned, the
ICHI
v2 token uses 18 decimals. Therefore, too fewICHI
v2 tokens are transferred.Impact
Users will receive substantially fewer
ICHI
v2 farming reward tokens than expected.Code Snippet
wrapper/WIchiFarm.sol#L143-L144
Tool used
Manual Review
Recommendation
Consider changing the denominator in lines 143 and 144 from
1e18
to1e9
to use the required18
decimals for theICHI
v2 token.