Skip to content

MAX_SAFE_CHAIN_ID no longer needed #13675

Open
@Solpatium

Description

@Solpatium

Describe the bug

Problem

MetaMask rejects chain ids bigger than 4503599627370476. It is a problem for networks that want to use a bigger chain id. In order to use them with MetaMask some mapping would have to be added.

Source of the problem

#10224 introduced MAX_SAFE_CHAIN_ID for reasons described in https://gist.github.com/rekmarks/a47bd5f2525936c4b8eee31a16345553. At that time libraries used by MetaMask used basic js number for computations, without the support of big integers.
Two libraries mentioned:

const isValidEIP155V =
  vInt === this.getChainId() * 2 + 35 || vInt === this.getChainId() * 2 + 36
v: chainId ? recovery + (chainId * 2 + 35) : recovery + 27,

Solution

Since then those libraries were updated and they accept big integers:

We could use changes in these libraries and limit chain id to fit in uint256, so it has to be lower than 2**256.

I can try to create a PR with required changes if MetaMask maintainers approve suggested solution.

Steps to reproduce

  1. Go to https://metamask.github.io/api-playground/api-documentation/#wallet_addEthereumChain and click "TRY IT NOW" for the example request.
  2. Replace chainId with 0xfffffffffffed (MAX_SAFE_CHAIN_ID+1).
  3. Send the request.

Error messages or log output

{
  "jsonrpc": "2.0",
  "id": 0,
  "error": {
    "code": 32329,
    "message": "Invalid chain ID \"0xfffffffffffed\": numerical value greater than max safe value. Received:\n0xfffffffffffed"
  }
}

Version

10.9.3

Build type

No response

Browser

Chrome

Operating system

MacOS

Hardware wallet

No response

Additional context

No response

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions