From 94d1d8719d1dadaf29b274c9d3e112d24c35ee8d Mon Sep 17 00:00:00 2001 From: Matthias Seitz Date: Tue, 24 Sep 2024 15:40:53 +0200 Subject: [PATCH] feat: add transact function to 7251 (#11158) --- crates/evm/src/system_calls/eip7251.rs | 36 +++++++++++++++++++++----- 1 file changed, 30 insertions(+), 6 deletions(-) diff --git a/crates/evm/src/system_calls/eip7251.rs b/crates/evm/src/system_calls/eip7251.rs index 02684d83b7a2..8a7049671028 100644 --- a/crates/evm/src/system_calls/eip7251.rs +++ b/crates/evm/src/system_calls/eip7251.rs @@ -48,11 +48,13 @@ where /// /// 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. +/// +/// Note: this does not commit the state changes to the database, it only transact the call. #[inline] -pub fn apply_consolidation_requests_contract_call( +pub fn transact_consolidation_requests_contract_call( evm_config: &EvmConfig, evm: &mut Evm<'_, EXT, DB>, -) -> Result, BlockExecutionError> +) -> Result where DB: Database + DatabaseCommit, DB::Error: core::fmt::Display, @@ -77,7 +79,7 @@ where Bytes::new(), ); - let ResultAndState { result, mut state } = match evm.transact() { + let mut res = match evm.transact() { Ok(res) => res, Err(e) => { evm.context.evm.env = previous_env; @@ -89,13 +91,35 @@ where }; // cleanup the state - state.remove(&alloy_eips::eip7002::SYSTEM_ADDRESS); - state.remove(&evm.block().coinbase); - evm.context.evm.db.commit(state); + res.state.remove(&alloy_eips::eip7002::SYSTEM_ADDRESS); + res.state.remove(&evm.block().coinbase); // re-set the previous env evm.context.evm.env = previous_env; + 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( + evm_config: &EvmConfig, + evm: &mut Evm<'_, EXT, DB>, +) -> Result, BlockExecutionError> +where + DB: Database + DatabaseCommit, + DB::Error: core::fmt::Display, + EvmConfig: ConfigureEvm
, +{ + let ResultAndState { result, state } = + transact_consolidation_requests_contract_call(evm_config, evm)?; + + // commit the state + evm.context.evm.db.commit(state); + let mut data = match result { ExecutionResult::Success { output, .. } => Ok(output.into_data()), ExecutionResult::Revert { output, .. } => {