From 123136907778cb791e5a217b352e3fc2d96708aa Mon Sep 17 00:00:00 2001 From: Marius van der Wijden Date: Mon, 16 Jan 2023 14:32:20 +0100 Subject: [PATCH 1/2] core/txpool: check if initcode size is exceeded --- core/txpool/txpool.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/core/txpool/txpool.go b/core/txpool/txpool.go index dc6a71f07ac2..64aacdd5b240 100644 --- a/core/txpool/txpool.go +++ b/core/txpool/txpool.go @@ -18,6 +18,7 @@ package txpool import ( "errors" + "fmt" "math" "math/big" "sort" @@ -637,6 +638,10 @@ func (pool *TxPool) validateTx(tx *types.Transaction, local bool) error { if pool.currentState.GetBalance(from).Cmp(tx.Cost()) < 0 { return core.ErrInsufficientFunds } + // Check whether the init code size has been exceeded. + if pool.shanghai && tx.To() == nil && len(tx.Data()) > params.MaxInitCodeSize { + return fmt.Errorf("%w: code size %v limit %v", core.ErrMaxInitCodeSizeExceeded, len(tx.Data()), params.MaxInitCodeSize) + } // Ensure the transaction has more gas than the basic tx fee. intrGas, err := core.IntrinsicGas(tx.Data(), tx.AccessList(), tx.To() == nil, true, pool.istanbul, pool.shanghai) if err != nil { From 0cd032a0ebfa14fb7dd40102d688b6ae90ebcb5e Mon Sep 17 00:00:00 2001 From: Marius van der Wijden Date: Tue, 17 Jan 2023 19:11:58 +0100 Subject: [PATCH 2/2] core/txpool: move check --- core/txpool/txpool.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/core/txpool/txpool.go b/core/txpool/txpool.go index 64aacdd5b240..3e4eb21cfc68 100644 --- a/core/txpool/txpool.go +++ b/core/txpool/txpool.go @@ -600,6 +600,10 @@ func (pool *TxPool) validateTx(tx *types.Transaction, local bool) error { if tx.Size() > txMaxSize { return ErrOversizedData } + // Check whether the init code size has been exceeded. + if pool.shanghai && tx.To() == nil && len(tx.Data()) > params.MaxInitCodeSize { + return fmt.Errorf("%w: code size %v limit %v", core.ErrMaxInitCodeSizeExceeded, len(tx.Data()), params.MaxInitCodeSize) + } // Transactions can't be negative. This may never happen using RLP decoded // transactions but may occur if you create a transaction using the RPC. if tx.Value().Sign() < 0 { @@ -638,10 +642,6 @@ func (pool *TxPool) validateTx(tx *types.Transaction, local bool) error { if pool.currentState.GetBalance(from).Cmp(tx.Cost()) < 0 { return core.ErrInsufficientFunds } - // Check whether the init code size has been exceeded. - if pool.shanghai && tx.To() == nil && len(tx.Data()) > params.MaxInitCodeSize { - return fmt.Errorf("%w: code size %v limit %v", core.ErrMaxInitCodeSizeExceeded, len(tx.Data()), params.MaxInitCodeSize) - } // Ensure the transaction has more gas than the basic tx fee. intrGas, err := core.IntrinsicGas(tx.Data(), tx.AccessList(), tx.To() == nil, true, pool.istanbul, pool.shanghai) if err != nil {