Skip to content

Commit

Permalink
consensus/misc: fix weird check due to misintepreted field
Browse files Browse the repository at this point in the history
  • Loading branch information
karalabe committed May 30, 2023
1 parent 94a3d59 commit 463e629
Showing 1 changed file with 8 additions and 19 deletions.
27 changes: 8 additions & 19 deletions consensus/misc/eip4844.go
Expand Up @@ -41,6 +41,14 @@ func VerifyEIP4844Header(parent, header *types.Header) error {
if header.DataGasUsed == nil {
return errors.New("header is missing dataGasUsed")
}
// Verify that the data gas used remains within reasonable limits.
if *header.DataGasUsed > params.BlobTxMaxDataGasPerBlock {
return fmt.Errorf("data gas used %d exceeds maximum allowance %d", *header.DataGasUsed, params.BlobTxMaxDataGasPerBlock)
}
if *header.DataGasUsed%params.BlobTxDataGasPerBlob != 0 {
return fmt.Errorf("data gas used %d not a multiple of data gas per blob %d", header.DataGasUsed, params.BlobTxDataGasPerBlob)
}
// Verify the excessDataGas is correct based on the parent header
var (
parentExcessDataGas uint64
parentDataGasUsed uint64
Expand All @@ -49,25 +57,6 @@ func VerifyEIP4844Header(parent, header *types.Header) error {
parentExcessDataGas = *parent.ExcessDataGas
parentDataGasUsed = *parent.DataGasUsed
}
// Verify that the data gas limit remains within allowed bounds. To check
// the **actual** real usage we need to block body (transaction list), but
// at least do some sanity checks as early as possible.
if parentDataGasUsed > *header.DataGasUsed {
if shrinkage := parentDataGasUsed - *header.DataGasUsed; shrinkage > params.BlobTxTargetDataGasPerBlock {
return fmt.Errorf("data gas used exceeds maximum shrinkage: have %d, parent %d, max shrinkage %d, actual shrinkage %d",
header.DataGasUsed, parentDataGasUsed, params.BlobTxTargetDataGasPerBlock, shrinkage)
} else if shrinkage%params.BlobTxDataGasPerBlob != 0 {
return fmt.Errorf("data gas shrinkage %d not a multiple of data gas per blob %d", shrinkage, params.BlobTxDataGasPerBlob)
}
} else {
if growth := *header.DataGasUsed - parentDataGasUsed; growth > params.BlobTxTargetDataGasPerBlock {
return fmt.Errorf("data gas used exceeds maximum growth: have %d, parent %d, max shtingage %d, actual growth %d",
header.DataGasUsed, parentDataGasUsed, params.BlobTxTargetDataGasPerBlock, growth)
} else if growth%params.BlobTxDataGasPerBlob != 0 {
return fmt.Errorf("data gas growth %d not a multiple of data gas per blob %d", growth, params.BlobTxDataGasPerBlob)
}
}
// Verify the excessDataGas is correct based on the parent header
expectedExcessDataGas := CalcExcessDataGas(parentExcessDataGas, parentDataGasUsed)
if *header.ExcessDataGas != expectedExcessDataGas {
return fmt.Errorf("invalid excessDataGas: have %d, want %d, parent excessDataGas %d, parent blobDataUsed %d",
Expand Down

0 comments on commit 463e629

Please sign in to comment.