EIP-4844: rename "data hash" to "blob hash" (#7947)

See https://github.com/ethereum/EIPs/pull/7001
This commit is contained in:
Andrew Ashikhmin 2023-07-31 10:12:53 +02:00 committed by GitHub
parent 443757edbd
commit 03ac80ad2d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
17 changed files with 38 additions and 38 deletions

View File

@ -836,6 +836,6 @@ func (m callMsg) Data() []byte { return m.CallMsg.Data }
func (m callMsg) AccessList() types2.AccessList { return m.CallMsg.AccessList } func (m callMsg) AccessList() types2.AccessList { return m.CallMsg.AccessList }
func (m callMsg) IsFree() bool { return false } func (m callMsg) IsFree() bool { return false }
func (m callMsg) BlobGas() uint64 { return misc.GetBlobGasUsed(len(m.CallMsg.DataHashes)) } func (m callMsg) BlobGas() uint64 { return misc.GetBlobGasUsed(len(m.CallMsg.BlobHashes)) }
func (m callMsg) MaxFeePerBlobGas() *uint256.Int { return m.CallMsg.MaxFeePerBlobGas } func (m callMsg) MaxFeePerBlobGas() *uint256.Int { return m.CallMsg.MaxFeePerBlobGas }
func (m callMsg) DataHashes() []libcommon.Hash { return m.CallMsg.DataHashes } func (m callMsg) BlobHashes() []libcommon.Hash { return m.CallMsg.BlobHashes }

View File

@ -80,7 +80,7 @@ func NewEVMTxContext(msg Message) evmtypes.TxContext {
return evmtypes.TxContext{ return evmtypes.TxContext{
Origin: msg.From(), Origin: msg.From(),
GasPrice: msg.GasPrice(), GasPrice: msg.GasPrice(),
DataHashes: msg.DataHashes(), BlobHashes: msg.BlobHashes(),
} }
} }

View File

@ -92,7 +92,7 @@ type Message interface {
CheckNonce() bool CheckNonce() bool
Data() []byte Data() []byte
AccessList() types2.AccessList AccessList() types2.AccessList
DataHashes() []libcommon.Hash BlobHashes() []libcommon.Hash
IsFree() bool IsFree() bool
} }

View File

@ -38,7 +38,7 @@ func (stx BlobTx) copy() *BlobTx {
func (stx BlobTx) Type() byte { return BlobTxType } func (stx BlobTx) Type() byte { return BlobTxType }
func (stx BlobTx) GetDataHashes() []libcommon.Hash { func (stx BlobTx) GetBlobHashes() []libcommon.Hash {
return stx.BlobVersionedHashes return stx.BlobVersionedHashes
} }
@ -51,7 +51,7 @@ func (stx BlobTx) AsMessage(s Signer, baseFee *big.Int, rules *chain.Rules) (Mes
if err != nil { if err != nil {
return Message{}, err return Message{}, err
} }
msg.dataHashes = stx.BlobVersionedHashes msg.blobHashes = stx.BlobVersionedHashes
return msg, err return msg, err
} }

View File

@ -300,7 +300,7 @@ func (txw *BlobTxWrapper) GetFeeCap() *uint256.Int { return txw.Tx.GetFeeCap() }
func (txw *BlobTxWrapper) Cost() *uint256.Int { return txw.Tx.GetFeeCap() } func (txw *BlobTxWrapper) Cost() *uint256.Int { return txw.Tx.GetFeeCap() }
func (txw *BlobTxWrapper) GetDataHashes() []libcommon.Hash { return txw.Tx.GetDataHashes() } func (txw *BlobTxWrapper) GetBlobHashes() []libcommon.Hash { return txw.Tx.GetBlobHashes() }
func (txw *BlobTxWrapper) GetGas() uint64 { return txw.Tx.GetGas() } func (txw *BlobTxWrapper) GetGas() uint64 { return txw.Tx.GetGas() }
func (txw *BlobTxWrapper) GetBlobGas() uint64 { return txw.Tx.GetBlobGas() } func (txw *BlobTxWrapper) GetBlobGas() uint64 { return txw.Tx.GetBlobGas() }

View File

@ -87,8 +87,8 @@ func (ct CommonTx) IsContractDeploy() bool {
return ct.GetTo() == nil return ct.GetTo() == nil
} }
func (ct *CommonTx) GetDataHashes() []libcommon.Hash { func (ct *CommonTx) GetBlobHashes() []libcommon.Hash {
// Only blob txs have data hashes // Only blob txs have blob hashes
return []libcommon.Hash{} return []libcommon.Hash{}
} }

View File

@ -66,7 +66,7 @@ type Transaction interface {
GetEffectiveGasTip(baseFee *uint256.Int) *uint256.Int GetEffectiveGasTip(baseFee *uint256.Int) *uint256.Int
GetFeeCap() *uint256.Int GetFeeCap() *uint256.Int
Cost() *uint256.Int Cost() *uint256.Int
GetDataHashes() []libcommon.Hash GetBlobHashes() []libcommon.Hash
GetGas() uint64 GetGas() uint64
GetBlobGas() uint64 GetBlobGas() uint64
GetValue() *uint256.Int GetValue() *uint256.Int
@ -525,7 +525,7 @@ type Message struct {
accessList types2.AccessList accessList types2.AccessList
checkNonce bool checkNonce bool
isFree bool isFree bool
dataHashes []libcommon.Hash blobHashes []libcommon.Hash
} }
func NewMessage(from libcommon.Address, to *libcommon.Address, nonce uint64, amount *uint256.Int, gasLimit uint64, func NewMessage(from libcommon.Address, to *libcommon.Address, nonce uint64, amount *uint256.Int, gasLimit uint64,
@ -593,13 +593,13 @@ func (m *Message) ChangeGas(globalGasCap, desiredGas uint64) {
m.gasLimit = gas m.gasLimit = gas
} }
func (m Message) BlobGas() uint64 { return fixedgas.BlobGasPerBlob * uint64(len(m.dataHashes)) } func (m Message) BlobGas() uint64 { return fixedgas.BlobGasPerBlob * uint64(len(m.blobHashes)) }
func (m Message) MaxFeePerBlobGas() *uint256.Int { func (m Message) MaxFeePerBlobGas() *uint256.Int {
return &m.maxFeePerBlobGas return &m.maxFeePerBlobGas
} }
func (m Message) DataHashes() []libcommon.Hash { return m.dataHashes } func (m Message) BlobHashes() []libcommon.Hash { return m.blobHashes }
func DecodeSSZ(data []byte, dest codec.Deserializable) error { func DecodeSSZ(data []byte, dest codec.Deserializable) error {
err := dest.Deserialize(codec.NewDecodingReader(bytes.NewReader(data), uint64(len(data)))) err := dest.Deserialize(codec.NewDecodingReader(bytes.NewReader(data), uint64(len(data))))

View File

@ -125,7 +125,7 @@ func toBlobTxJSON(tx *BlobTx) *txJSON {
enc.R = (*hexutil.Big)(tx.R.ToBig()) enc.R = (*hexutil.Big)(tx.R.ToBig())
enc.S = (*hexutil.Big)(tx.S.ToBig()) enc.S = (*hexutil.Big)(tx.S.ToBig())
enc.MaxFeePerBlobGas = (*hexutil.Big)(tx.MaxFeePerBlobGas.ToBig()) enc.MaxFeePerBlobGas = (*hexutil.Big)(tx.MaxFeePerBlobGas.ToBig())
enc.BlobVersionedHashes = tx.GetDataHashes() enc.BlobVersionedHashes = tx.GetBlobHashes()
return &enc return &enc
} }

View File

@ -243,22 +243,22 @@ func enable3860(jt *JumpTable) {
jt[CREATE2].dynamicGas = gasCreate2Eip3860 jt[CREATE2].dynamicGas = gasCreate2Eip3860
} }
// enable4844 applies mini-danksharding (DATAHASH Opcode) // enable4844 applies mini-danksharding (BLOBHASH opcode)
// - Adds an opcode that returns the versioned data hash of the tx at a index. // - Adds an opcode that returns the versioned blob hash of the tx at a index.
func enable4844(jt *JumpTable) { func enable4844(jt *JumpTable) {
jt[DATAHASH] = &operation{ jt[BLOBHASH] = &operation{
execute: opDataHash, execute: opBlobHash,
constantGas: GasFastestStep, constantGas: GasFastestStep,
numPop: 1, numPop: 1,
numPush: 1, numPush: 1,
} }
} }
// opDataHash implements DATAHASH opcode // opBlobHash implements the BLOBHASH opcode
func opDataHash(pc *uint64, interpreter *EVMInterpreter, scope *ScopeContext) ([]byte, error) { func opBlobHash(pc *uint64, interpreter *EVMInterpreter, scope *ScopeContext) ([]byte, error) {
idx := scope.Stack.Peek() idx := scope.Stack.Peek()
if idx.LtUint64(uint64(len(interpreter.evm.TxContext().DataHashes))) { if idx.LtUint64(uint64(len(interpreter.evm.TxContext().BlobHashes))) {
hash := interpreter.evm.TxContext().DataHashes[idx.Uint64()] hash := interpreter.evm.TxContext().BlobHashes[idx.Uint64()]
idx.SetBytes(hash.Bytes()) idx.SetBytes(hash.Bytes())
} else { } else {
idx.Clear() idx.Clear()

View File

@ -42,7 +42,7 @@ type TxContext struct {
TxHash common.Hash TxHash common.Hash
Origin common.Address // Provides information for ORIGIN Origin common.Address // Provides information for ORIGIN
GasPrice *uint256.Int // Provides information for GASPRICE GasPrice *uint256.Int // Provides information for GASPRICE
DataHashes []common.Hash // Provides versioned data hashes for DATAHASH BlobHashes []common.Hash // Provides versioned blob hashes for BLOBHASH
} }
type ( type (

View File

@ -95,16 +95,16 @@ const (
// 0x40 range - block operations. // 0x40 range - block operations.
const ( const (
BLOCKHASH OpCode = 0x40 + iota BLOCKHASH OpCode = 0x40
COINBASE COINBASE OpCode = 0x41
TIMESTAMP TIMESTAMP OpCode = 0x42
NUMBER NUMBER OpCode = 0x43
DIFFICULTY DIFFICULTY OpCode = 0x44
GASLIMIT GASLIMIT OpCode = 0x45
CHAINID OpCode = 0x46 CHAINID OpCode = 0x46
SELFBALANCE OpCode = 0x47 SELFBALANCE OpCode = 0x47
BASEFEE OpCode = 0x48 BASEFEE OpCode = 0x48
DATAHASH OpCode = 0x49 BLOBHASH OpCode = 0x49
) )
// 0x50 range - 'storage' and execution. // 0x50 range - 'storage' and execution.
@ -281,7 +281,7 @@ var opCodeToString = map[OpCode]string{
CHAINID: "CHAINID", CHAINID: "CHAINID",
SELFBALANCE: "SELFBALANCE", SELFBALANCE: "SELFBALANCE",
BASEFEE: "BASEFEE", BASEFEE: "BASEFEE",
DATAHASH: "DATAHASH", BLOBHASH: "BLOBHASH",
// 0x50 range - 'storage' and execution. // 0x50 range - 'storage' and execution.
POP: "POP", POP: "POP",
@ -436,7 +436,7 @@ var stringToOp = map[string]OpCode{
"CALLDATACOPY": CALLDATACOPY, "CALLDATACOPY": CALLDATACOPY,
"CHAINID": CHAINID, "CHAINID": CHAINID,
"BASEFEE": BASEFEE, "BASEFEE": BASEFEE,
"DATAHASH": DATAHASH, "BLOBHASH": BLOBHASH,
"DELEGATECALL": DELEGATECALL, "DELEGATECALL": DELEGATECALL,
"STATICCALL": STATICCALL, "STATICCALL": STATICCALL,
"CODESIZE": CODESIZE, "CODESIZE": CODESIZE,

View File

@ -127,7 +127,7 @@ type CallMsg struct {
FeeCap *uint256.Int // EIP-1559 fee cap per gas. FeeCap *uint256.Int // EIP-1559 fee cap per gas.
Tip *uint256.Int // EIP-1559 tip per gas. Tip *uint256.Int // EIP-1559 tip per gas.
AccessList types2.AccessList // EIP-2930 access list. AccessList types2.AccessList // EIP-2930 access list.
DataHashes []libcommon.Hash // EIP-4844 versioned data hashes. BlobHashes []libcommon.Hash // EIP-4844 versioned blob hashes.
} }
// A ContractCaller provides contract calls, essentially transactions that are executed by // A ContractCaller provides contract calls, essentially transactions that are executed by

View File

@ -461,7 +461,7 @@ func newRPCTransaction(tx types.Transaction, blockHash libcommon.Hash, blockNumb
// if the transaction has been mined, compute the effective gas price // if the transaction has been mined, compute the effective gas price
result.GasPrice = computeGasPrice(tx, blockHash, baseFee) result.GasPrice = computeGasPrice(tx, blockHash, baseFee)
result.MaxFeePerBlobGas = (*hexutil.Big)(t.MaxFeePerBlobGas.ToBig()) result.MaxFeePerBlobGas = (*hexutil.Big)(t.MaxFeePerBlobGas.ToBig())
result.BlobVersionedHashes = t.GetDataHashes() result.BlobVersionedHashes = t.GetBlobHashes()
} }
signer := types.LatestSignerForChainID(chainId.ToBig()) signer := types.LatestSignerForChainID(chainId.ToBig())
var err error var err error

View File

@ -207,7 +207,7 @@ func (s *EngineServer) newPayload(ctx context.Context, req *engine_types.Executi
if version >= clparams.DenebVersion { if version >= clparams.DenebVersion {
actualBlobHashes := []libcommon.Hash{} actualBlobHashes := []libcommon.Hash{}
for _, tx := range transactions { for _, tx := range transactions {
actualBlobHashes = append(actualBlobHashes, tx.GetDataHashes()...) actualBlobHashes = append(actualBlobHashes, tx.GetBlobHashes()...)
} }
if !reflect.DeepEqual(actualBlobHashes, expectedBlobHashes) { if !reflect.DeepEqual(actualBlobHashes, expectedBlobHashes) {
s.logger.Warn("[NewPayload] mismatch in blob hashes", s.logger.Warn("[NewPayload] mismatch in blob hashes",

View File

@ -215,7 +215,7 @@ func (s *EngineServerExperimental) newPayload(ctx context.Context, req *engine_t
if version >= clparams.DenebVersion { if version >= clparams.DenebVersion {
actualBlobHashes := []libcommon.Hash{} actualBlobHashes := []libcommon.Hash{}
for _, tx := range transactions { for _, tx := range transactions {
actualBlobHashes = append(actualBlobHashes, tx.GetDataHashes()...) actualBlobHashes = append(actualBlobHashes, tx.GetBlobHashes()...)
} }
if !reflect.DeepEqual(actualBlobHashes, expectedBlobHashes) { if !reflect.DeepEqual(actualBlobHashes, expectedBlobHashes) {
s.logger.Warn("[NewPayload] mismatch in blob hashes", s.logger.Warn("[NewPayload] mismatch in blob hashes",

View File

@ -166,7 +166,7 @@ func (e *EthereumExecutionModule) GetAssembledBlock(ctx context.Context, req *ex
if !ok { if !ok {
return nil, fmt.Errorf("expected blob transaction to be type BlobTxWrapper, got: %T", blobTx) return nil, fmt.Errorf("expected blob transaction to be type BlobTxWrapper, got: %T", blobTx)
} }
versionedHashes, commitments, proofs, blobs := blobTx.GetDataHashes(), blobTx.Commitments, blobTx.Proofs, blobTx.Blobs versionedHashes, commitments, proofs, blobs := blobTx.GetBlobHashes(), blobTx.Commitments, blobTx.Proofs, blobTx.Blobs
lenCheck := len(versionedHashes) lenCheck := len(versionedHashes)
if lenCheck != len(commitments) || lenCheck != len(proofs) || lenCheck != len(blobs) { if lenCheck != len(commitments) || lenCheck != len(proofs) || lenCheck != len(blobs) {
return nil, fmt.Errorf("tx %d in block %s has inconsistent commitments (%d) / proofs (%d) / blobs (%d) / "+ return nil, fmt.Errorf("tx %d in block %s has inconsistent commitments (%d) / proofs (%d) / blobs (%d) / "+

View File

@ -765,7 +765,7 @@ func marshalReceipt(receipt *types.Receipt, txn types.Transaction, chainConfig *
fields["contractAddress"] = receipt.ContractAddress fields["contractAddress"] = receipt.ContractAddress
} }
// Set derived blob related fields // Set derived blob related fields
numBlobs := len(txn.GetDataHashes()) numBlobs := len(txn.GetBlobHashes())
if numBlobs > 0 { if numBlobs > 0 {
if header.ExcessBlobGas == nil { if header.ExcessBlobGas == nil {
log.Warn("excess blob gas not set when trying to marshal blob tx") log.Warn("excess blob gas not set when trying to marshal blob tx")