Skip to content

Commit

Permalink
Bump Reth to 1.0.1
Browse files Browse the repository at this point in the history
  • Loading branch information
dapplion committed Jul 13, 2024
1 parent d83f0b1 commit 65b2ec2
Show file tree
Hide file tree
Showing 8 changed files with 1,663 additions and 901 deletions.
2,297 changes: 1,444 additions & 853 deletions Cargo.lock

Large diffs are not rendered by default.

19 changes: 12 additions & 7 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,22 @@ name = "reth"
path = "src/main.rs"

[dependencies]
reth = { git = "https://github.com/paradigmxyz/reth", rev = "7b435e0d6dede497dca211090d95a4cfa387dd1b" }
reth-evm = { git = "https://github.com/paradigmxyz/reth", rev = "7b435e0d6dede497dca211090d95a4cfa387dd1b" }
reth-engine-primitives = { git = "https://github.com/paradigmxyz/reth", rev = "7b435e0d6dede497dca211090d95a4cfa387dd1b" }
reth-node-ethereum = { git = "https://github.com/paradigmxyz/reth", rev = "7b435e0d6dede497dca211090d95a4cfa387dd1b" }
reth-evm-ethereum = { git = "https://github.com/paradigmxyz/reth", rev = "7b435e0d6dede497dca211090d95a4cfa387dd1b" }
reth-ethereum-consensus = { git = "https://github.com/paradigmxyz/reth", rev = "7b435e0d6dede497dca211090d95a4cfa387dd1b" }
reth = { git = "https://github.com/paradigmxyz/reth", rev = "d599393771f9d7d137ea4abf271e1bd118184c73" }
reth-evm = { git = "https://github.com/paradigmxyz/reth", rev = "d599393771f9d7d137ea4abf271e1bd118184c73" }
reth-engine-primitives = { git = "https://github.com/paradigmxyz/reth", rev = "d599393771f9d7d137ea4abf271e1bd118184c73" }
reth-node-ethereum = { git = "https://github.com/paradigmxyz/reth", rev = "d599393771f9d7d137ea4abf271e1bd118184c73" }
reth-evm-ethereum = { git = "https://github.com/paradigmxyz/reth", rev = "d599393771f9d7d137ea4abf271e1bd118184c73" }
reth-ethereum-consensus = { git = "https://github.com/paradigmxyz/reth", rev = "d599393771f9d7d137ea4abf271e1bd118184c73" }
reth-chainspec = { git = "https://github.com/paradigmxyz/reth", rev = "d599393771f9d7d137ea4abf271e1bd118184c73" }
reth-consensus = { git = "https://github.com/paradigmxyz/reth", rev = "d599393771f9d7d137ea4abf271e1bd118184c73" }
reth-auto-seal-consensus = { git = "https://github.com/paradigmxyz/reth", rev = "d599393771f9d7d137ea4abf271e1bd118184c73" }
reth-prune-types = { git = "https://github.com/paradigmxyz/reth", rev = "d599393771f9d7d137ea4abf271e1bd118184c73" }
eyre = "0.6.12"
clap = { version = "4.5.6", features = ["derive"] }
alloy-sol-macro = "0.7.6"
alloy-sol-types = "0.7.6"
revm = "9.0.0"
revm = "11.0.0"
revm-primitives = "6.0.0"
serde_json = "1.0.117"

[target.'cfg(unix)'.dependencies]
Expand Down
52 changes: 52 additions & 0 deletions src/consensus.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
use reth::primitives::{BlockWithSenders, Header, SealedBlock, SealedHeader};
use reth_chainspec::ChainSpec;
use reth_consensus::{Consensus, ConsensusError, PostExecutionInput};
use revm_primitives::U256;
use std::sync::Arc;

#[derive(Debug, Clone, PartialEq, Eq)]
pub struct GnosisBeaconConsensus {
/// Configuration
chain_spec: Arc<ChainSpec>,
}

impl GnosisBeaconConsensus {
pub fn new(chain_spec: Arc<ChainSpec>) -> Self {
Self { chain_spec }
}
}

// `validate_header`, `validate_header_against_parent`, `validate_header_with_total_difficulty`, `validate_block_pre_execution`, `validate_block_post_execution`
impl Consensus for GnosisBeaconConsensus {
fn validate_header(&self, _header: &SealedHeader) -> Result<(), ConsensusError> {
todo!();
}

fn validate_header_against_parent(
&self,
_header: &SealedHeader,
_parent: &SealedHeader,
) -> Result<(), ConsensusError> {
todo!();
}

fn validate_header_with_total_difficulty(
&self,
_header: &Header,
_total_difficulty: U256,
) -> Result<(), ConsensusError> {
todo!();
}

fn validate_block_pre_execution(&self, _block: &SealedBlock) -> Result<(), ConsensusError> {
todo!();
}

fn validate_block_post_execution(
&self,
_block: &BlockWithSenders,
_input: PostExecutionInput<'_>,
) -> Result<(), ConsensusError> {
todo!();
}
}
47 changes: 34 additions & 13 deletions src/ethereum.rs
Original file line number Diff line number Diff line change
@@ -1,23 +1,25 @@
//! This module is exactly identical to <https://github.com/paradigmxyz/reth/blob/268e768d822a0d4eb8ed365dc6390862f759a849/crates/ethereum/evm/src/execute.rs>

use reth::{
primitives::{BlockWithSenders, ChainSpec, Receipt, Request},
primitives::{BlockWithSenders, Receipt, Request},
providers::ProviderError,
revm::{
primitives::ResultAndState,
state_change::{
apply_beacon_root_contract_call, apply_blockhashes_update,
apply_withdrawal_requests_contract_call,
},
Database, DatabaseCommit, Evm, State,
primitives::ResultAndState, state_change::apply_blockhashes_update, Database,
DatabaseCommit, Evm, State,
},
};
use reth_chainspec::{ChainSpec, EthereumHardforks};
use reth_evm::{
execute::{BlockExecutionError, BlockValidationError},
system_calls::{
apply_beacon_root_contract_call, apply_consolidation_requests_contract_call,
apply_withdrawal_requests_contract_call,
},
ConfigureEvm,
};
use reth_evm_ethereum::eip6110::parse_deposits_from_receipts;
use std::sync::Arc;
use revm_primitives::EVMError;
use std::{fmt::Display, sync::Arc};

/// Helper type for the output of executing a block.
#[derive(Debug, Clone)]
Expand Down Expand Up @@ -51,10 +53,11 @@ where
mut evm: Evm<'_, Ext, &mut State<DB>>,
) -> Result<EthExecuteOutput, BlockExecutionError>
where
DB: Database<Error = ProviderError>,
DB: Database<Error: Into<ProviderError> + Display>,
{
// apply pre execution changes
apply_beacon_root_contract_call(
&self.evm_config,
&self.chain_spec,
block.timestamp,
block.number,
Expand Down Expand Up @@ -86,14 +89,22 @@ where
);
}

EvmConfig::fill_tx_env(evm.tx_mut(), transaction, *sender);
self.evm_config
.fill_tx_env(evm.tx_mut(), transaction, *sender);

// Execute transaction.
let ResultAndState { result, state } = evm.transact().map_err(move |err| {
let new_err = match err {
EVMError::Transaction(e) => EVMError::Transaction(e),
EVMError::Header(e) => EVMError::Header(e),
EVMError::Database(e) => EVMError::Database(e.into()),
EVMError::Custom(e) => EVMError::Custom(e),
EVMError::Precompile(e) => EVMError::Precompile(e),
};
// Ensure hash is calculated for error log, if not already done
BlockValidationError::EVM {
hash: transaction.recalculate_hash(),
error: err.into(),
error: Box::new(new_err),
}
})?;
evm.db_mut().commit(state);
Expand Down Expand Up @@ -125,9 +136,19 @@ where
let deposit_requests = parse_deposits_from_receipts(&self.chain_spec, &receipts)?;

// Collect all EIP-7685 requests
let withdrawal_requests = apply_withdrawal_requests_contract_call(&mut evm)?;
let withdrawal_requests =
apply_withdrawal_requests_contract_call(&self.evm_config, &mut evm)?;

// Collect all EIP-7251 requests
let consolidation_requests =
apply_consolidation_requests_contract_call(&self.evm_config, &mut evm)?;

[deposit_requests, withdrawal_requests].concat()
[
deposit_requests,
withdrawal_requests,
consolidation_requests,
]
.concat()
} else {
vec![]
};
Expand Down
64 changes: 59 additions & 5 deletions src/evm_config.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
use reth::{
primitives::{Address, ChainSpec, Header, TransactionSigned, U256},
primitives::{transaction::FillTxEnv, Address, Head, Header, TransactionSigned, U256},
revm::{
inspector_handle_register,
interpreter::Gas,
primitives::{spec_to_generic, CfgEnvWithHandlerCfg, EVMError, Spec, SpecId, TxEnv},
Context, Database, Evm, EvmBuilder, GetInspector,
},
};
use reth_chainspec::ChainSpec;
use reth_evm::{ConfigureEvm, ConfigureEvmEnv};
use reth_evm_ethereum::EthEvmConfig;
use reth_evm_ethereum::revm_spec;
use revm::handler::mainnet::reward_beneficiary as reward_beneficiary_mainnet;
use revm_primitives::{AnalysisKind, Bytes, Env, TxKind};
use std::sync::Arc;

/// Reward beneficiary with gas fee.
Expand Down Expand Up @@ -97,16 +99,68 @@ impl ConfigureEvm for GnosisEvmConfig {
}

impl ConfigureEvmEnv for GnosisEvmConfig {
fn fill_tx_env(tx_env: &mut TxEnv, transaction: &TransactionSigned, sender: Address) {
EthEvmConfig::fill_tx_env(tx_env, transaction, sender)
fn fill_tx_env(&self, tx_env: &mut TxEnv, transaction: &TransactionSigned, sender: Address) {
transaction.fill_tx_env(tx_env, sender);
}

fn fill_tx_env_system_contract_call(
&self,
env: &mut Env,
caller: Address,
contract: Address,
data: Bytes,
) {
env.tx = TxEnv {
caller,
transact_to: TxKind::Call(contract),
// Explicitly set nonce to None so revm does not do any nonce checks
nonce: None,
gas_limit: 30_000_000,
value: U256::ZERO,
data,
// Setting the gas price to zero enforces that no value is transferred as part of the
// call, and that the call will not count against the block's gas limit
gas_price: U256::ZERO,
// The chain ID check is not relevant here and is disabled if set to None
chain_id: None,
// Setting the gas priority fee to None ensures the effective gas price is derived from
// the `gas_price` field, which we need to be zero
gas_priority_fee: None,
access_list: Vec::new(),
// blob fields can be None for this tx
blob_hashes: Vec::new(),
max_fee_per_blob_gas: None,
authorization_list: None,
};

// ensure the block gas limit is >= the tx
env.block.gas_limit = U256::from(env.tx.gas_limit);

// disable the base fee check for this call by setting the base fee to zero
env.block.basefee = U256::ZERO;
}

fn fill_cfg_env(
&self,
cfg_env: &mut CfgEnvWithHandlerCfg,
chain_spec: &ChainSpec,
header: &Header,
total_difficulty: U256,
) {
EthEvmConfig::fill_cfg_env(cfg_env, chain_spec, header, total_difficulty);
let spec_id = revm_spec(
chain_spec,
&Head {
number: header.number,
timestamp: header.timestamp,
difficulty: header.difficulty,
total_difficulty,
hash: Default::default(),
},
);

cfg_env.chain_id = chain_spec.chain().id();
cfg_env.perf_analyse_created_bytecodes = AnalysisKind::Analyse;

cfg_env.handler_cfg.spec_id = spec_id;
}
}
Loading

0 comments on commit 65b2ec2

Please sign in to comment.