Skip to content

Commit 645e3e8

Browse files
authored
core, eth/downloader: make body validation more strict (#26704)
1 parent 08bf8a6 commit 645e3e8

File tree

2 files changed

+14
-8
lines changed

2 files changed

+14
-8
lines changed

core/block_validator.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,9 @@ func (v *BlockValidator) ValidateBody(block *types.Block) error {
7676
if hash := types.DeriveSha(block.Withdrawals(), trie.NewStackTrie(nil)); hash != *header.WithdrawalsHash {
7777
return fmt.Errorf("withdrawals root hash mismatch (header value %x, calculated %x)", *header.WithdrawalsHash, hash)
7878
}
79+
} else if block.Withdrawals() != nil {
80+
// Withdrawals are not allowed prior to shanghai fork
81+
return fmt.Errorf("withdrawals present in block body")
7982
}
8083

8184
if !v.bc.HasBlockAndState(block.ParentHash(), block.NumberU64()-1) {

eth/downloader/queue.go

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -781,14 +781,17 @@ func (q *queue) DeliverBodies(id string, txLists [][]*types.Transaction, txListH
781781
return errInvalidBody
782782
}
783783
if header.WithdrawalsHash == nil {
784-
// discard any withdrawals if we don't have a withdrawal hash set
785-
withdrawalLists[index] = nil
786-
} else if *header.WithdrawalsHash == types.EmptyRootHash && withdrawalLists[index] == nil {
787-
// if the withdrawal hash is the emptyRootHash,
788-
// we expect withdrawals to be [] instead of nil
789-
withdrawalLists[index] = make([]*types.Withdrawal, 0)
790-
} else if withdrawalListHashes[index] != *header.WithdrawalsHash {
791-
return errInvalidBody
784+
// nil hash means there withdrawals should not be present in body
785+
if withdrawalLists[index] != nil {
786+
return errInvalidBody
787+
}
788+
} else { // non-nil hash: body must have withdrawals
789+
if withdrawalLists[index] == nil {
790+
return errInvalidBody
791+
}
792+
if withdrawalListHashes[index] != *header.WithdrawalsHash {
793+
return errInvalidBody
794+
}
792795
}
793796
return nil
794797
}

0 commit comments

Comments
 (0)