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。
回复 where to buy cytotec for sale 取消回复