Skip to content

Commit 2272bc0

Browse files
fix(osaka): EIP-7918 blob excess_gas calculation (#1237)
Co-authored-by: Wodann <Wodann@users.noreply.github.com>
1 parent bbc09f3 commit 2272bc0

File tree

4 files changed

+54
-27
lines changed

4 files changed

+54
-27
lines changed

.changeset/open-lines-jump.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@nomicfoundation/edr": patch
3+
---
4+
5+
Fixed `excess_blob_gas` calculation after Osaka

crates/block/header/src/lib.rs

Lines changed: 37 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -412,34 +412,44 @@ impl PartialHeader {
412412
}),
413413
blob_gas: overrides.blob_gas.or_else(|| {
414414
if evm_spec_id >= EvmSpecId::CANCUN {
415-
let excess_gas = parent.and_then(|parent| parent.blob_gas.as_ref()).map_or(
416-
// For the first (post-fork) block, both parent.blob_gas_used and
417-
// parent.excess_blob_gas are evaluated as 0.
415+
let excess_gas = parent.map_or(
416+
// For the first block, both `blob_gas_used` and `excess_blob_gas` are
417+
// evaluated as 0.
418418
0,
419-
|BlobGas {
420-
gas_used,
421-
excess_gas,
422-
}| {
423-
let blob_params = blob_params_for_hardfork(
424-
evm_spec_id,
425-
timestamp,
426-
scheduled_blob_params.as_ref(),
427-
);
428-
429-
let base_fee = if evm_spec_id >= EvmSpecId::OSAKA {
430-
base_fee.expect("base fee must be set for post-Osaka blocks")
431-
} else {
432-
// In pre-Osaka (EIP-4844) scenarios, the base fee parameter is not
433-
// used in excess blob gas calculation. Passing 0 is acceptable here
434-
// because `next_block_excess_blob_gas_osaka` ignores the base fee
435-
// value for these hardforks.
436-
0
437-
};
438-
439-
blob_params.next_block_excess_blob_gas_osaka(
440-
*excess_gas,
441-
*gas_used,
442-
base_fee.try_into().expect("base fee is too large"),
419+
|parent| {
420+
parent.blob_gas.as_ref().map_or(
421+
// For the first post-fork block, both `blob_gas_used` and
422+
// `excess_blob_gas` are evaluated as 0.
423+
0,
424+
|BlobGas {
425+
gas_used,
426+
excess_gas,
427+
}| {
428+
let blob_params = blob_params_for_hardfork(
429+
evm_spec_id,
430+
timestamp,
431+
scheduled_blob_params.as_ref(),
432+
);
433+
434+
let base_fee = if evm_spec_id >= EvmSpecId::OSAKA {
435+
parent
436+
.base_fee_per_gas
437+
.expect("base fee must be set for post-Osaka blocks")
438+
} else {
439+
// In pre-Osaka (EIP-4844) scenarios, the base fee parameter
440+
// is not used in excess blob gas calculation. Passing 0 is
441+
// acceptable here because
442+
// `next_block_excess_blob_gas_osaka` ignores the base fee
443+
// value for these hardforks.
444+
0
445+
};
446+
447+
blob_params.next_block_excess_blob_gas_osaka(
448+
*excess_gas,
449+
*gas_used,
450+
base_fee.try_into().expect("base fee is too large"),
451+
)
452+
},
443453
)
444454
},
445455
);

crates/edr_provider/src/data.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4295,6 +4295,12 @@ mod tests {
42954295
url: get_alchemy_url(),
42964296
header_overrides_constructor: l1_header_overrides,
42974297
},
4298+
mainnet_blob_excess_gas_calculation_issue => L1ChainSpec {
4299+
block_number: 24_035_797,
4300+
url: get_alchemy_url(),
4301+
header_overrides_constructor: l1_header_overrides,
4302+
},
4303+
42984304
}
42994305
}
43004306
}

crates/test/block_replay/src/lib.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -352,6 +352,12 @@ pub async fn run_full_block<
352352
.expect("transaction index is valid")
353353
);
354354
}
355+
debug_assert_eq!(
356+
expected_block.block_hash(),
357+
mined_block.block.block_hash(),
358+
"{:?}",
359+
"Block hashes differ"
360+
);
355361

356362
assert_eq!(replay_header, mined_header);
357363

0 commit comments

Comments
 (0)