Skip to content

Crash due to ethers overflow/underflow issue when customizing decimals #688

Description

@NLSiLi

Bug description
As an experiment, I was trying to modify the decimals when adding a token to BlockWallet. The thought behind it is that it could be useful to adopt another number of decimals if a token has either a too large supply or too low, which would normally result in nearly unreadable values. For example, with Bitcoin, you could transfer to sats or 10^x sats as a single unit.

Modifying to fewer decimals is no problem. But I got a problem when trying to give an 18-decimal-token 20 decimals (somehow 19 still works). It crashes the wallet after login, and the issue persists.

Props for having a "reset account state" option on the error page! Resetting account state can still be a hustle, but is definitely better than having to factory reset the entire wallet.

How to reproduce

window.ethereum.request({
        method: 'wallet_watchAsset',
        params: {
          type: 'ERC20',
          options: {
            address: tokenData.address,
            symbol: tokenData.symbol,
            decimals: Number(tokenData.decimals),
            image: tokenData.logoURI,
          },
        },
      });

I have made a simple front end so I can edit tokenData easily, however instead you could also fill in the data for a given token directly.

The trick here is that I insert a higher number of decimals than the ERC20 token actually has.

Expected behaviour
Let's take a value 12345.678900000000000000. This has 18 decimals.
Now I want to make the units bigger and move the dot to the left. This means I have to configure more decimals.
For example, 20 decimals would be: 123.45678900000000000000.
In this case, 1 unit would be 100 coins in reality.

Screenshots
blockwallet-error

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions