主页EIPs周刊
EIPsEIP-2294
EIP-2294

Explicit bound to Chain ID size

Adds a maximum value to the Chain ID parameter to avoid potential encoding issues that may occur when using large values of the parameter.
ReviewInformational
创建时间: 2019-09-19
关联 EIP: EIP-155
Zainan Victor Zhou (@xinbenlv), Alex Beregszaszi (@axic), Bryant Eisenbach (@fubuloubu)
社区讨论原文链接编辑
1 分钟了解
欢迎补充好内容
去提交
相关视频
欢迎补充好内容
去提交
正文

Abstract

This EIP informationally defines the "Safe Range" and "Max Range" of ChainId based on a few known restrictions such as EIP-155 and major wallet and JsonPRC representation of ChainId.

Motivation

  1. We want chainId to be safe across the different components of the ecosystem such as smart contract, wallet, dApp and JsonPRC etc.
  2. We want to enable Cross-Chain function call
  3. We want to ensure EIP-712 domains have a clear definition of how to pack ChainID.
  4. Enable possbile expansion of chains, such as increasing amount of L2s, L3s, or shards of Ethereum mainnets.
  5. Enable hashed based temparary chain: There have been suggestions of using a hash-based identifier in place on Chain ID to allow the value to adapt over time to different contentious forks and other scenarios. This proposal does not describe this behavior, but ~63 bits of entropy should be enough to ensure that no collisions are likely for reasonable (e.g. non-malicious) uses of this feature for that purpose.

Specification

We declared the following chainID range

  1. (1, 2^31 - 1): "Safe Range", the higher bound is decided by Javascript number
  2. (1, MAX_CHAIN_ID); "Max Range", in which MAX_CHAIN_ID := floor(MAX_UINT64 / 2) - 36 = 9,223,372,036,854,775,771:

Rationale

Beyond "Max Range", the EIP-155 will overflow as discussed below

The MAX_CHAIN_ID is calculated to avoid overflow when performing uint64 math. For reference, a value of 0 or less is also disallowed.

Due to how the calculation for chain ID is performed, the maximum value seen during the arithmetic is CHAIN_ID * 2 + 36, so clients must test to ensure no overflow conditions are encountered when the highest value is used. No underflow is possible.

EIP-155 introduces the Chain ID parameter, which is an important parameter used for domain separation (replay protection) of Ethereum protocol signed messages. However, it does not specify any properties about the size that this parameter takes. Allowing it to be 256-bit wide means that the RLP encoding of a transaction must use >256-bit arithmetic to calculate the v field.

and suggests a reasonable maximum enforced size in order to ensure that there are no issues when encoding this parameter. This would allow a sufficient amount of different values for this parameter, which is typically chosen by community consensus as a genesis parameter for a given chain and thus does not change often.

Without a well-chosen value of Chain ID, there could be differences in the implementation of EIP-155 (and EIP-1344 by derivative) in both client codebase and external tooling that could lead to consensus-critical vulnerabilities being introduced to the network. By making this limit explicit, we avoid this scenario for Ethereum and any project which uses the Ethereum codebase.

Also, the field chainID have experienced increasing usage and dependencies, due more and more contracts are depending on EIP-1344 to expose CHAIN ID in the smart contract execution. For example when used with EIP-712, ERC-1271 for on-contract signature verification, chainId has been increasingly introduced for replay attack prevention. It's security critical to ensure clients depending on the chainId computation in cryptography yields identical result for verification in all cases.

Backwards Compatibility

This EIP introduces a change that affects previous implementations of this feature. However, as of time of writing(2022-10-18) no known chain makes use of a value outside of the suggested bounds, there should not be an issue in adopting this limit on the size of this parameter, therefore the impact should be non-existent.

If any other chain is operating with a incompatible chainId, we advised they make proper arrangement when this EIP becomes adopted.

Security Considerations

Needs discussion.

Copyright and related rights waived via CC0.

扩展阅读
欢迎补充好内容
去提交

不想错过最新的 EIP 动态?

订阅 EIPs Fun 周刊以跟进相关更新,建⽴你与 EIP 之间的连接 ,更好地建设以太坊。

详情
支持以太坊贡献者,推动生态建设
资源
GitHub
支持社区