关于PlatON网络支持双ChainID的提案 | Proposal on Supporting Two ChainIDs in the PlatON Network


PIP: 7
Topic: PlatON网络对双ChaiID的支持
Author: benbaley
Status: Draft
Type: Upgrade
Description: 提议在PlatON主网络对ChainID 100和210425同时进行支持和适配
Created: 2022-02-11

背景

PlatON主网当前的ChainID值是100,在ethereum-lists/chains 登记的链ID中与其他网络冲突了,为了更好的对DApp(如MetaMask)进行支持,需要再确定一个在EVM框架下由统一的第三方平台注册过唯一的链ID。因PlatON主网已运行近一年,已有的生态工具(钱包、浏览器等)不能立即迁移或适配新的链ID,因此提议在一段时期内PlatON主网络同时支持双ChainID。

概述

当前PlatON主网络ChainID值和其他网络冲突,存在以下问题:

  1. 存在不同链上的交易在PlatON网络上重放风险
  2. 如MetaMask之类的第三方应用不能唯一适配到PlatON网络上

因此,我们的最终目标是将主网络的ChainID由当前的100更新为210425,为达成这个目标需要分2步进行:

  • 支持新ChainID210425

可以通过PlatON特有的升级提案先在主网络确保对新链ID210425的支持,同时兼容旧ChainID100,这样既可以很好的适配诸如MetaMask之类的工具,方便新DApp的快速开发,又可以同时兼容当前已经在运行中的应用。

  • 未来择机停止对ChainID100的支持

在完成第一阶段升级后,所有新的应用将直接使用新ChainID开发和运行,对于旧的DApp来说(只针对使用了ChainID的应用),可以有充足的时间进行适配和升级,在经历充分的适配调整时间以后,需要再发起新的升级提案,停止使用旧ChainID。

原理

在PlatON网络中ChainID主要有以下作用:

  1. 防止交易重放

交易签名加入了ChainID,用于区分不同的链,避免将其他链的交易在PlatON网络中执行,因v值除了记录ChainID外还用于标记椭圆曲线y值的奇偶性,因此只要两个ChainID不是连续整数则可以根据v值获取到用户签名时填入的ChainID。

  1. 防止异形攻击

P2P握手消息中加入ChainID,用于验证节点是否是属于同一个链,可以通过判断握手消息中携带的ChainID是否为PlatON所支持的2个ChainID中的一个来适配。

实现

  1. 交易验证

v = v - 2*100(原ChainID)

v = v - 8

if v > 28

then

v = v - (新ChainID - 原ChainID)

判断v是否为27或28

 使用新新ChainID进行判断

 签名非法

else

使用原ChainID进行判断

  1. P2P握手

handle处理ping、pong、findnode、neighbors消息时,直接对Rest字段判断,为两个ChainID其一者则验证通过,当收到的ping消息带的chainid是旧值,则pong返回的消息也返回旧值,同理适用于findnode、neighbors消息。

  1. opCode(0x46)

EVM执行CHAINID指令时,根据大版本号判断,提案前使用旧ChainID, 提案升级成功后按新ChainID返回。

影响分析

底层实现本提案后,将有以下影响:

  1. 需要链上治理升级

意味着需要分叉, 新客户端将兼容旧的交易的ChainID和旧节点, 但旧客户端无法支持新ChainID的交易和新节点。

  1. P2P链接的影响

由于新节点使用新ChainID,在节点发现时(UDP消息,对应Ping、Pong、Findnode、Neighbors)新节点消息带新ChainID,该消息会被旧节点认为是不属于当前链,新节点不能发现旧节点,且只能主动连新节点,不能主动连接旧节点,但旧节点可以发现新节点,也可以主动连接新节点。

  1. DApp需要对ChainID更新适配

由于新版本客户端ChainID更新为210425,EVM获取ChaiID的指令需要根据版本号(链上)来判断返回新值或是旧值,因此对于DApp中合约逻辑使用了ChainID的应用,需要重新进行适配,对于在合约中硬编码了ChainID逻辑的应用,只能通过重新部署新合约后将旧合约中数据迁移致新约的方式进行适配,对于在应用层(链下)使用ChainID的情形,需要在应用层代码逻辑中自行适配。

链接

  1. Chain Agnostic Improvement Proposals
  2. Ethereum-lists注册PlatON主网络ChainID

欢迎大家讨论并发表各自的看法 :rose:

2 个赞

支持 :crazy_face: :crazy_face: :crazy_face: :crazy_face:

我帮你翻译吧:
PlatON network support for double chaiid!
I hope you’ll support it.
Or you’ll be in trouble.
Understand?
翻译完成,简单明了。

[English translation]


PIP: 7
Topic: PlatON network to support ChainID 100 and 210425
Author: benbaley
Status: Draft 
Type: Upgrade
Description: It is proposed that the PlatON mainnet should support and be adapted to both ChainID 100 and 210425
Created: 2022-02-11

Proposal on Supporting Two ChainIDs in the PlatON Network

Background

The current ChainID of the PlatON mainnet is 100, which conflicts with that of other networks registered in ethereum-lists/chains. To better support DApps like MetaMask, another ChainID is needed, one that is unique and registered by a unified third-party platform under the EVM framework. As the PlatON mainnet has been running for nearly a year, the existing ecosystem tools (wallets, browsers, etc.) cannot be immediately migrated or adapted to the new ChainID. It is therefore proposed that the PlatON mainnet should support two ChainIDs at the same time for a certain period.

Overview

The current ChainID of the PlatON mainnet conflicts with that of other networks, which may lead to the following problems:

  1. Transactions on other chains might be replayed on the PlatON network.

  2. Third-party applications such as MetaMask may not be uniquely adapted to the PlatON network

As such, our ultimate goal is to update the ChainID of the mainnet from 100 to 210425. This goal will be achieved in two steps:

  • Support the new ChainID 210425

    We can first make sure that the mainnet support the new ChainID 210425 through PlatON’s unique upgrade proposal. In the meantime, the existing ChainID100 will also be supported. This means that the mainnet will be well adapted to tools such as MetaMask. Moreover, the upgrade will enable the fast development of new DApps while offering compatibility for applications currently running on PlatON.

  • The PlatON network will stop supporting ChainID100 sometime in the future.

    Upon completion of Step 1 of the upgrade, all new applications will be developed and run directly using the new ChainID. For existing DApps (applicable only to applications using ChainID), there will be enough time for adaptation and upgrade. Following a sufficient adjustment period, a new upgrade proposal will be initiated and the old ChainID will no longer be supported.

Principle

The primary functions of ChianID in the PlatON network are as follows:

  1. Avoid transaction replay

ChainID is added to the transaction signature to distinguish between different chains and avoid executing the transactions on other chains in the PlatON network. In addition to recording the ChainID, the V value is also used to mark the parity of the Y value of the elliptic curve. Therefore, so as long as the two ChainIDs are not consecutive numbers, the ChainID entered when the user provides his/her signature can be obtained based on the V value.

  1. Prevent alien attack

ChainID is added to the P2P handshake message to determine whether the nodes belong to the same chain. Adaptation is subject to whether the ChainID contained in the handshake message coincides with one of the two ChainIDs supported by PlatON.

Implementation

  1. Transaction verification

v = v - 2*100 (the existing ChainID)

v = v - 8

if v > 28

then

v = v - (the new ChainID - the existing ChainID)

Determine if v equals 27 or 28

Yes

 To be verified using the new ChianID

No

 The signature is illegitimate

else

To be verified using the existing ChianID

  1. P2P handshake

When processing messages that include ping, pong, findnode, and neighbors, the Rest field will be directly verified. The message will be deemed valid if the number coincides with one of the two ChainIDs. When the ChainID of the received ping message coincides with the old ChainID, the returned message of pong will also return the old ChainID. The same principle also applies to findnode and neighbors.

  1. opCode(0x46)

When the EVM executes the CHAINID command, verification will be subject to the version number. Before the upgrade proposal, the old ChainID will be used; after the upgrade, the new ChainID will be adopted.

Impact Analysis

The implementation of this proposal at the underlying level will have the following impacts:

  1. An upgrade of on-chain governance is required

Such an upgrade indicates that a fork is required. Though the new client will be compatible with transactions and nodes using the old ChainID, the old client will not be able to support transactions and nodes using the new ChainID.

  1. Impact on P2P links

As new nodes will be using a new ChainID, the new node message contains a new ChainID when the nodes are discovered (UDP message, corresponding to Ping, Pong, Findnode, Neighbors). To old nodes, such a message means that the nodes do not belong to the current blockchain. Moreover, a new node cannot discover old nodes and may only connect to other new nodes. However, an old node can discover new nodes and connect to such nodes.

  1. DApps should be upgraded and adapted to the new ChianID

Given that the ChainID of the new client version will be updated to 210425, the EVM command for obtaining the ChaiID should determine whether to return the new ChainID or the old ChainID according to the version number (on-chain). As such, DApps that use ChainID in the contract logic need to be readapted. Applications with a hard-coded ChainID logic in the contract may only be adapted by migrating the relevant data from the old contract to the new contract after the new contract is redeployed. If ChianID is used on the application level (off-chain), self-adaptation in the coding logic of the application level will be required.

Links

  1. Chain Agnostic Improvement Proposals

  2. Ethereum-lists: Resigtered ChainID of the PlatON mainnet