Skip to content

Commit 0eb3a6c

Browse files
karalabedevopsbo3
authored andcommitted
core, eth/downloader: validate blobtx.To at serialization time (ethereum#27393)
1 parent b606e38 commit 0eb3a6c

File tree

5 files changed

+8
-13
lines changed

5 files changed

+8
-13
lines changed

core/block_validator.go

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -89,9 +89,6 @@ func (v *BlockValidator) ValidateBody(block *types.Block) error {
8989

9090
// Validate the data blobs individually too
9191
if tx.Type() == types.BlobTxType {
92-
if tx.To() == nil {
93-
return errors.New("contract creation attempt by blob transaction") // TODO(karalabe): Why not make the field non-nil-able
94-
}
9592
if len(tx.BlobHashes()) == 0 {
9693
return errors.New("no-blob blob transaction present in block body")
9794
}

core/types/receipt_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ var (
130130
}),
131131
// EIP-4844 transactions.
132132
NewTx(&BlobTx{
133-
To: &to6,
133+
To: to6,
134134
Nonce: 6,
135135
Value: uint256.NewInt(6),
136136
Gas: 6,
@@ -139,7 +139,7 @@ var (
139139
BlobFeeCap: uint256.NewInt(100066),
140140
}),
141141
NewTx(&BlobTx{
142-
To: &to7,
142+
To: to7,
143143
Nonce: 7,
144144
Value: uint256.NewInt(7),
145145
Gas: 7,

core/types/transaction_marshalling.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -290,9 +290,10 @@ func (tx *Transaction) UnmarshalJSON(input []byte) error {
290290
return errors.New("missing required field 'nonce' in transaction")
291291
}
292292
itx.Nonce = uint64(*dec.Nonce)
293-
if dec.To != nil {
294-
itx.To = dec.To
293+
if dec.To == nil {
294+
return errors.New("missing required field 'to' in transaction")
295295
}
296+
itx.To = *dec.To
296297
if dec.Gas == nil {
297298
return errors.New("missing required field 'gas' for txdata")
298299
}

core/types/tx_blob.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ type BlobTx struct {
3131
GasTipCap *uint256.Int // a.k.a. maxPriorityFeePerGas
3232
GasFeeCap *uint256.Int // a.k.a. maxFeePerGas
3333
Gas uint64
34-
To *common.Address `rlp:"nil"` // nil means contract creation
34+
To common.Address
3535
Value *uint256.Int
3636
Data []byte
3737
AccessList AccessList
@@ -48,7 +48,7 @@ type BlobTx struct {
4848
func (tx *BlobTx) copy() TxData {
4949
cpy := &BlobTx{
5050
Nonce: tx.Nonce,
51-
To: copyAddressPtr(tx.To),
51+
To: tx.To,
5252
Data: common.CopyBytes(tx.Data),
5353
Gas: tx.Gas,
5454
// These are copied below.
@@ -104,7 +104,7 @@ func (tx *BlobTx) gasTipCap() *big.Int { return tx.GasTipCap.ToBig() }
104104
func (tx *BlobTx) gasPrice() *big.Int { return tx.GasFeeCap.ToBig() }
105105
func (tx *BlobTx) value() *big.Int { return tx.Value.ToBig() }
106106
func (tx *BlobTx) nonce() uint64 { return tx.Nonce }
107-
func (tx *BlobTx) to() *common.Address { return tx.To }
107+
func (tx *BlobTx) to() *common.Address { tmp := tx.To; return &tmp }
108108
func (tx *BlobTx) blobGas() uint64 { return params.BlobTxDataGasPerBlob * uint64(len(tx.BlobHashes)) }
109109
func (tx *BlobTx) blobGasFeeCap() *big.Int { return tx.BlobFeeCap.ToBig() }
110110
func (tx *BlobTx) blobHashes() []common.Hash { return tx.BlobHashes }

eth/downloader/queue.go

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -806,9 +806,6 @@ func (q *queue) DeliverBodies(id string, txLists [][]*types.Transaction, txListH
806806

807807
// Validate the data blobs individually too
808808
if tx.Type() == types.BlobTxType {
809-
if tx.To() == nil {
810-
return errInvalidBody // TODO(karalabe): Why not make the field non-nil-able
811-
}
812809
if len(tx.BlobHashes()) == 0 {
813810
return errInvalidBody
814811
}

0 commit comments

Comments
 (0)