From 463e6296fdc6d58aff6776ceb664a25370bddf99 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?P=C3=A9ter=20Szil=C3=A1gyi?= Date: Tue, 30 May 2023 10:49:55 +0300 Subject: [PATCH] consensus/misc: fix weird check due to misintepreted field --- consensus/misc/eip4844.go | 27 ++++++++------------------- 1 file changed, 8 insertions(+), 19 deletions(-) diff --git a/consensus/misc/eip4844.go b/consensus/misc/eip4844.go index 3e507ebf9d0e3..f370e490176ac 100644 --- a/consensus/misc/eip4844.go +++ b/consensus/misc/eip4844.go @@ -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 @@ -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",