Description
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:
- [email protected] contained
const isValidEIP155V =
vInt === this.getChainId() * 2 + 35 || vInt === this.getChainId() * 2 + 36
- [email protected] contained
v: chainId ? recovery + (chainId * 2 + 35) : recovery + 27,
Solution
Since then those libraries were updated and they accept big integers:
- @ethereumjs/[email protected] used by MetaMask's develop branch currently
- [email protected] used by MetaMask's develop branch currently
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
- Go to https://metamask.github.io/api-playground/api-documentation/#wallet_addEthereumChain and click "TRY IT NOW" for the example request.
- Replace chainId with
0xfffffffffffed
(MAX_SAFE_CHAIN_ID+1). - 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