Skip to content

WIP: Update to reth 1.4.3 #168

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 4 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2,380 changes: 1,432 additions & 948 deletions Cargo.lock

Large diffs are not rendered by default.

57 changes: 24 additions & 33 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -36,47 +36,38 @@ features = ["orphan", "rkyv", "rlp_serialize", "serde"]
# External
[workspace.dependencies]
# Alloy
alloy = { version = "0.4.2", features = ["full"] }
alloy-chains = "0.1.38"
alloy-consensus = "0.4.2"
alloy-genesis = "0.4.2"
alloy-primitives = { version = "0.8.18", default-features = false, features = [
alloy = { version = "1.0.6", features = ["full"] }
alloy-chains = "0.2.1"
alloy-consensus = "1.0.6"
alloy-genesis = "1.0.6"
alloy-network-primitives = "1.0.6"
alloy-primitives = { version = "1.1.2", default-features = false, features = [
"k256",
"map-hashbrown",
] }
alloy-rlp = "0.3.8"
op-alloy-consensus = "0.4.0"
op-alloy-network = "0.4.0"
op-alloy-rpc-types = "0.4.0"
alloy-rlp = "0.3.12"
op-alloy-consensus = "0.16.0"
op-alloy-network = "0.16.0"
op-alloy-rpc-types = "0.16.0"

# Reth
reth-chainspec = { git = "https://github.com/risc0/reth", branch = "p1.1.0_zstd", default-features = false, features = [
"std",
] }
reth-consensus = { git = "https://github.com/risc0/reth", branch = "p1.1.0_zstd" }
reth-ethereum-consensus = { git = "https://github.com/risc0/reth", branch = "p1.1.0_zstd" }
reth-evm = { git = "https://github.com/risc0/reth", branch = "p1.1.0_zstd", default-features = false, features = [
"std",
] }
reth-evm-ethereum = { git = "https://github.com/risc0/reth", branch = "p1.1.0_zstd", default-features = false, features = [
"std",
] }
reth-optimism-chainspec = { git = "https://github.com/risc0/reth", branch = "p1.1.0_zstd", default-features = false, features = [
"std",
] }
reth-optimism-consensus = { git = "https://github.com/risc0/reth", branch = "p1.1.0_zstd" }
reth-optimism-evm = { git = "https://github.com/risc0/reth", branch = "p1.1.0_zstd", default-features = false }
reth-optimism-forks = { git = "https://github.com/risc0/reth", branch = "p1.1.0_zstd", default-features = false }
reth-primitives = { git = "https://github.com/risc0/reth", branch = "p1.1.0_zstd", default-features = false, features = [
reth-chainspec = { git = "https://github.com/risc0/reth", branch = "p1.4.3" }
reth-codecs = { git = "https://github.com/risc0/reth", branch = "p1.4.3", default-features = false }
reth-consensus = { git = "https://github.com/risc0/reth", branch = "p1.4.3" }
reth-ethereum-consensus = { git = "https://github.com/risc0/reth", branch = "p1.4.3" }
reth-evm = { git = "https://github.com/risc0/reth", branch = "p1.4.3" }
reth-evm-ethereum = { git = "https://github.com/risc0/reth", branch = "p1.4.3" }
reth-optimism-chainspec = { git = "https://github.com/risc0/reth", branch = "p1.4.3", features = ["serde"] }
reth-optimism-consensus = { git = "https://github.com/risc0/reth", branch = "p1.4.3" }
reth-optimism-evm = { git = "https://github.com/risc0/reth", branch = "p1.4.3", default-features = false }
reth-optimism-forks = { git = "https://github.com/risc0/reth", branch = "p1.4.3", default-features = false }
reth-optimism-primitives = { git = "https://github.com/risc0/reth", branch = "p1.4.3", default-features = false }
reth-primitives = { git = "https://github.com/risc0/reth", branch = "p1.4.3", default-features = false, features = [
"std",
"alloy-compat",
] }
reth-revm = { git = "https://github.com/risc0/reth", branch = "p1.1.0_zstd", default-features = false, features = [
"std",
] }
reth-storage-errors = { git = "https://github.com/risc0/reth", branch = "p1.1.0_zstd", default-features = false, features = [
"std",
] }
reth-revm = { git = "https://github.com/risc0/reth", branch = "p1.4.3", features = ["serde"] }
reth-storage-errors = { git = "https://github.com/risc0/reth", branch = "p1.4.3" }

# Zeth
zeth = { path = "crates/zeth" }
Expand Down
23 changes: 7 additions & 16 deletions crates/core-ethereum/src/chain_spec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,10 @@
use alloy_genesis::Genesis;
use once_cell::sync::Lazy;
use reth_chainspec::{
once_cell_set, BaseFeeParams, BaseFeeParamsKind, Chain, ChainSpec, DepositContract,
EthereumHardfork, DEV_HARDFORKS,
BaseFeeParams, BaseFeeParamsKind, Chain, ChainSpec, DepositContract, EthereumHardfork,
DEV_HARDFORKS, MAINNET_PRUNE_DELETE_LIMIT,
};
use reth_primitives::constants::ETHEREUM_BLOCK_GAS_LIMIT;
use reth_primitives::revm_primitives::{address, b256, U256};
use reth_primitives::{
DEV_GENESIS_HASH, HOLESKY_GENESIS_HASH, MAINNET_GENESIS_HASH, SEPOLIA_GENESIS_HASH,
};
use reth_revm::primitives::bytes;
use reth_revm::primitives::{address, b256, bytes, U256};
use std::sync::Arc;

/// The Ethereum mainnet spec
Expand All @@ -41,7 +36,6 @@ pub static MAINNET: Lazy<Arc<ChainSpec>> = Lazy::new(|| {
genesis.config.dao_fork_support = true;
genesis
},
genesis_hash: once_cell_set(MAINNET_GENESIS_HASH),
genesis_header: Default::default(),
// <https://etherscan.io/block/15537394>
paris_block_and_final_difficulty: Some((
Expand All @@ -56,8 +50,8 @@ pub static MAINNET: Lazy<Arc<ChainSpec>> = Lazy::new(|| {
b256!("649bbc62d0e31342afea4e5cd82d4049e7e1ee912fc0889aa790803be39038c5"),
)),
base_fee_params: BaseFeeParamsKind::Constant(BaseFeeParams::ethereum()),
max_gas_limit: ETHEREUM_BLOCK_GAS_LIMIT,
prune_delete_limit: 20000,
prune_delete_limit: MAINNET_PRUNE_DELETE_LIMIT,
blob_params: Default::default(),
}
.into()
});
Expand All @@ -77,7 +71,6 @@ pub static SEPOLIA: Lazy<Arc<ChainSpec>> = Lazy::new(|| {
genesis.config.dao_fork_support = true;
genesis
},
genesis_hash: once_cell_set(SEPOLIA_GENESIS_HASH),
genesis_header: Default::default(),
// <https://sepolia.etherscan.io/block/1450409>
paris_block_and_final_difficulty: Some((1450409, U256::from(17_000_018_015_853_232u128))),
Expand All @@ -89,8 +82,8 @@ pub static SEPOLIA: Lazy<Arc<ChainSpec>> = Lazy::new(|| {
b256!("649bbc62d0e31342afea4e5cd82d4049e7e1ee912fc0889aa790803be39038c5"),
)),
base_fee_params: BaseFeeParamsKind::Constant(BaseFeeParams::ethereum()),
max_gas_limit: ETHEREUM_BLOCK_GAS_LIMIT,
prune_delete_limit: 10000,
blob_params: Default::default(),
}
.into()
});
Expand All @@ -108,7 +101,6 @@ pub static HOLESKY: Lazy<Arc<ChainSpec>> = Lazy::new(|| {
genesis.config.dao_fork_support = true;
genesis
},
genesis_hash: once_cell_set(HOLESKY_GENESIS_HASH),
genesis_header: Default::default(),
paris_block_and_final_difficulty: Some((0, U256::from(1))),
hardforks: EthereumHardfork::holesky().into(),
Expand All @@ -118,8 +110,8 @@ pub static HOLESKY: Lazy<Arc<ChainSpec>> = Lazy::new(|| {
b256!("649bbc62d0e31342afea4e5cd82d4049e7e1ee912fc0889aa790803be39038c5"),
)),
base_fee_params: BaseFeeParamsKind::Constant(BaseFeeParams::ethereum()),
max_gas_limit: ETHEREUM_BLOCK_GAS_LIMIT,
prune_delete_limit: 10000,
blob_params: Default::default(),
}
.into()
});
Expand All @@ -132,7 +124,6 @@ pub static DEV: Lazy<Arc<ChainSpec>> = Lazy::new(|| {
ChainSpec {
chain: Chain::dev(),
genesis: Genesis::default(),
genesis_hash: once_cell_set(DEV_GENESIS_HASH),
paris_block_and_final_difficulty: Some((0, U256::from(0))),
hardforks: DEV_HARDFORKS.clone(),
base_fee_params: BaseFeeParamsKind::Constant(BaseFeeParams::ethereum()),
Expand Down
65 changes: 35 additions & 30 deletions crates/core-ethereum/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,18 @@ use crate::chain_spec::{DEV, HOLESKY, MAINNET, SEPOLIA};
use anyhow::Context;
use k256::ecdsa::signature::hazmat::PrehashVerifier;
use k256::ecdsa::VerifyingKey;
use reth_chainspec::{ChainSpec, EthereumHardforks, NamedChain};
use reth_consensus::Consensus;
use reth_chainspec::{ChainSpec, EthChainSpec, EthereumHardforks, NamedChain};
use reth_consensus::{Consensus, HeaderValidator};
use reth_ethereum_consensus::EthBeaconConsensus;
use reth_evm::execute::{
BatchExecutor, BlockExecutionInput, BlockExecutorProvider, ExecutionOutcome,
};
use reth_evm::execute::Executor;
use reth_evm::ConfigureEvm;
use reth_evm_ethereum::execute::EthExecutorProvider;
use reth_primitives::revm_primitives::alloy_primitives::{BlockNumber, Sealable};
use reth_primitives::revm_primitives::{Address, B256, U256};
use reth_primitives::{Block, Header, Receipt, SealedHeader, TransactionSigned};
use reth_primitives::{
Block, Header, Receipt, RecoveredBlock, SealedBlock, SealedHeader, TransactionSigned,
};
use reth_revm::db::BundleState;
use reth_revm::primitives::alloy_primitives::{BlockNumber, Sealable};
use reth_revm::primitives::{Address, B256, U256};
use reth_storage_errors::provider::ProviderError;
use std::fmt::Display;
use std::mem::take;
Expand Down Expand Up @@ -72,24 +73,27 @@ where
parent_header: &mut Header,
total_difficulty: &mut U256,
) -> anyhow::Result<()> {
// Validate total difficulty
if !chain_spec.is_paris_active_at_block(block.number) {
// Total difficulty must not have reached Paris threshold prior to its activation
if let Some(paris_difficulty) = chain_spec.final_paris_total_difficulty() {
assert!(paris_difficulty > *total_difficulty);
}
}
// Instantiate consensus engine
let consensus = EthBeaconConsensus::new(chain_spec);
// Validate total difficulty
consensus
.validate_header_with_total_difficulty(&block.header, *total_difficulty)
.context("validate_header_with_total_difficulty")?;
// Validate header (todo: seal beforehand to save rehashing costs)
let sealed_block = take(block).seal_slow();
let sealed_block = SealedBlock::seal_slow(take(block));
consensus
.validate_header(&sealed_block.header)
.validate_header(sealed_block.sealed_header())
.context("validate_header")?;
// Validate header w.r.t. parent
let sealed_parent_header = {
let (parent_header, parent_header_seal) = take(parent_header).seal_slow().into_parts();
SealedHeader::new(parent_header, parent_header_seal)
};
consensus
.validate_header_against_parent(&sealed_block.header, &sealed_parent_header)
.validate_header_against_parent(sealed_block.sealed_header(), &sealed_parent_header)
.context("validate_header_against_parent")?;
// Check pre-execution block conditions
consensus
Expand All @@ -104,7 +108,7 @@ where

pub struct RethExecutionStrategy;

impl<Database: reth_revm::Database> ExecutionStrategy<RethCoreDriver, Database>
impl<Database: reth_evm::Database> ExecutionStrategy<RethCoreDriver, Database>
for RethExecutionStrategy
where
Database: 'static,
Expand All @@ -114,12 +118,12 @@ where
chain_spec: Arc<ChainSpec>,
block: &mut Block,
signers: &[VerifyingKey],
total_difficulty: &mut U256,
_total_difficulty: &mut U256,
db: &mut Option<Database>,
) -> anyhow::Result<BundleState> {
// Instantiate execution engine using database
let mut executor = EthExecutorProvider::ethereum(chain_spec.clone())
.batch_executor(db.take().expect("Missing database."));
let evm_config = EthExecutorProvider::ethereum(chain_spec.clone());
let mut executor = evm_config.batch_executor(db.take().expect("Missing database."));
// Verify the transaction signatures and compute senders
let mut senders = Vec::with_capacity(block.body.transactions.len());
for (i, tx) in block.body.transactions().enumerate() {
Expand All @@ -141,19 +145,16 @@ where
}

// Execute transactions
let block_with_senders = take(block).with_senders_unchecked(senders);
let block_hash = block.hash_slow();
let block_with_senders = RecoveredBlock::new(take(block), senders, block_hash);
executor
.execute_and_verify_one(BlockExecutionInput {
block: &block_with_senders,
total_difficulty: *total_difficulty,
})
.execute_one(&block_with_senders)
.context("execution failed")?;

// Return block
*block = block_with_senders.block;
*block = block_with_senders.into_block();
// Return bundle state
let ExecutionOutcome { bundle, .. } = executor.finalize();
Ok(bundle)
Ok(executor.into_state().bundle_state)
}
}

Expand Down Expand Up @@ -210,8 +211,12 @@ impl CoreDriver for RethCoreDriver {
total_difficulty: U256,
chain_spec: &Self::ChainSpec,
) -> U256 {
chain_spec
.final_paris_total_difficulty(block)
.unwrap_or(total_difficulty)
if chain_spec.is_paris_active_at_block(block) {
chain_spec
.final_paris_total_difficulty()
.unwrap_or(total_difficulty)
} else {
total_difficulty
}
}
}
10 changes: 6 additions & 4 deletions crates/core-optimism/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,14 @@ once_cell.workspace = true
op-alloy-consensus.workspace = true

reth-chainspec.workspace = true
reth-codecs = { workspace = true, features = ["op"] }
reth-consensus.workspace = true
reth-evm.workspace = true
reth-optimism-chainspec.workspace = true
reth-optimism-consensus = { workspace = true, features = ["optimism"] }
reth-optimism-evm = { workspace = true, features = ["optimism"] }
reth-optimism-consensus = { workspace = true }
reth-optimism-evm = { workspace = true }
reth-optimism-forks.workspace = true
reth-primitives = { workspace = true, features = ["optimism"] }
reth-revm = { workspace = true, features = ["optimism"] }
reth-optimism-primitives = { workspace = true }
reth-primitives = { workspace = true }
reth-revm = { workspace = true }
reth-storage-errors.workspace = true
Loading
Loading