fix(validation): enforce at least one tx post-prague1 (#40)

This commit is contained in:
Cal Bera 2025-07-30 10:03:32 -07:00 committed by GitHub
parent 77bab9e10f
commit 34be2e0985
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -69,7 +69,8 @@ func (v *BlockValidator) ValidateBody(block *types.Block) error {
if hash := types.CalcUncleHash(block.Uncles()); hash != header.UncleHash {
return fmt.Errorf("uncle root hash mismatch (header value %x, calculated %x)", header.UncleHash, hash)
}
if hash := types.DeriveSha(block.Transactions(), trie.NewStackTrie(nil)); hash != header.TxHash {
txs := block.Transactions()
if hash := types.DeriveSha(txs, trie.NewStackTrie(nil)); hash != header.TxHash {
return fmt.Errorf("transaction root hash mismatch (header value %x, calculated %x)", header.TxHash, hash)
}
@ -92,7 +93,6 @@ func (v *BlockValidator) ValidateBody(block *types.Block) error {
var expectedPoLHash common.Hash
if isPrague1 {
if block.ProposerPubkey() == nil {
// TODO: does this need to enforce the proposer pubkey is the exact value we expect?
return errors.New("post-prague1 block missing parent proposer pubkey")
}
@ -108,11 +108,16 @@ func (v *BlockValidator) ValidateBody(block *types.Block) error {
return fmt.Errorf("failed to create expected PoL tx: %w", err)
}
expectedPoLHash = polTx.Hash()
// Validate that the block has at least one tx.
if len(txs) == 0 {
return errors.New("post-prague1 block missing PoL tx")
}
}
// Blob transactions may be present after the Cancun fork.
var blobs int
for i, tx := range block.Transactions() {
for i, tx := range txs {
// Berachain: validate the PoL tx is only the first tx in the block.
switch {
case isPrague1 && i == 0: