Skip to content

Commit db97017

Browse files
authored
fix(evm): apply blob base fee block override (#356)
1 parent a8083c6 commit db97017

1 file changed

Lines changed: 29 additions & 0 deletions

File tree

crates/evm/src/overrides.rs

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ use alloy_rpc_types_eth::{
1212
use revm::{
1313
bytecode::BytecodeDecodeError,
1414
context::BlockEnv,
15+
context_interface::block::BlobExcessGasAndPrice,
1516
database::{CacheDB, State},
1617
state::{Account, AccountStatus, Bytecode, EvmStorageSlot},
1718
Database, DatabaseCommit,
@@ -77,6 +78,7 @@ where
7778
coinbase,
7879
random,
7980
base_fee,
81+
blob_base_fee,
8082
block_hash,
8183
..
8284
} = BlockOverrides { ..overrides };
@@ -107,6 +109,14 @@ where
107109
if let Some(base_fee) = base_fee {
108110
env.basefee = base_fee.saturating_to();
109111
}
112+
if let Some(blob_base_fee) = blob_base_fee {
113+
let excess_blob_gas =
114+
env.blob_excess_gas_and_price.map(|blob| blob.excess_blob_gas).unwrap_or_default();
115+
env.blob_excess_gas_and_price = Some(BlobExcessGasAndPrice {
116+
excess_blob_gas,
117+
blob_gasprice: blob_base_fee.saturating_to(),
118+
});
119+
}
110120
}
111121

112122
/// Applies the given state overrides (a set of [`AccountOverride`]) to the database.
@@ -214,6 +224,25 @@ mod tests {
214224
use alloy_primitives::{address, bytes};
215225
use revm::database::EmptyDB;
216226

227+
#[test]
228+
fn test_block_override_blob_base_fee() {
229+
let mut db = CacheDB::new(EmptyDB::new());
230+
let mut env = BlockEnv {
231+
blob_excess_gas_and_price: Some(BlobExcessGasAndPrice {
232+
excess_blob_gas: 42,
233+
blob_gasprice: 1,
234+
}),
235+
..Default::default()
236+
};
237+
238+
let overrides = BlockOverrides::default().with_blob_base_fee(U256::from(12345));
239+
apply_block_overrides(overrides, &mut db, &mut env);
240+
241+
let blob = env.blob_excess_gas_and_price.unwrap();
242+
assert_eq!(blob.excess_blob_gas, 42);
243+
assert_eq!(blob.blob_gasprice, 12345);
244+
}
245+
217246
#[test]
218247
fn test_state_override_state() {
219248
let code = bytes!(

0 commit comments

Comments
 (0)