Skip to content

Commit

Permalink
core, eth/downloader: validate blobtx.To at serialization time
Browse files Browse the repository at this point in the history
  • Loading branch information
karalabe committed May 31, 2023
1 parent 495692c commit b0ebe94
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 11 deletions.
3 changes: 0 additions & 3 deletions core/block_validator.go
Expand Up @@ -89,9 +89,6 @@ 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")
}
Expand Down
5 changes: 3 additions & 2 deletions core/types/transaction_marshalling.go
Expand Up @@ -290,9 +290,10 @@ 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 {
itx.To = dec.To
if dec.To == nil {
return errors.New("missing required field 'to' in transaction")
}
itx.To = *dec.To
if dec.Gas == nil {
return errors.New("missing required field 'gas' for txdata")
}
Expand Down
6 changes: 3 additions & 3 deletions core/types/tx_blob.go
Expand Up @@ -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 `rlp:"nil"` // nil means contract creation
To common.Address
Value *uint256.Int
Data []byte
AccessList AccessList
Expand All @@ -48,7 +48,7 @@ type BlobTx struct {
func (tx *BlobTx) copy() TxData {
cpy := &BlobTx{
Nonce: tx.Nonce,
To: copyAddressPtr(tx.To),
To: tx.To,
Data: common.CopyBytes(tx.Data),
Gas: tx.Gas,
// These are copied below.
Expand Down Expand Up @@ -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 { return tx.To }
func (tx *BlobTx) to() *common.Address { tmp := tx.To; return &tmp }
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 }
Expand Down
3 changes: 0 additions & 3 deletions eth/downloader/queue.go
Expand Up @@ -806,9 +806,6 @@ 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
}
Expand Down

0 comments on commit b0ebe94

Please sign in to comment.