From ca54e8aa52f2db0260503eb81015f25c47da004f Mon Sep 17 00:00:00 2001 From: zhiqiangxu <652732310@qq.com> Date: Sat, 24 Feb 2024 12:39:17 +0800 Subject: [PATCH] only allow blob tx after cancun fork --- core/error.go | 3 +++ core/state_transition.go | 39 ++++++++++++++++++++++----------------- 2 files changed, 25 insertions(+), 17 deletions(-) diff --git a/core/error.go b/core/error.go index 72cacf8c78..5795fc8067 100644 --- a/core/error.go +++ b/core/error.go @@ -110,4 +110,7 @@ var ( // ErrBlobTxCreate is returned if a blob transaction has no explicit to field. ErrBlobTxCreate = errors.New("blob transaction of type create") + + // ErrBlobTxTooEarly is returned if a blob transaction is found before cancun fork. + ErrBlobTxTooEarly = errors.New("blob transaction is only allowed after cancun fork") ) diff --git a/core/state_transition.go b/core/state_transition.go index 9c4f76d1c5..6fd8f18a4a 100644 --- a/core/state_transition.go +++ b/core/state_transition.go @@ -319,25 +319,26 @@ func (st *StateTransition) preCheck() error { } } } - // Check the blob version validity - if msg.BlobHashes != nil { - // The to field of a blob tx type is mandatory, and a `BlobTx` transaction internally - // has it as a non-nillable value, so any msg derived from blob transaction has it non-nil. - // However, messages created through RPC (eth_call) don't have this restriction. - if msg.To == nil { - return ErrBlobTxCreate - } - if len(msg.BlobHashes) == 0 { - return ErrMissingBlobHashes - } - for i, hash := range msg.BlobHashes { - if !kzg4844.IsValidVersionedHash(hash[:]) { - return fmt.Errorf("blob %d has invalid hash version", i) - } - } - } + // Check that the user is paying at least the current blob fee if st.evm.ChainConfig().IsCancun(st.evm.Context.BlockNumber, st.evm.Context.Time) { + // Check the blob version validity + if msg.BlobHashes != nil { + // The to field of a blob tx type is mandatory, and a `BlobTx` transaction internally + // has it as a non-nillable value, so any msg derived from blob transaction has it non-nil. + // However, messages created through RPC (eth_call) don't have this restriction. + if msg.To == nil { + return ErrBlobTxCreate + } + if len(msg.BlobHashes) == 0 { + return ErrMissingBlobHashes + } + for i, hash := range msg.BlobHashes { + if !kzg4844.IsValidVersionedHash(hash[:]) { + return fmt.Errorf("blob %d has invalid hash version", i) + } + } + } if st.blobGasUsed() > 0 { // Skip the checks if gas fields are zero and blobBaseFee was explicitly disabled (eth_call) skipCheck := st.evm.Config.NoBaseFee && msg.BlobGasFeeCap.BitLen() == 0 @@ -350,6 +351,10 @@ func (st *StateTransition) preCheck() error { } } } + } else { + if msg.BlobHashes != nil { + return ErrBlobTxTooEarly + } } return st.buyGas() }