From b3eca9f583fa1440fd2d9614bc7b88e836776aba Mon Sep 17 00:00:00 2001 From: devopsbo3 <69951731+devopsbo3@users.noreply.github.com> Date: Fri, 10 Nov 2023 12:31:54 -0600 Subject: [PATCH] Revert "core, eth/downloader: validate blobtx.To at serialization time (#27393)" This reverts commit 0eb3a6cdbb1647a2d5bd216a7cd5c529e626a3b4. --- core/block_validator.go | 3 +++ core/types/receipt_test.go | 4 ++-- core/types/transaction_marshalling.go | 5 ++--- core/types/tx_blob.go | 6 +++--- eth/downloader/queue.go | 3 +++ 5 files changed, 13 insertions(+), 8 deletions(-) diff --git a/core/block_validator.go b/core/block_validator.go index 1bca444451275..6dc9a3fa051a5 100644 --- a/core/block_validator.go +++ b/core/block_validator.go @@ -89,6 +89,9 @@ func (v *BlockValidator) ValidateBody(block *types.Block) error { // Validate the data blobs individually too if tx.Type() == types.BlobTxType { + if tx.To() == nil { + return errors.New("contract creation attempt by blob transaction") // TODO(karalabe): Why not make the field non-nil-able + } if len(tx.BlobHashes()) == 0 { return errors.New("no-blob blob transaction present in block body") } diff --git a/core/types/receipt_test.go b/core/types/receipt_test.go index 5722eceac13d6..168f36208b9eb 100644 --- a/core/types/receipt_test.go +++ b/core/types/receipt_test.go @@ -130,7 +130,7 @@ var ( }), // EIP-4844 transactions. NewTx(&BlobTx{ - To: to6, + To: &to6, Nonce: 6, Value: uint256.NewInt(6), Gas: 6, @@ -139,7 +139,7 @@ var ( BlobFeeCap: uint256.NewInt(100066), }), NewTx(&BlobTx{ - To: to7, + To: &to7, Nonce: 7, Value: uint256.NewInt(7), Gas: 7, diff --git a/core/types/transaction_marshalling.go b/core/types/transaction_marshalling.go index 070927484cc7c..6c6c50d498d72 100644 --- a/core/types/transaction_marshalling.go +++ b/core/types/transaction_marshalling.go @@ -290,10 +290,9 @@ func (tx *Transaction) UnmarshalJSON(input []byte) error { return errors.New("missing required field 'nonce' in transaction") } itx.Nonce = uint64(*dec.Nonce) - if dec.To == nil { - return errors.New("missing required field 'to' in transaction") + if dec.To != nil { + itx.To = dec.To } - itx.To = *dec.To if dec.Gas == nil { return errors.New("missing required field 'gas' for txdata") } diff --git a/core/types/tx_blob.go b/core/types/tx_blob.go index 34c01ee014c3a..58065d0017d31 100644 --- a/core/types/tx_blob.go +++ b/core/types/tx_blob.go @@ -31,7 +31,7 @@ type BlobTx struct { GasTipCap *uint256.Int // a.k.a. maxPriorityFeePerGas GasFeeCap *uint256.Int // a.k.a. maxFeePerGas Gas uint64 - To common.Address + To *common.Address `rlp:"nil"` // nil means contract creation Value *uint256.Int Data []byte AccessList AccessList @@ -48,7 +48,7 @@ type BlobTx struct { func (tx *BlobTx) copy() TxData { cpy := &BlobTx{ Nonce: tx.Nonce, - To: tx.To, + To: copyAddressPtr(tx.To), Data: common.CopyBytes(tx.Data), Gas: tx.Gas, // These are copied below. @@ -104,7 +104,7 @@ func (tx *BlobTx) gasTipCap() *big.Int { return tx.GasTipCap.ToBig() } func (tx *BlobTx) gasPrice() *big.Int { return tx.GasFeeCap.ToBig() } func (tx *BlobTx) value() *big.Int { return tx.Value.ToBig() } func (tx *BlobTx) nonce() uint64 { return tx.Nonce } -func (tx *BlobTx) to() *common.Address { tmp := tx.To; return &tmp } +func (tx *BlobTx) to() *common.Address { return tx.To } func (tx *BlobTx) blobGas() uint64 { return params.BlobTxDataGasPerBlob * uint64(len(tx.BlobHashes)) } func (tx *BlobTx) blobGasFeeCap() *big.Int { return tx.BlobFeeCap.ToBig() } func (tx *BlobTx) blobHashes() []common.Hash { return tx.BlobHashes } diff --git a/eth/downloader/queue.go b/eth/downloader/queue.go index 8c82d7f072d0d..25449d87724b2 100644 --- a/eth/downloader/queue.go +++ b/eth/downloader/queue.go @@ -806,6 +806,9 @@ func (q *queue) DeliverBodies(id string, txLists [][]*types.Transaction, txListH // Validate the data blobs individually too if tx.Type() == types.BlobTxType { + if tx.To() == nil { + return errInvalidBody // TODO(karalabe): Why not make the field non-nil-able + } if len(tx.BlobHashes()) == 0 { return errInvalidBody }