Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
Wodann committed Sep 16, 2024
1 parent 00ab711 commit cfc180b
Show file tree
Hide file tree
Showing 81 changed files with 734 additions and 804 deletions.
234 changes: 70 additions & 164 deletions Cargo.lock

Large diffs are not rendered by default.

10 changes: 5 additions & 5 deletions crates/edr_eth/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ version = "0.3.5"
edition = "2021"

[dependencies]
anyhow = "1.0.75"
anyhow = "1.0.89"
alloy-eips = { version = "0.3", default-features = false }
alloy-rlp = { version = "0.3", default-features = false, features = ["derive"] }
c-kzg = { version = "1.0.3", default-features = false }
Expand All @@ -16,9 +16,9 @@ hex = { version = "0.4.3", default-features = false, features = ["alloc"] }
itertools = { version = "0.10.5", default-features = false, features = ["use_alloc"] }
k256 = { version = "0.13.1", default-features = false, features = ["arithmetic", "ecdsa", "pkcs8", ] }
log = { version = "0.4.17", default-features = false }
once_cell = { version = "1.18.0", default-features = false, features = ["alloc", "race", "std"] }
revm = { git = "https://github.com/Wodann/revm", rev = "dfc2f28f", version = "14.0", default-features = false, features = ["c-kzg", "dev", "serde"] }
revm-primitives = { git = "https://github.com/Wodann/revm", rev = "dfc2f28f", version = "9.0", default-features = false, features = ["c-kzg", "hashbrown", "rand"] }
once_cell = { version = "1.19.0", default-features = false, features = ["alloc", "race", "std"] }
revm = { git = "https://github.com/Wodann/revm", rev = "e407ed0", version = "14.0", default-features = false, features = ["c-kzg", "dev", "serde"] }
revm-primitives = { git = "https://github.com/Wodann/revm", rev = "e407ed0", version = "9.0", default-features = false, features = ["c-kzg", "hashbrown", "rand"] }
serde = { version = "1.0.209", default-features = false, features = ["derive"], optional = true }
sha2 = { version = "0.10.8", default-features = false }
sha3 = { version = "0.10.8", default-features = false }
Expand All @@ -27,7 +27,7 @@ tracing = { version = "0.1.37", features = ["attributes", "std"], optional = tru
triehash = { version = "0.8.4", default-features = false }

[dev-dependencies]
anyhow = "1.0.75"
anyhow = "1.0.89"
assert-json-diff = "2.0.2"
edr_defaults = { version = "0.3.5", path = "../edr_defaults" }
edr_rpc_eth = { version = "0.3.5", path = "../edr_rpc_eth" }
Expand Down
31 changes: 1 addition & 30 deletions crates/edr_eth/src/chain_spec.rs
Original file line number Diff line number Diff line change
@@ -1,40 +1,11 @@
use std::marker::PhantomData;

use alloy_rlp::RlpEncodable;
use revm::Database;
pub use revm_primitives::EvmWiring;
use revm_primitives::{ChainSpec, InvalidTransaction, TransactionValidation};
pub use revm_primitives::{ChainSpec, EvmWiring, HaltReasonTrait, HardforkTrait};

use crate::{
eips::eip1559::{BaseFeeParams, ConstantBaseFeeParams},
transaction,
};

/// A wrapper around the EVM's wiring.
pub struct Wiring<ChainSpecT: ChainSpec, DatabaseT: Database, ExternalContextT> {
_phantom: PhantomData<(ChainSpecT, DatabaseT, ExternalContextT)>,
}

impl<ChainSpecT: ChainSpec, DatabaseT: Database, ExternalContextT> EvmWiring
for Wiring<ChainSpecT, DatabaseT, ExternalContextT>
{
type ChainSpec = ChainSpecT;
type ExternalContext = ExternalContextT;
type Database = DatabaseT;
}

impl<ChainSpecT, DatabaseT, ExternalContextT> revm::EvmWiring
for Wiring<ChainSpecT, DatabaseT, ExternalContextT>
where
ChainSpecT:
ChainSpec<Transaction: TransactionValidation<ValidationError: From<InvalidTransaction>>>,
DatabaseT: Database,
{
fn handler<'evm>(hardfork: Self::Hardfork) -> revm::EvmHandler<'evm, Self> {
revm::EvmHandler::mainnet_with_spec(hardfork)
}
}

/// The chain specification for Ethereum Layer 1.
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, RlpEncodable)]
pub struct L1ChainSpec;
Expand Down
4 changes: 2 additions & 2 deletions crates/edr_eth/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ pub use revm_primitives::{
address,
alloy_primitives::{Bloom, BloomInput, ChainId, B512, B64, U128, U160, U64, U8},
bytes, db, env, hex, hex_literal, result, specification, AccessList, AccessListItem,
AccountInfo, Address, Bytecode, Bytes, HashMap, HashSet, Precompile, SpecId, B256,
KECCAK_EMPTY, MAX_INITCODE_SIZE, U256,
AccountInfo, Address, Bytecode, Bytes, HashMap, HashSet, Precompile, SignedAuthorization,
SpecId, B256, KECCAK_EMPTY, MAX_INITCODE_SIZE, U256,
};

pub use self::block_spec::{BlockSpec, BlockTag, Eip1898BlockSpec, PreEip1898BlockSpec};
Expand Down
4 changes: 3 additions & 1 deletion crates/edr_eth/src/transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ pub mod signed;

use std::str::FromStr;

pub use revm_primitives::{alloy_primitives::TxKind, Transaction, TransactionValidation};
pub use revm_primitives::{
alloy_primitives::TxKind, AuthorizationList, Transaction, TransactionValidation,
};
use revm_primitives::{ruint, B256};

use crate::{signature::Signature, Bytes, U256, U8};
Expand Down
8 changes: 4 additions & 4 deletions crates/edr_evm/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ version = "0.3.5"
edition = "2021"

[dependencies]
anyhow = { version = "1.0.75", optional = true }
anyhow = { version = "1.0.89", optional = true }
alloy-rlp = { version = "0.3", default-features = false, features = ["derive"] }
async-rwlock = { version = "1.3.0", default-features = false }
auto_impl = { version = "1.2", default-features = false }
Expand All @@ -16,12 +16,12 @@ hasher = { version = "0.1.4", default-features = false, features = ["hash-keccak
indexmap = { version = "2.0.0", default-features = false, features = ["std"] }
itertools = { version = "0.11.0", default-features = false, features = ["use_alloc", "use_std"] }
log = { version = "0.4.17", default-features = false }
once_cell = { version = "1.18.0", default-features = false, features = ["alloc", "race", "std"] }
once_cell = { version = "1.19.0", default-features = false, features = ["alloc", "race", "std"] }
parking_lot = { version = "0.12.1", default-features = false }
edr_defaults = { version = "0.3.5", path = "../edr_defaults" }
edr_eth = { version = "0.3.5", path = "../edr_eth", features = ["serde"] }
edr_rpc_eth = { version = "0.3.5", path = "../edr_rpc_eth" }
revm = { git = "https://github.com/Wodann/revm", rev = "dfc2f28f", version = "14.0", default-features = false, features = ["c-kzg", "dev", "serde", "std"] }
revm = { git = "https://github.com/Wodann/revm", rev = "e407ed0", version = "14.0", default-features = false, features = ["c-kzg", "dev", "serde", "std"] }
rpds = { version = "1.1.0", default-features = false, features = ["std"] }
serde = { version = "1.0.209", default-features = false, features = ["std"] }
serde_json = { version = "1.0.127", default-features = false, features = ["std"] }
Expand All @@ -30,7 +30,7 @@ tokio = { version = "1.21.2", default-features = false, features = ["macros", "r
tracing = { version = "0.1.37", features = ["attributes", "std"], optional = true }

[dev-dependencies]
anyhow = "1.0.75"
anyhow = "1.0.89"
criterion = { version = "0.4.0", default-features = false, features = ["cargo_bench_support", "html_reports", "plotters"] }
edr_test_utils = { version = "0.3.5", path = "../edr_test_utils" }
lazy_static = "1.4.0"
Expand Down
16 changes: 8 additions & 8 deletions crates/edr_evm/src/block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ pub use self::{
local::LocalBlock,
remote::{ConversionError as RemoteBlockConversionError, EthRpcBlock, RemoteBlock},
};
use crate::chain_spec::ChainSpec;
use crate::chain_spec::EvmSpec;

/// A block receipt with filter logs for the specified RPC specification.
pub type BlockReceipt<RpcSpecT> = edr_eth::receipt::BlockReceipt<
Expand All @@ -33,7 +33,7 @@ pub type BlockReceipt<RpcSpecT> = edr_eth::receipt::BlockReceipt<

/// Trait for implementations of an Ethereum block.
#[auto_impl(Arc)]
pub trait Block<ChainSpecT: ChainSpec>: Debug {
pub trait Block<ChainSpecT: EvmSpec>: Debug {
/// The blockchain error type.
type Error;

Expand Down Expand Up @@ -62,19 +62,19 @@ pub trait Block<ChainSpecT: ChainSpec>: Debug {
/// Trait that meets all requirements for a synchronous block.
pub trait SyncBlock<ChainSpecT>: Block<ChainSpecT> + Send + Sync
where
ChainSpecT: ChainSpec,
ChainSpecT: EvmSpec,
{
}

impl<BlockT, ChainSpecT> SyncBlock<ChainSpecT> for BlockT
where
BlockT: Block<ChainSpecT> + Send + Sync,
ChainSpecT: ChainSpec,
ChainSpecT: EvmSpec,
{
}

/// A type containing the relevant data for an Ethereum block.
pub struct EthBlockData<ChainSpecT: ChainSpec> {
pub struct EthBlockData<ChainSpecT: EvmSpec> {
/// The block's header.
pub header: edr_eth::block::Header,
/// The block's transactions.
Expand All @@ -89,7 +89,7 @@ pub struct EthBlockData<ChainSpecT: ChainSpec> {
pub rlp_size: u64,
}

impl<ChainSpecT: ChainSpec> TryFrom<edr_rpc_eth::Block<ChainSpecT::RpcTransaction>>
impl<ChainSpecT: EvmSpec> TryFrom<edr_rpc_eth::Block<ChainSpecT::RpcTransaction>>
for EthBlockData<ChainSpecT>
{
type Error = RemoteBlockConversionError<ChainSpecT>;
Expand Down Expand Up @@ -154,14 +154,14 @@ impl<ChainSpecT: ChainSpec> TryFrom<edr_rpc_eth::Block<ChainSpecT::RpcTransactio

/// The result returned by requesting a block by number.
#[derive_where(Clone, Debug)]
pub struct BlockAndTotalDifficulty<ChainSpecT: ChainSpec, BlockchainErrorT> {
pub struct BlockAndTotalDifficulty<ChainSpecT: EvmSpec, BlockchainErrorT> {
/// The block
pub block: Arc<dyn SyncBlock<ChainSpecT, Error = BlockchainErrorT>>,
/// The total difficulty with the block
pub total_difficulty: Option<U256>,
}

impl<BlockchainErrorT, ChainSpecT: ChainSpec>
impl<BlockchainErrorT, ChainSpecT: EvmSpec>
From<BlockAndTotalDifficulty<ChainSpecT, BlockchainErrorT>> for edr_rpc_eth::Block<B256>
{
fn from(value: BlockAndTotalDifficulty<ChainSpecT, BlockchainErrorT>) -> Self {
Expand Down
23 changes: 11 additions & 12 deletions crates/edr_evm/src/block/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ use std::{

use edr_eth::{
block::{BlobGas, BlockOptions, PartialHeader},
chain_spec::Wiring,
env::{CfgEnv, Env},
log::ExecutionLog,
receipt::{ExecutionReceiptBuilder as _, Receipt as _, TransactionReceipt},
Expand All @@ -27,7 +26,7 @@ use revm::{
use super::local::LocalBlock;
use crate::{
blockchain::SyncBlockchain,
chain_spec::{BlockEnvConstructor, ChainSpec},
chain_spec::{BlockEnvConstructor, EvmSpec},
debug::{DebugContext, EvmContext},
state::{AccountModifierFn, StateDebug, StateDiff, SyncState},
transaction::TransactionError,
Expand All @@ -38,7 +37,7 @@ use crate::{
#[derive(Debug, thiserror::Error)]
pub enum BlockBuilderCreationError<ChainSpecT>
where
ChainSpecT: ChainSpec<Hardfork: Debug>,
ChainSpecT: EvmSpec<Hardfork: Debug>,
{
/// Unsupported hardfork. Hardforks older than Byzantium are not supported
#[error("Unsupported hardfork: {0:?}. Hardforks older than Byzantium are not supported.")]
Expand Down Expand Up @@ -66,7 +65,7 @@ where
/// was executed.
pub struct ExecutionResultWithContext<
'evm,
ChainSpecT: ChainSpec<Transaction: TransactionValidation<ValidationError: From<InvalidTransaction>>>,
ChainSpecT: EvmSpec<Transaction: TransactionValidation<ValidationError: From<InvalidTransaction>>>,
BlockchainErrorT,
StateErrorT,
DebugDataT,
Expand All @@ -82,15 +81,15 @@ pub struct ExecutionResultWithContext<
}

/// The result of building a block, using the [`BlockBuilder`].
pub struct BuildBlockResult<ChainSpecT: ChainSpec> {
pub struct BuildBlockResult<ChainSpecT: EvmSpec> {
/// Built block
pub block: LocalBlock<ChainSpecT>,
/// State diff
pub state_diff: StateDiff,
}

/// A builder for constructing Ethereum blocks.
pub struct BlockBuilder<ChainSpecT: ChainSpec> {
pub struct BlockBuilder<ChainSpecT: EvmSpec> {
cfg: CfgEnv,
hardfork: ChainSpecT::Hardfork,
header: PartialHeader,
Expand All @@ -103,7 +102,7 @@ pub struct BlockBuilder<ChainSpecT: ChainSpec> {

impl<ChainSpecT> BlockBuilder<ChainSpecT>
where
ChainSpecT: ChainSpec<Hardfork: Debug>,
ChainSpecT: EvmSpec<Hardfork: Debug>,
{
/// Creates an intance of [`BlockBuilder`].
#[cfg_attr(feature = "tracing", tracing::instrument(skip_all))]
Expand Down Expand Up @@ -149,7 +148,7 @@ where
}
}

impl<ChainSpecT: ChainSpec> BlockBuilder<ChainSpecT> {
impl<ChainSpecT: EvmSpec> BlockBuilder<ChainSpecT> {
/// Retrieves the config of the block builder.
pub fn config(&self) -> &CfgEnv {
&self.cfg
Expand All @@ -176,7 +175,7 @@ impl<ChainSpecT: ChainSpec> BlockBuilder<ChainSpecT> {
}
}

impl<ChainSpecT: ChainSpec> BlockBuilder<ChainSpecT> {
impl<ChainSpecT: EvmSpec> BlockBuilder<ChainSpecT> {
/// Finalizes the block, returning the block and the callers of the
/// transactions.
#[cfg_attr(feature = "tracing", tracing::instrument(skip_all))]
Expand Down Expand Up @@ -248,7 +247,7 @@ impl<ChainSpecT: ChainSpec> BlockBuilder<ChainSpecT> {

impl<ChainSpecT> BlockBuilder<ChainSpecT>
where
ChainSpecT: ChainSpec<
ChainSpecT: EvmSpec<
Block: Default,
Transaction: Clone
+ Default
Expand Down Expand Up @@ -337,7 +336,7 @@ where
},
) = {
if let Some(debug_context) = debug_context {
let mut evm = Evm::<Wiring<ChainSpecT, _, _>>::builder()
let mut evm = Evm::<ChainSpecT::EvmWiring<_, _>>::builder()
.with_db(db)
.with_external_context(debug_context.data)
.with_env(env)

Check failure on line 342 in crates/edr_evm/src/block/builder.rs

View workflow job for this annotation

GitHub Actions / Check EDR

mismatched types
Expand Down Expand Up @@ -372,7 +371,7 @@ where
}
}
} else {
let mut evm = Evm::<Wiring<ChainSpecT, _, ()>>::builder()
let mut evm = Evm::<ChainSpecT::EvmWiring<_, ()>>::builder()
.with_db(db)
.with_env(env)

Check failure on line 376 in crates/edr_evm/src/block/builder.rs

View workflow job for this annotation

GitHub Actions / Check EDR

mismatched types
.build();
Expand Down
12 changes: 6 additions & 6 deletions crates/edr_evm/src/block/local.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ use revm::primitives::keccak256;

use crate::{
blockchain::BlockchainError,
chain_spec::{ChainSpec, SyncChainSpec},
chain_spec::{EvmSpec, SyncEvmSpec},
transaction::DetailedTransaction,
Block, SyncBlock,
};
Expand All @@ -25,7 +25,7 @@ use crate::{
#[derive(PartialEq, Eq, RlpEncodable)]
#[derive_where(Clone, Debug; ChainSpecT::ExecutionReceipt<FilterLog>, ChainSpecT::Transaction)]
#[rlp(trailing)]
pub struct LocalBlock<ChainSpecT: ChainSpec> {
pub struct LocalBlock<ChainSpecT: EvmSpec> {
header: block::Header,
transactions: Vec<ChainSpecT::Transaction>,
#[rlp(skip)]
Expand All @@ -38,7 +38,7 @@ pub struct LocalBlock<ChainSpecT: ChainSpec> {
hash: B256,
}

impl<ChainSpecT: ChainSpec> LocalBlock<ChainSpecT> {
impl<ChainSpecT: EvmSpec> LocalBlock<ChainSpecT> {
/// Constructs an empty block, i.e. no transactions.
pub fn empty(spec_id: ChainSpecT::Hardfork, partial_header: PartialHeader) -> Self {
let withdrawals = if spec_id.into() >= SpecId::SHANGHAI {
Expand Down Expand Up @@ -117,7 +117,7 @@ impl<ChainSpecT: ChainSpec> LocalBlock<ChainSpecT> {
}
}

impl<ChainSpecT: ChainSpec> Block<ChainSpecT> for LocalBlock<ChainSpecT> {
impl<ChainSpecT: EvmSpec> Block<ChainSpecT> for LocalBlock<ChainSpecT> {
type Error = BlockchainError<ChainSpecT>;

fn hash(&self) -> &B256 {
Expand Down Expand Up @@ -154,7 +154,7 @@ impl<ChainSpecT: ChainSpec> Block<ChainSpecT> for LocalBlock<ChainSpecT> {
}
}

fn transaction_to_block_receipts<ChainSpecT: ChainSpec>(
fn transaction_to_block_receipts<ChainSpecT: EvmSpec>(
block_hash: &B256,
block_number: u64,
receipts: Vec<TransactionReceipt<ChainSpecT::ExecutionReceipt<ExecutionLog>, ExecutionLog>>,
Expand Down Expand Up @@ -199,7 +199,7 @@ fn transaction_to_block_receipts<ChainSpecT: ChainSpec>(
impl<ChainSpecT> From<LocalBlock<ChainSpecT>>
for Arc<dyn SyncBlock<ChainSpecT, Error = BlockchainError<ChainSpecT>>>
where
ChainSpecT: SyncChainSpec,
ChainSpecT: SyncEvmSpec,
{
fn from(value: LocalBlock<ChainSpecT>) -> Self {
Arc::new(value)
Expand Down
Loading

0 comments on commit cfc180b

Please sign in to comment.