Skip to content

Commit 942ea19

Browse files
lightclientqianhh
authored andcommitted
consensus/misc/eip4844: use head's target blobs, not parent (#31101)
A clarification was made to EIP-7691 stating that at the fork boundary it is required to use the target blob count associated with the head block, rather than the parent as implemented here. See for more: ethereum/EIPs#9249
1 parent 0d4c026 commit 942ea19

File tree

9 files changed

+16
-12
lines changed

9 files changed

+16
-12
lines changed

cmd/evm/internal/t8ntool/execution.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,11 +196,11 @@ func (pre *Prestate) Apply(vmConfig vm.Config, chainConfig *params.ChainConfig,
196196
ExcessBlobGas: pre.Env.ParentExcessBlobGas,
197197
BlobGasUsed: pre.Env.ParentBlobGasUsed,
198198
}
199-
excessBlobGas = eip4844.CalcExcessBlobGas(chainConfig, parent)
200199
header := &types.Header{
201200
Time: pre.Env.Timestamp,
202201
ExcessBlobGas: &excessBlobGas,
203202
}
203+
excessBlobGas = eip4844.CalcExcessBlobGas(chainConfig, parent, header)
204204
vmContext.BlobBaseFee = eip4844.CalcBlobFee(chainConfig, header)
205205
}
206206
}

consensus/misc/eip4844/eip4844.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ func VerifyEIP4844Header(config *params.ChainConfig, parent, header *types.Heade
5050
return fmt.Errorf("blob gas used %d not a multiple of blob gas per blob %d", header.BlobGasUsed, params.BlobTxBlobGasPerBlob)
5151
}
5252
// Verify the excessBlobGas is correct based on the parent header
53-
expectedExcessBlobGas := CalcExcessBlobGas(config, parent)
53+
expectedExcessBlobGas := CalcExcessBlobGas(config, parent, header)
5454
if *header.ExcessBlobGas != expectedExcessBlobGas {
5555
return fmt.Errorf("invalid excessBlobGas: have %d, want %d", *header.ExcessBlobGas, expectedExcessBlobGas)
5656
}
@@ -59,9 +59,9 @@ func VerifyEIP4844Header(config *params.ChainConfig, parent, header *types.Heade
5959

6060
// CalcExcessBlobGas calculates the excess blob gas after applying the set of
6161
// blobs on top of the excess blob gas.
62-
func CalcExcessBlobGas(config *params.ChainConfig, parent *types.Header) uint64 {
62+
func CalcExcessBlobGas(config *params.ChainConfig, parent, header *types.Header) uint64 {
6363
var (
64-
targetGas = uint64(targetBlobsPerBlock(config, parent.Time)) * params.BlobTxBlobGasPerBlob
64+
targetGas = uint64(targetBlobsPerBlock(config, header.Time)) * params.BlobTxBlobGasPerBlob
6565
parentExcessBlobGas uint64
6666
parentBlobGasUsed uint64
6767
)

consensus/misc/eip4844/eip4844_test.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,12 +57,15 @@ func TestCalcExcessBlobGas(t *testing.T) {
5757
}
5858
for i, tt := range tests {
5959
blobGasUsed := uint64(tt.blobs) * params.BlobTxBlobGasPerBlob
60+
head := &types.Header{
61+
Time: *config.CancunTime,
62+
}
6063
parent := &types.Header{
6164
Time: *config.CancunTime,
6265
ExcessBlobGas: &tt.excess,
6366
BlobGasUsed: &blobGasUsed,
6467
}
65-
result := CalcExcessBlobGas(config, parent)
68+
result := CalcExcessBlobGas(config, parent, head)
6669
if result != tt.want {
6770
t.Errorf("test %d: excess blob gas mismatch: have %v, want %v", i, result, tt.want)
6871
}

core/chain_makers.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -600,7 +600,7 @@ func (cm *chainMaker) makeHeader(parent *types.Block, state *state.StateDB, engi
600600
}
601601
}
602602
if cm.config.IsCancun(header.Number, header.Time) {
603-
excessBlobGas := eip4844.CalcExcessBlobGas(cm.config, parent.Header())
603+
excessBlobGas := eip4844.CalcExcessBlobGas(cm.config, parent.Header(), header)
604604
header.ExcessBlobGas = &excessBlobGas
605605
header.BlobGasUsed = new(uint64)
606606
header.ParentBeaconRoot = new(common.Hash)

core/state_processor_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -407,7 +407,7 @@ func GenerateBadBlock(parent *types.Block, engine consensus.Engine, txs types.Tr
407407
}
408408
header.Root = common.BytesToHash(hasher.Sum(nil))
409409
if config.IsCancun(header.Number, header.Time) {
410-
excess := eip4844.CalcExcessBlobGas(config, parent.Header())
410+
excess := eip4844.CalcExcessBlobGas(config, parent.Header(), header)
411411
used := uint64(nBlobs * params.BlobTxBlobGasPerBlob)
412412
header.ExcessBlobGas = &excess
413413
header.BlobGasUsed = &used

eth/gasprice/feehistory.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ func (oracle *Oracle) processBlock(ctx context.Context, bf *blockFees, percentil
102102
// Fill in blob base fee and next blob base fee.
103103
if excessBlobGas := bf.header.ExcessBlobGas; excessBlobGas != nil {
104104
bf.results.blobBaseFee = eip4844.CalcBlobFee(config, bf.header)
105-
excess := eip4844.CalcExcessBlobGas(config, bf.header)
105+
excess := eip4844.CalcExcessBlobGas(config, bf.header, bf.header)
106106
next := &types.Header{Number: bf.header.Number, Time: bf.header.Time, ExcessBlobGas: &excess}
107107
bf.results.nextBlobBaseFee = eip4844.CalcBlobFee(config, next)
108108
} else {

eth/tracers/internal/tracetest/util.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,9 @@ func (c *callContext) toBlockContext(genesis *core.Genesis) vm.BlockContext {
5454
}
5555

5656
if genesis.ExcessBlobGas != nil && genesis.BlobGasUsed != nil {
57-
excess := eip4844.CalcExcessBlobGas(genesis.Config, genesis.ToBlock().Header())
58-
header := &types.Header{ExcessBlobGas: &excess, Number: genesis.Config.LondonBlock, Time: *genesis.Config.CancunTime}
57+
header := &types.Header{Number: genesis.Config.LondonBlock, Time: *genesis.Config.CancunTime}
58+
excess := eip4844.CalcExcessBlobGas(genesis.Config, header, genesis.ToBlock().Header())
59+
header.ExcessBlobGas = &excess
5960
context.BlobBaseFee = eip4844.CalcBlobFee(genesis.Config, header)
6061
}
6162
return context

internal/ethapi/simulate.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ func (sim *simulator) processBlock(ctx context.Context, block *simBlock, header,
159159
if sim.chainConfig.IsCancun(header.Number, header.Time) {
160160
var excess uint64
161161
if sim.chainConfig.IsCancun(parent.Number, parent.Time) {
162-
excess = eip4844.CalcExcessBlobGas(sim.chainConfig, parent)
162+
excess = eip4844.CalcExcessBlobGas(sim.chainConfig, parent, header)
163163
}
164164
header.ExcessBlobGas = &excess
165165
}

miner/worker.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1012,7 +1012,7 @@ func (w *worker) prepareWork(genParams *generateParams, witness bool) (*environm
10121012
if w.chainConfig.IsCancun(header.Number, header.Time) {
10131013
var excessBlobGas uint64
10141014
if w.chainConfig.IsCancun(parent.Number, parent.Time) {
1015-
excessBlobGas = eip4844.CalcExcessBlobGas(w.chainConfig, parent)
1015+
excessBlobGas = eip4844.CalcExcessBlobGas(w.chainConfig, parent, header)
10161016
}
10171017
header.BlobGasUsed = new(uint64)
10181018
header.ExcessBlobGas = &excessBlobGas

0 commit comments

Comments
 (0)