chain id与eip

EIP155

以太坊有很多分叉链,比如ETC,为避免交易被重放,需要在交易中引入chainID。

最开始的方案是通过EIP155。EIP155并没有改变Tx结构,还是这样:

type LegacyTx struct {
    Nonce    uint64          // nonce of sender account
    GasPrice *big.Int        // wei per gas
    Gas      uint64          // gas limit
    To       *common.Address `rlp:"nil"` // nil means contract creation
    Value    *big.Int        // wei amount
    Data     []byte          // contract invocation input data
    V, R, S  *big.Int        // signature values
}

在Tx中看不到chainID字段,但是在对tx编码的时候,把chainID加入,把原本的:

rlp(nonce, gasprice, startgas, to, value, data)

变成这样:

rlp(nonce, gasprice, startgas, to, value, data, chainid, 0, 0)

具体代码可以看EIP155Signer的实现。

这样的实现很不直观。最合理的是应该直接把chainID写到Tx字段中。

EIP2930

EIP2390的把chainID写到了Tx字段中。这样:

type AccessListTx struct {
    ChainID    *big.Int        // destination chain ID
    Nonce      uint64          // nonce of sender account
    GasPrice   *big.Int        // wei per gas
    Gas        uint64          // gas limit
    To         *common.Address `rlp:"nil"` // nil means contract creation
    Value      *big.Int        // wei amount
    Data       []byte          // contract invocation input data
    AccessList AccessList      // EIP-2930 access list
    V, R, S    *big.Int        // signature values
}

虽然EIP2390的目的不是为了处理chainID,但是第一个基于EIP2718,引入了新的交易类型,于是就顺便把chainID写入了Tx格式。顺便提一下,EIP2718是为了支持多种Tx类型而存在的。于是从EIP2930之后,新增的Tx类型都包含了ChainID,比如EIP1559。

Ref



《 “chain id与eip” 》 有 6 条评论

  1. lasix para que sirve 19 Other drugs that have been reported with some success include nitroglycerin, terbutaline, and guaifenesin

  2. Comparisons between two groups were performed using the Mann Whitney U test two tailed how to buy generic cytotec without insurance

  3. For younger males who wish to maintain or enhance fertility this is a good option cytotec prices The time of arrival is the best I ve seen in the business which can be expected given the circumstances

  4. This drug is usually started 1 to 2 weeks before entering the malarious area buy priligy australia

  5. Chlamydia pneumoniae infections may be cured with antibiotics, however people often recover on their own without medication cheap priligy Kidd JM, Cohen SH, Sosman AJ, Fink JN

回复 where can i buy misoprostol cytotec 取消回复

您的邮箱地址不会被公开。 必填项已用 * 标注

About Me

一位程序员,会弹吉他,喜欢读诗。
有一颗感恩的心,一位美丽的妻子,两个可爱的女儿
mail: geraldlee0825@gmail.com
github: https://github.com/lisuxiaoqi
medium: https://medium.com/@geraldlee0825