revmc_statetest/btest/
pre_block.rs1use revm_context::{Block, ContextTr};
4use revm_database::Database;
5use revm_database_interface::DatabaseCommit;
6use revm_handler::{EvmTr, SystemCallCommitEvm};
7use revm_primitives::{Address, B256, address, hardfork::SpecId};
8
9pub fn pre_block_transition<
15 'a,
16 DB: Database + DatabaseCommit + 'a,
17 EVM: SystemCallCommitEvm<Error: core::fmt::Debug> + EvmTr<Context: ContextTr<Db = DB>>,
18>(
19 evm: &mut EVM,
20 spec: SpecId,
21 parent_block_hash: Option<B256>,
22 parent_beacon_block_root: Option<B256>,
23) -> Result<(), EVM::Error> {
24 if evm.ctx().block().number() == 0 {
26 return Ok(());
27 }
28
29 if let Some(parent_block_hash) = parent_block_hash {
31 if spec.is_enabled_in(SpecId::PRAGUE) {
32 system_call_eip2935_blockhash(evm, parent_block_hash)?;
33 }
34 }
35
36 if let Some(parent_beacon_block_root) = parent_beacon_block_root {
37 if spec.is_enabled_in(SpecId::CANCUN) {
38 system_call_eip4788_beacon_root(evm, parent_beacon_block_root)?;
39 }
40 }
41
42 Ok(())
43}
44
45pub const HISTORY_STORAGE_ADDRESS: Address = address!("0x0000F90827F1C53a10cb7A02335B175320002935");
46
47#[inline]
49pub(crate) fn system_call_eip2935_blockhash<EVM>(
50 evm: &mut EVM,
51 parent_block_hash: B256,
52) -> Result<(), EVM::Error>
53where
54 EVM: SystemCallCommitEvm<Error: core::fmt::Debug>,
55{
56 evm.system_call_commit(HISTORY_STORAGE_ADDRESS, parent_block_hash.0.into())?;
57 Ok(())
58}
59
60pub const BEACON_ROOTS_ADDRESS: Address = address!("000F3df6D732807Ef1319fB7B8bB8522d0Beac02");
61
62pub(crate) fn system_call_eip4788_beacon_root<EVM>(
64 evm: &mut EVM,
65 parent_beacon_block_root: B256,
66) -> Result<(), EVM::Error>
67where
68 EVM: SystemCallCommitEvm<Error: core::fmt::Debug>,
69{
70 evm.system_call_commit(BEACON_ROOTS_ADDRESS, parent_beacon_block_root.0.into())?;
71 Ok(())
72}