Skip to content

Commit

Permalink
Fix merge conflicts
Browse files Browse the repository at this point in the history
  • Loading branch information
emhane committed Jan 31, 2025
1 parent da72782 commit a2d539f
Show file tree
Hide file tree
Showing 8 changed files with 38 additions and 27 deletions.
2 changes: 2 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion crates/evm/src/test_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ use crate::{
BlockExecutionStrategy, BlockExecutorProvider, Executor,
},
system_calls::OnStateHook,
Database,
};
use alloy_eips::eip7685::Requests;
use parking_lot::Mutex;
Expand Down
2 changes: 2 additions & 0 deletions crates/optimism/consensus/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ reth-consensus.workspace = true
reth-primitives.workspace = true
reth-primitives-traits.workspace = true
reth-storage-api.workspace = true
reth-trie.workspace = true
reth-storage-errors.workspace = true

# op-reth
reth-optimism-forks.workspace = true
Expand Down
13 changes: 8 additions & 5 deletions crates/optimism/consensus/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,10 @@ impl FullConsensus<OpPrimitives> for OpBeaconConsensus {
}
}

impl<B: Block> Consensus<B> for OpBeaconConsensus {
impl<B> Consensus<B> for OpBeaconConsensus
where
B: Block<Body: BlockBody>,
{
type Error = ConsensusError;

fn validate_body_against_header(
Expand Down Expand Up @@ -98,7 +101,7 @@ impl<B: Block> Consensus<B> for OpBeaconConsensus {
}

// Check empty shanghai-withdrawals
if self.chain_spec.is_canyon_active_at_timestamp(block.timestamp) {
if self.chain_spec.is_canyon_active_at_timestamp(block.timestamp()) {
canyon::verify_empty_shanghai_withdrawals(block.body()).map_err(|err| {
trace!(target: "op::consensus",
block_number=block.number(),
Expand All @@ -119,9 +122,9 @@ impl<B: Block> Consensus<B> for OpBeaconConsensus {
}

// Check withdrawals root field in header
if self.chain_spec.is_isthmus_active_at_timestamp(block.timestamp) {
if self.chain_spec.is_isthmus_active_at_timestamp(block.timestamp()) {
// storage root of withdrawals pre-deploy is verified post-execution
isthmus::verify_withdrawals_storage_root_is_some(&block.header).map_err(|err| {
isthmus::verify_withdrawals_storage_root_is_some(block.header()).map_err(|err| {
trace!(target: "op::consensus",
block_number=block.number(),
%err,
Expand All @@ -132,7 +135,7 @@ impl<B: Block> Consensus<B> for OpBeaconConsensus {
})?
} else {
// canyon is active, else would have returned already
canyon::verify_empty_withdrawals_root(&block.header)?
canyon::verify_empty_withdrawals_root(block.header())?
}

Ok(())
Expand Down
14 changes: 7 additions & 7 deletions crates/optimism/consensus/src/validation/canyon.rs
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
//! Canyon consensus rule checks.
use alloy_consensus::Header;
use alloy_consensus::BlockHeader;
use alloy_trie::EMPTY_ROOT_HASH;
use reth_consensus::ConsensusError;
use reth_optimism_primitives::OpBlockBody;
use reth_primitives::GotExpected;
use reth_primitives_traits::BlockBody;

use crate::OpConsensusError;

/// Verifies that withdrawals in block body (Shanghai) is always empty in Canyon.
/// <https://specs.optimism.io/protocol/rollup-node-p2p.html#block-validation>
#[inline]
pub fn verify_empty_shanghai_withdrawals(body: &OpBlockBody) -> Result<(), OpConsensusError> {
pub fn verify_empty_shanghai_withdrawals<T: BlockBody>(body: &T) -> Result<(), OpConsensusError> {
// Shanghai rule
let withdrawals = body.withdrawals.as_ref().ok_or(ConsensusError::BodyWithdrawalsMissing)?;
let withdrawals = body.withdrawals().ok_or(ConsensusError::BodyWithdrawalsMissing)?;

// Canyon rule
if !withdrawals.is_empty() {
if !withdrawals.as_ref().is_empty() {
return Err(OpConsensusError::WithdrawalsNonEmpty)
}

Expand All @@ -26,10 +26,10 @@ pub fn verify_empty_shanghai_withdrawals(body: &OpBlockBody) -> Result<(), OpCon
/// Verifies that withdrawals root in block header (Shanghai) is always [`EMPTY_ROOT_HASH`] in
/// Canyon.
#[inline]
pub fn verify_empty_withdrawals_root(header: &Header) -> Result<(), ConsensusError> {
pub fn verify_empty_withdrawals_root<H: BlockHeader>(header: &H) -> Result<(), ConsensusError> {
// Shanghai rule
let header_withdrawals_root =
&header.withdrawals_root.ok_or(ConsensusError::WithdrawalsRootMissing)?;
&header.withdrawals_root().ok_or(ConsensusError::WithdrawalsRootMissing)?;

// Canyon rules
if *header_withdrawals_root != EMPTY_ROOT_HASH {
Expand Down
18 changes: 10 additions & 8 deletions crates/optimism/consensus/src/validation/isthmus.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//! Block verification w.r.t. consensus rules new in Isthmus hardfork.
use alloy_consensus::Header;
use alloy_consensus::BlockHeader;
use reth_optimism_primitives::predeploys::ADDRESS_L2_TO_L1_MESSAGE_PASSER;
use reth_storage_api::StorageRootProvider;
use reth_trie::{test_utils::storage_root_prehashed, HashedStorage};
Expand All @@ -10,21 +10,23 @@ use crate::OpConsensusError;

/// Verifies that `withdrawals_root` (i.e. `l2tol1-msg-passer` storage root since Isthmus) field is
/// set in block header.
pub fn verify_withdrawals_storage_root_is_some(header: &Header) -> Result<(), OpConsensusError> {
header.withdrawals_root.as_ref().ok_or(OpConsensusError::StorageRootMissing)?;
pub fn verify_withdrawals_storage_root_is_some<H: BlockHeader>(
header: H,
) -> Result<(), OpConsensusError> {
header.withdrawals_root().as_ref().ok_or(OpConsensusError::StorageRootMissing)?;

Ok(())
}

/// Verifies block header field `withdrawals_root` against storage root of
/// `l2tol1-message-passer` predeploy post block execution.
pub fn verify_withdrawals_storage_root<DB: StorageRootProvider>(
pub fn verify_withdrawals_storage_root<DB: StorageRootProvider, H: BlockHeader>(
state_updates: &BundleState,
state: DB,
header: &Header,
header: H,
) -> Result<(), OpConsensusError> {
let header_storage_root =
header.withdrawals_root.expect("should be dropped in pre-exec verification");
header.withdrawals_root().ok_or(OpConsensusError::StorageRootMissing)?;

let storage_root = match state_updates.state().get(&ADDRESS_L2_TO_L1_MESSAGE_PASSER) {
Some(account) => {
Expand Down Expand Up @@ -67,7 +69,7 @@ mod test {
use reth_optimism_chainspec::OpChainSpecBuilder;
use reth_optimism_node::OpNode;
use reth_provider::{
providers::BlockchainProvider2, test_utils::create_test_provider_factory_with_node_types,
providers::BlockchainProvider, test_utils::create_test_provider_factory_with_node_types,
StateWriter,
};
use reth_storage_api::StateProviderFactory;
Expand Down Expand Up @@ -113,7 +115,7 @@ mod test {
};

// create state provider factory
let state_provider_factory = BlockchainProvider2::new(provider_factory).unwrap();
let state_provider_factory = BlockchainProvider::new(provider_factory).unwrap();

// validate block against existing state by passing empty state updates
let block_execution_state_updates = BundleState::default();
Expand Down
11 changes: 7 additions & 4 deletions crates/optimism/evm/src/execute.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ use reth_evm::{
},
state_change::post_block_balance_increments,
system_calls::{OnStateHook, SystemCaller},
ConfigureEvmFor, Database, Evm,
ConfigureEvmFor, Evm,
};
use reth_optimism_chainspec::OpChainSpec;
use reth_optimism_consensus::{validate_block_post_execution, validation::isthmus};
Expand Down Expand Up @@ -82,8 +82,11 @@ where
where
DB: StateProvider,
{
let state =
State::builder().with_database(db).with_bundle_update().without_state_clear().build();
let state = State::builder()
.with_database(StateProviderDatabase(db))
.with_bundle_update()
.without_state_clear()
.build();
OpExecutionStrategy::new(
state,
self.chain_spec.clone(),
Expand Down Expand Up @@ -276,7 +279,7 @@ where
isthmus::verify_withdrawals_storage_root(
&state_updates,
&*self.state.database,
&block.header,
block.header(),
)
.map_err(OpBlockExecutionError::Consensus)?;
}
Expand Down
4 changes: 2 additions & 2 deletions examples/custom-beacon-withdrawals/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use reth::{
providers::StateProvider,
revm::{
primitives::{address, Address},
DatabaseCommit, State,
DatabaseCommit, State, StateProviderDatabase,
},
};
use reth_chainspec::{ChainSpec, EthereumHardforks};
Expand All @@ -23,7 +23,7 @@ use reth_evm::{
BlockExecutionError, BlockExecutionStrategy, BlockExecutionStrategyFactory, ExecuteOutput,
InternalBlockExecutionError,
},
Database, Evm,
Evm,
};
use reth_evm_ethereum::EthEvmConfig;
use reth_node_ethereum::{node::EthereumAddOns, BasicBlockExecutorProvider, EthereumNode};
Expand Down

0 comments on commit a2d539f

Please sign in to comment.