mirror of
https://github.com/hl-archive-node/nanoreth.git
synced 2025-12-06 10:59:55 +00:00
feat: wire SystemCaller (#11321)
This commit is contained in:
@ -5,52 +5,11 @@ use alloy_eips::eip2935::HISTORY_STORAGE_ADDRESS;
|
||||
|
||||
use crate::ConfigureEvm;
|
||||
use alloy_primitives::B256;
|
||||
use core::fmt::Display;
|
||||
use reth_chainspec::EthereumHardforks;
|
||||
use reth_execution_errors::{BlockExecutionError, BlockValidationError};
|
||||
use reth_primitives::Header;
|
||||
use revm::{interpreter::Host, Database, DatabaseCommit, Evm};
|
||||
use revm_primitives::{BlockEnv, CfgEnvWithHandlerCfg, EnvWithHandlerCfg, ResultAndState};
|
||||
|
||||
/// Apply the [EIP-2935](https://eips.ethereum.org/EIPS/eip-2935) pre block contract call.
|
||||
///
|
||||
/// This constructs a new [`Evm`] with the given database and environment ([`CfgEnvWithHandlerCfg`]
|
||||
/// and [`BlockEnv`]) to execute the pre block contract call.
|
||||
///
|
||||
/// This uses [`apply_blockhashes_contract_call`] to ultimately apply the
|
||||
/// blockhash contract state change.
|
||||
pub fn pre_block_blockhashes_contract_call<EvmConfig, DB>(
|
||||
db: &mut DB,
|
||||
evm_config: &EvmConfig,
|
||||
chain_spec: impl EthereumHardforks,
|
||||
initialized_cfg: &CfgEnvWithHandlerCfg,
|
||||
initialized_block_env: &BlockEnv,
|
||||
parent_block_hash: B256,
|
||||
) -> Result<(), BlockExecutionError>
|
||||
where
|
||||
DB: Database + DatabaseCommit,
|
||||
DB::Error: Display,
|
||||
EvmConfig: ConfigureEvm<Header = Header>,
|
||||
{
|
||||
// Apply the pre-block EIP-2935 contract call
|
||||
let mut evm_pre_block = Evm::builder()
|
||||
.with_db(db)
|
||||
.with_env_with_handler_cfg(EnvWithHandlerCfg::new_with_cfg_env(
|
||||
initialized_cfg.clone(),
|
||||
initialized_block_env.clone(),
|
||||
Default::default(),
|
||||
))
|
||||
.build();
|
||||
|
||||
apply_blockhashes_contract_call(
|
||||
evm_config,
|
||||
chain_spec,
|
||||
initialized_block_env.timestamp.to(),
|
||||
initialized_block_env.number.to(),
|
||||
parent_block_hash,
|
||||
&mut evm_pre_block,
|
||||
)
|
||||
}
|
||||
use revm::{interpreter::Host, Database, Evm};
|
||||
use revm_primitives::ResultAndState;
|
||||
|
||||
/// Applies the pre-block call to the [EIP-2935] blockhashes contract, using the given block,
|
||||
/// chain specification, and EVM.
|
||||
@ -65,7 +24,7 @@ where
|
||||
///
|
||||
/// [EIP-2935]: https://eips.ethereum.org/EIPS/eip-2935
|
||||
#[inline]
|
||||
pub fn transact_blockhashes_contract_call<EvmConfig, EXT, DB>(
|
||||
pub(crate) fn transact_blockhashes_contract_call<EvmConfig, EXT, DB>(
|
||||
evm_config: &EvmConfig,
|
||||
chain_spec: impl EthereumHardforks,
|
||||
block_timestamp: u64,
|
||||
@ -115,38 +74,3 @@ where
|
||||
|
||||
Ok(Some(res))
|
||||
}
|
||||
|
||||
/// Applies the pre-block call to the [EIP-2935] blockhashes contract, using the given block,
|
||||
/// chain specification, and EVM and commits the relevant state changes.
|
||||
///
|
||||
/// If Prague is not activated, or the block is the genesis block, then this is a no-op, and no
|
||||
/// state changes are made.
|
||||
///
|
||||
/// [EIP-2935]: https://eips.ethereum.org/EIPS/eip-2935
|
||||
#[inline]
|
||||
pub fn apply_blockhashes_contract_call<EvmConfig, EXT, DB>(
|
||||
evm_config: &EvmConfig,
|
||||
chain_spec: impl EthereumHardforks,
|
||||
block_timestamp: u64,
|
||||
block_number: u64,
|
||||
parent_block_hash: B256,
|
||||
evm: &mut Evm<'_, EXT, DB>,
|
||||
) -> Result<(), BlockExecutionError>
|
||||
where
|
||||
DB: Database + DatabaseCommit,
|
||||
DB::Error: core::fmt::Display,
|
||||
EvmConfig: ConfigureEvm<Header = Header>,
|
||||
{
|
||||
if let Some(res) = transact_blockhashes_contract_call(
|
||||
evm_config,
|
||||
chain_spec,
|
||||
block_timestamp,
|
||||
block_number,
|
||||
parent_block_hash,
|
||||
evm,
|
||||
)? {
|
||||
evm.context.evm.db.commit(res.state);
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@ -7,49 +7,8 @@ use alloy_primitives::B256;
|
||||
use reth_chainspec::EthereumHardforks;
|
||||
use reth_execution_errors::{BlockExecutionError, BlockValidationError};
|
||||
use reth_primitives::Header;
|
||||
use revm::{interpreter::Host, Database, DatabaseCommit, Evm};
|
||||
use revm_primitives::{BlockEnv, CfgEnvWithHandlerCfg, EnvWithHandlerCfg, ResultAndState};
|
||||
|
||||
/// Apply the [EIP-4788](https://eips.ethereum.org/EIPS/eip-4788) pre block contract call.
|
||||
///
|
||||
/// This constructs a new [`Evm`] with the given DB, and environment
|
||||
/// ([`CfgEnvWithHandlerCfg`] and [`BlockEnv`]) to execute the pre block contract call.
|
||||
///
|
||||
/// This uses [`apply_beacon_root_contract_call`] to ultimately apply the beacon root contract state
|
||||
/// change.
|
||||
pub fn pre_block_beacon_root_contract_call<EvmConfig, DB>(
|
||||
db: &mut DB,
|
||||
evm_config: &EvmConfig,
|
||||
chain_spec: impl EthereumHardforks,
|
||||
initialized_cfg: &CfgEnvWithHandlerCfg,
|
||||
initialized_block_env: &BlockEnv,
|
||||
parent_beacon_block_root: Option<B256>,
|
||||
) -> Result<(), BlockExecutionError>
|
||||
where
|
||||
DB: Database + DatabaseCommit,
|
||||
DB::Error: core::fmt::Display,
|
||||
EvmConfig: ConfigureEvm<Header = Header>,
|
||||
{
|
||||
// apply pre-block EIP-4788 contract call
|
||||
let mut evm_pre_block = Evm::builder()
|
||||
.with_db(db)
|
||||
.with_env_with_handler_cfg(EnvWithHandlerCfg::new_with_cfg_env(
|
||||
initialized_cfg.clone(),
|
||||
initialized_block_env.clone(),
|
||||
Default::default(),
|
||||
))
|
||||
.build();
|
||||
|
||||
// initialize a block from the env, because the pre block call needs the block itself
|
||||
apply_beacon_root_contract_call(
|
||||
evm_config,
|
||||
chain_spec,
|
||||
initialized_block_env.timestamp.to(),
|
||||
initialized_block_env.number.to(),
|
||||
parent_beacon_block_root,
|
||||
&mut evm_pre_block,
|
||||
)
|
||||
}
|
||||
use revm::{interpreter::Host, Database, Evm};
|
||||
use revm_primitives::ResultAndState;
|
||||
|
||||
/// Applies the pre-block call to the [EIP-4788] beacon block root contract, using the given block,
|
||||
/// chain spec, EVM.
|
||||
@ -61,7 +20,7 @@ where
|
||||
///
|
||||
/// [EIP-4788]: https://eips.ethereum.org/EIPS/eip-4788
|
||||
#[inline]
|
||||
pub fn transact_beacon_root_contract_call<EvmConfig, EXT, DB, Spec>(
|
||||
pub(crate) fn transact_beacon_root_contract_call<EvmConfig, EXT, DB, Spec>(
|
||||
evm_config: &EvmConfig,
|
||||
chain_spec: &Spec,
|
||||
block_timestamp: u64,
|
||||
@ -125,38 +84,3 @@ where
|
||||
|
||||
Ok(Some(res))
|
||||
}
|
||||
|
||||
/// Applies the pre-block call to the [EIP-4788] beacon block root contract, using the given block,
|
||||
/// chain spec, EVM.
|
||||
///
|
||||
/// If Cancun is not activated or the block is the genesis block, then this is a no-op, and no
|
||||
/// state changes are made.
|
||||
///
|
||||
/// [EIP-4788]: https://eips.ethereum.org/EIPS/eip-4788
|
||||
#[inline]
|
||||
pub fn apply_beacon_root_contract_call<EvmConfig, EXT, DB>(
|
||||
evm_config: &EvmConfig,
|
||||
chain_spec: impl EthereumHardforks,
|
||||
block_timestamp: u64,
|
||||
block_number: u64,
|
||||
parent_beacon_block_root: Option<B256>,
|
||||
evm: &mut Evm<'_, EXT, DB>,
|
||||
) -> Result<(), BlockExecutionError>
|
||||
where
|
||||
DB: Database + DatabaseCommit,
|
||||
DB::Error: core::fmt::Display,
|
||||
EvmConfig: ConfigureEvm<Header = Header>,
|
||||
{
|
||||
if let Some(res) = transact_beacon_root_contract_call(
|
||||
evm_config,
|
||||
&chain_spec,
|
||||
block_timestamp,
|
||||
block_number,
|
||||
parent_beacon_block_root,
|
||||
evm,
|
||||
)? {
|
||||
evm.context.evm.db.commit(res.state);
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@ -1,48 +1,12 @@
|
||||
//! [EIP-7002](https://eips.ethereum.org/EIPS/eip-7002) system call implementation.
|
||||
use alloc::{boxed::Box, format, string::ToString, vec::Vec};
|
||||
use core::fmt::Display;
|
||||
|
||||
use crate::ConfigureEvm;
|
||||
use alloc::{boxed::Box, format, string::ToString, vec::Vec};
|
||||
use alloy_eips::eip7002::{WithdrawalRequest, WITHDRAWAL_REQUEST_PREDEPLOY_ADDRESS};
|
||||
use alloy_primitives::{bytes::Buf, Address, Bytes, FixedBytes};
|
||||
use reth_execution_errors::{BlockExecutionError, BlockValidationError};
|
||||
use reth_primitives::{Header, Request};
|
||||
use revm::{interpreter::Host, Database, DatabaseCommit, Evm};
|
||||
use revm_primitives::{
|
||||
BlockEnv, CfgEnvWithHandlerCfg, EnvWithHandlerCfg, ExecutionResult, ResultAndState,
|
||||
};
|
||||
|
||||
/// Apply the [EIP-7002](https://eips.ethereum.org/EIPS/eip-7002) post block contract call.
|
||||
///
|
||||
/// This constructs a new [Evm] with the given DB, and environment
|
||||
/// ([`CfgEnvWithHandlerCfg`] and [`BlockEnv`]) to execute the post block contract call.
|
||||
///
|
||||
/// This uses [`apply_withdrawal_requests_contract_call`] to ultimately calculate the
|
||||
/// [requests](Request).
|
||||
pub fn post_block_withdrawal_requests_contract_call<EvmConfig, DB>(
|
||||
evm_config: &EvmConfig,
|
||||
db: &mut DB,
|
||||
initialized_cfg: &CfgEnvWithHandlerCfg,
|
||||
initialized_block_env: &BlockEnv,
|
||||
) -> Result<Vec<Request>, BlockExecutionError>
|
||||
where
|
||||
DB: Database + DatabaseCommit,
|
||||
DB::Error: Display,
|
||||
EvmConfig: ConfigureEvm<Header = Header>,
|
||||
{
|
||||
// apply post-block EIP-7002 contract call
|
||||
let mut evm_post_block = Evm::builder()
|
||||
.with_db(db)
|
||||
.with_env_with_handler_cfg(EnvWithHandlerCfg::new_with_cfg_env(
|
||||
initialized_cfg.clone(),
|
||||
initialized_block_env.clone(),
|
||||
Default::default(),
|
||||
))
|
||||
.build();
|
||||
|
||||
// initialize a block from the env, because the post block call needs the block itself
|
||||
apply_withdrawal_requests_contract_call(evm_config, &mut evm_post_block)
|
||||
}
|
||||
use revm::{interpreter::Host, Database, Evm};
|
||||
use revm_primitives::{ExecutionResult, ResultAndState};
|
||||
|
||||
/// Applies the post-block call to the EIP-7002 withdrawal requests contract.
|
||||
///
|
||||
@ -50,7 +14,7 @@ where
|
||||
///
|
||||
/// Note: this does not commit the state changes to the database, it only transact the call.
|
||||
#[inline]
|
||||
pub fn transact_withdrawal_requests_contract_call<EvmConfig, EXT, DB>(
|
||||
pub(crate) fn transact_withdrawal_requests_contract_call<EvmConfig, EXT, DB>(
|
||||
evm_config: &EvmConfig,
|
||||
evm: &mut Evm<'_, EXT, DB>,
|
||||
) -> Result<ResultAndState, BlockExecutionError>
|
||||
@ -98,29 +62,6 @@ where
|
||||
Ok(res)
|
||||
}
|
||||
|
||||
/// Applies the post-block call to the EIP-7002 withdrawal requests contract.
|
||||
///
|
||||
/// If Prague is not active at the given timestamp, then this is a no-op, and an empty vector is
|
||||
/// returned. Otherwise, the withdrawal requests are returned.
|
||||
#[inline]
|
||||
pub fn apply_withdrawal_requests_contract_call<EvmConfig, EXT, DB>(
|
||||
evm_config: &EvmConfig,
|
||||
evm: &mut Evm<'_, EXT, DB>,
|
||||
) -> Result<Vec<Request>, BlockExecutionError>
|
||||
where
|
||||
DB: Database + DatabaseCommit,
|
||||
DB::Error: core::fmt::Display,
|
||||
EvmConfig: ConfigureEvm<Header = Header>,
|
||||
{
|
||||
let ResultAndState { result, state } =
|
||||
transact_withdrawal_requests_contract_call(evm_config, evm)?;
|
||||
|
||||
// commit the state
|
||||
evm.context.evm.db.commit(state);
|
||||
|
||||
post_commit(result)
|
||||
}
|
||||
|
||||
/// Parses the withdrawal requests from the execution output.
|
||||
#[inline]
|
||||
pub(crate) fn post_commit(result: ExecutionResult) -> Result<Vec<Request>, BlockExecutionError> {
|
||||
|
||||
@ -1,48 +1,12 @@
|
||||
//! [EIP-7251](https://eips.ethereum.org/EIPS/eip-7251) system call implementation.
|
||||
use alloc::{boxed::Box, format, string::ToString, vec::Vec};
|
||||
use core::fmt::Display;
|
||||
|
||||
use crate::ConfigureEvm;
|
||||
use alloc::{boxed::Box, format, string::ToString, vec::Vec};
|
||||
use alloy_eips::eip7251::{ConsolidationRequest, CONSOLIDATION_REQUEST_PREDEPLOY_ADDRESS};
|
||||
use alloy_primitives::{bytes::Buf, Address, Bytes, FixedBytes};
|
||||
use reth_execution_errors::{BlockExecutionError, BlockValidationError};
|
||||
use reth_primitives::{Header, Request};
|
||||
use revm::{interpreter::Host, Database, DatabaseCommit, Evm};
|
||||
use revm_primitives::{
|
||||
BlockEnv, CfgEnvWithHandlerCfg, EnvWithHandlerCfg, ExecutionResult, ResultAndState,
|
||||
};
|
||||
|
||||
/// Apply the [EIP-7251](https://eips.ethereum.org/EIPS/eip-7251) post block contract call.
|
||||
///
|
||||
/// This constructs a new [Evm] with the given DB, and environment
|
||||
/// ([`CfgEnvWithHandlerCfg`] and [`BlockEnv`]) to execute the post block contract call.
|
||||
///
|
||||
/// This uses [`apply_consolidation_requests_contract_call`] to ultimately calculate the
|
||||
/// [requests](Request).
|
||||
pub fn post_block_consolidation_requests_contract_call<EvmConfig, DB>(
|
||||
evm_config: &EvmConfig,
|
||||
db: &mut DB,
|
||||
initialized_cfg: &CfgEnvWithHandlerCfg,
|
||||
initialized_block_env: &BlockEnv,
|
||||
) -> Result<Vec<Request>, BlockExecutionError>
|
||||
where
|
||||
DB: Database + DatabaseCommit,
|
||||
DB::Error: Display,
|
||||
EvmConfig: ConfigureEvm<Header = Header>,
|
||||
{
|
||||
// apply post-block EIP-7251 contract call
|
||||
let mut evm_post_block = Evm::builder()
|
||||
.with_db(db)
|
||||
.with_env_with_handler_cfg(EnvWithHandlerCfg::new_with_cfg_env(
|
||||
initialized_cfg.clone(),
|
||||
initialized_block_env.clone(),
|
||||
Default::default(),
|
||||
))
|
||||
.build();
|
||||
|
||||
// initialize a block from the env, because the post block call needs the block itself
|
||||
apply_consolidation_requests_contract_call(evm_config, &mut evm_post_block)
|
||||
}
|
||||
use revm::{interpreter::Host, Database, Evm};
|
||||
use revm_primitives::{ExecutionResult, ResultAndState};
|
||||
|
||||
/// Applies the post-block call to the EIP-7251 consolidation requests contract.
|
||||
///
|
||||
@ -51,7 +15,7 @@ where
|
||||
///
|
||||
/// Note: this does not commit the state changes to the database, it only transact the call.
|
||||
#[inline]
|
||||
pub fn transact_consolidation_requests_contract_call<EvmConfig, EXT, DB>(
|
||||
pub(crate) fn transact_consolidation_requests_contract_call<EvmConfig, EXT, DB>(
|
||||
evm_config: &EvmConfig,
|
||||
evm: &mut Evm<'_, EXT, DB>,
|
||||
) -> Result<ResultAndState, BlockExecutionError>
|
||||
@ -100,29 +64,6 @@ where
|
||||
Ok(res)
|
||||
}
|
||||
|
||||
/// Applies the post-block call to the EIP-7251 consolidation requests contract.
|
||||
///
|
||||
/// If Prague is not active at the given timestamp, then this is a no-op, and an empty vector is
|
||||
/// returned. Otherwise, the consolidation requests are returned.
|
||||
#[inline]
|
||||
pub fn apply_consolidation_requests_contract_call<EvmConfig, EXT, DB>(
|
||||
evm_config: &EvmConfig,
|
||||
evm: &mut Evm<'_, EXT, DB>,
|
||||
) -> Result<Vec<Request>, BlockExecutionError>
|
||||
where
|
||||
DB: Database + DatabaseCommit,
|
||||
DB::Error: core::fmt::Display,
|
||||
EvmConfig: ConfigureEvm<Header = Header>,
|
||||
{
|
||||
let ResultAndState { result, state } =
|
||||
transact_consolidation_requests_contract_call(evm_config, evm)?;
|
||||
|
||||
// commit the state
|
||||
evm.context.evm.db.commit(state);
|
||||
|
||||
post_commit(result)
|
||||
}
|
||||
|
||||
/// Parses the consolidation requests from the execution output.
|
||||
#[inline]
|
||||
pub(crate) fn post_commit(result: ExecutionResult) -> Result<Vec<Request>, BlockExecutionError> {
|
||||
|
||||
@ -10,16 +10,9 @@ use revm::{Database, DatabaseCommit, Evm};
|
||||
use revm_primitives::{BlockEnv, CfgEnvWithHandlerCfg, EnvWithHandlerCfg, ResultAndState, B256};
|
||||
|
||||
mod eip2935;
|
||||
pub use eip2935::*;
|
||||
|
||||
mod eip4788;
|
||||
pub use eip4788::*;
|
||||
|
||||
mod eip7002;
|
||||
pub use eip7002::*;
|
||||
|
||||
mod eip7251;
|
||||
pub use eip7251::*;
|
||||
|
||||
/// A hook that is called after each state change.
|
||||
pub trait OnStateHook {
|
||||
|
||||
Reference in New Issue
Block a user