core, eth/downloader: make body validation more strict (#26704)
This commit is contained in:
parent
08bf8a60c3
commit
645e3e86c4
@ -76,6 +76,9 @@ func (v *BlockValidator) ValidateBody(block *types.Block) error {
|
|||||||
if hash := types.DeriveSha(block.Withdrawals(), trie.NewStackTrie(nil)); hash != *header.WithdrawalsHash {
|
if hash := types.DeriveSha(block.Withdrawals(), trie.NewStackTrie(nil)); hash != *header.WithdrawalsHash {
|
||||||
return fmt.Errorf("withdrawals root hash mismatch (header value %x, calculated %x)", *header.WithdrawalsHash, hash)
|
return fmt.Errorf("withdrawals root hash mismatch (header value %x, calculated %x)", *header.WithdrawalsHash, hash)
|
||||||
}
|
}
|
||||||
|
} else if block.Withdrawals() != nil {
|
||||||
|
// Withdrawals are not allowed prior to shanghai fork
|
||||||
|
return fmt.Errorf("withdrawals present in block body")
|
||||||
}
|
}
|
||||||
|
|
||||||
if !v.bc.HasBlockAndState(block.ParentHash(), block.NumberU64()-1) {
|
if !v.bc.HasBlockAndState(block.ParentHash(), block.NumberU64()-1) {
|
||||||
|
@ -781,15 +781,18 @@ func (q *queue) DeliverBodies(id string, txLists [][]*types.Transaction, txListH
|
|||||||
return errInvalidBody
|
return errInvalidBody
|
||||||
}
|
}
|
||||||
if header.WithdrawalsHash == nil {
|
if header.WithdrawalsHash == nil {
|
||||||
// discard any withdrawals if we don't have a withdrawal hash set
|
// nil hash means there withdrawals should not be present in body
|
||||||
withdrawalLists[index] = nil
|
if withdrawalLists[index] != nil {
|
||||||
} else if *header.WithdrawalsHash == types.EmptyRootHash && withdrawalLists[index] == nil {
|
|
||||||
// if the withdrawal hash is the emptyRootHash,
|
|
||||||
// we expect withdrawals to be [] instead of nil
|
|
||||||
withdrawalLists[index] = make([]*types.Withdrawal, 0)
|
|
||||||
} else if withdrawalListHashes[index] != *header.WithdrawalsHash {
|
|
||||||
return errInvalidBody
|
return errInvalidBody
|
||||||
}
|
}
|
||||||
|
} else { // non-nil hash: body must have withdrawals
|
||||||
|
if withdrawalLists[index] == nil {
|
||||||
|
return errInvalidBody
|
||||||
|
}
|
||||||
|
if withdrawalListHashes[index] != *header.WithdrawalsHash {
|
||||||
|
return errInvalidBody
|
||||||
|
}
|
||||||
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user