diff --git a/x/evm/keeper/txutils.go b/x/evm/keeper/txutils.go index 055b983..f8cad32 100644 --- a/x/evm/keeper/txutils.go +++ b/x/evm/keeper/txutils.go @@ -75,6 +75,11 @@ func (u *TxUtils) ConvertEthereumTxToCosmosTx(ctx context.Context, ethTx *corety // convert value unit from wei to cosmos fee unit value := types.FromEthersUnit(decimals, ethTx.Value()) + // check if the value is correctly converted without dropping any precision + if types.ToEthersUint(decimals, value).Cmp(ethTx.Value()) != 0 { + return nil, types.ErrInvalidValue.Wrap("failed to convert value to token unit without dropping precision") + } + // signer chainID := sdk.UnwrapSDKContext(ctx).ChainID() ethChainID := types.ConvertCosmosChainIDToEthereumChainID(chainID) diff --git a/x/evm/types/decimals.go b/x/evm/types/decimals.go index d1f6018..a88eac0 100644 --- a/x/evm/types/decimals.go +++ b/x/evm/types/decimals.go @@ -70,7 +70,6 @@ func FromEthersUnit(decimals uint8, val *big.Int) *big.Int { } decimalDiff := EtherDecimals - decimals - exp := new(big.Int).Exp(big.NewInt(10), big.NewInt(int64(decimalDiff)), nil) return new(big.Int).Div(val, exp) }