Skip to content
Merged
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,213 changes: 1,418 additions & 795 deletions Cargo.lock

Large diffs are not rendered by default.

57 changes: 28 additions & 29 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -42,51 +42,50 @@ use_self = "warn"
pevm = { path = "crates/pevm", features = ["full"] }

# alloy
alloy-consensus = "0.9.2"
alloy-primitives = { version = "0.8.18", features = [
alloy-consensus = "0.12.6"
alloy-primitives = { version = "0.8.25", features = [
"asm-keccak",
"map-fxhash",
] }
alloy-provider = "0.9.2"
alloy-rlp = "0.3.10"
alloy-rpc-types-eth = "0.9.2"
alloy-transport = "0.9.2"
alloy-transport-http = "0.9.2"
alloy-trie = "0.7.8"
alloy-provider = "0.12.6"
alloy-rlp = "0.3.12"
alloy-rpc-types-eth = "0.12.6"
alloy-transport = "0.12.6"
alloy-trie = "0.7.9"

# Will remove [revm] with https://github.com/risechain/pevm/issues/382.
revm = { git = "https://github.com/risechain/revm", rev = "ac75f1ef59ecae15238f5a2e94e71c3bcc01d45c", features = [
revm = { git = "https://github.com/risechain/revm", rev = "a79e833be41199a140dc85a222141c4bdf0b9aa5", features = [
"serde",
] }
revme = { git = "https://github.com/risechain/revm", rev = "ac75f1ef59ecae15238f5a2e94e71c3bcc01d45c" }
revme = { git = "https://github.com/risechain/revm", rev = "a79e833be41199a140dc85a222141c4bdf0b9aa5" }

# OP
op-alloy-consensus = "0.9.2"
op-alloy-network = "0.9.2"
op-alloy-rpc-types = "0.9.2"
op-alloy-consensus = "0.11.3"
op-alloy-network = "0.11.3"
op-alloy-rpc-types = "0.11.3"

# Allocators
rpmalloc = { version = "0.2.2", features = ["thread_cache", "global_cache"] }
snmalloc-rs = "0.3.7"
tikv-jemallocator = "0.6.0"
snmalloc-rs = "0.3.8"
tikv-jemallocator = "0.6.1"

bincode = "1.3.3"
# We can roll our own but [revm] depends on this anyway.
bitflags = "2.7.0"
bitflags = "2.9.4"
bitvec = "1.0.1"
clap = { version = "4.5.26", features = ["derive"] }
color-eyre = "0.6.3"
criterion = "0.5.1"
clap = { version = "4.5.51", features = ["derive"] }
color-eyre = "0.6.5"
criterion = "0.7.0"
dashmap = "6.1.0"
flate2 = "1.0.35"
hashbrown = "0.15.2"
flate2 = "1.1.5"
hashbrown = "0.15.5"
rand = "0.8.5"
rayon = "1.10.0"
reqwest = "0.12.12"
rustc-hash = "2.1.0"
serde = "1.0.217"
serde_json = "1.0.135"
smallvec = "1.13.2"
thiserror = "2.0.10"
tokio = { version = "1.43.0", features = ["rt-multi-thread"] }
rayon = "1.11.0"
reqwest = "0.12.24"
rustc-hash = "2.1.1"
serde = "=1.0.221"
serde_json = "1.0.145"
smallvec = "1.15.1"
thiserror = "2.0.17"
tokio = { version = "1.48.0", features = ["rt-multi-thread"] }
walkdir = "2.5.0"
9 changes: 5 additions & 4 deletions bins/fetch/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ use std::{

use alloy_consensus::constants::KECCAK_EMPTY;
use alloy_primitives::{Address, B256};
use alloy_provider::{Provider, ProviderBuilder};
use alloy_rpc_types_eth::{BlockId, BlockTransactionsKind};
use alloy_provider::{Provider, ProviderBuilder, network::Ethereum};
use alloy_rpc_types_eth::BlockId;
use clap::Parser;
use color_eyre::eyre::{Result, WrapErr, eyre};
use flate2::{Compression, bufread::GzDecoder, write::GzEncoder};
Expand All @@ -35,11 +35,12 @@ async fn main() -> Result<()> {
let Fetch { block_id, rpc_url } = Fetch::parse();

// Define provider.
let provider = ProviderBuilder::new().on_http(rpc_url);
let provider = ProviderBuilder::<_, _, Ethereum>::default().on_http(rpc_url);

// Retrieve block from provider.
let block = provider
.get_block(block_id, BlockTransactionsKind::Full)
.get_block(block_id)
.full()
.await
.context("Failed to fetch block from provider")?
.ok_or_else(|| eyre!("No block found for ID: {block_id:?}"))?;
Expand Down
8 changes: 1 addition & 7 deletions crates/pevm/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,7 @@ optimism = [
"dep:op-alloy-rpc-types",
]

rpc-storage = [
"dep:alloy-transport",
"dep:alloy-transport-http",
"dep:reqwest",
"dep:tokio",
]
rpc-storage = ["dep:alloy-transport", "dep:reqwest", "dep:tokio"]

global-alloc = ["dep:rpmalloc", "dep:snmalloc-rs", "dep:tikv-jemallocator"]

Expand Down Expand Up @@ -50,7 +45,6 @@ op-alloy-rpc-types = { workspace = true, optional = true }

# Storage RPC feature dependencies
alloy-transport = { workspace = true, optional = true }
alloy-transport-http = { workspace = true, optional = true }
reqwest = { workspace = true, optional = true }
tokio = { workspace = true, optional = true }

Expand Down
4 changes: 2 additions & 2 deletions crates/pevm/benches/gigagas.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@

// TODO: More fancy benchmarks & plots.

use std::{num::NonZeroUsize, sync::Arc, thread};
use std::{hint::black_box, num::NonZeroUsize, sync::Arc, thread};

use alloy_primitives::{Address, U160, U256};
use criterion::{Criterion, black_box, criterion_group, criterion_main};
use criterion::{Criterion, criterion_group, criterion_main};
use pevm::{
Bytecodes, ChainState, EvmAccount, InMemoryStorage, Pevm, chain::PevmEthereum,
execute_revm_sequential,
Expand Down
4 changes: 2 additions & 2 deletions crates/pevm/benches/mainnet.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
//! Benchmark mainnet blocks with needed state loaded in memory.

// TODO: More fancy benchmarks & plots.
use std::{num::NonZeroUsize, thread};
use std::{hint::black_box, num::NonZeroUsize, thread};

use criterion::{Criterion, black_box, criterion_group, criterion_main};
use criterion::{Criterion, criterion_group, criterion_main};
use pevm::{Pevm, chain::PevmEthereum};

// Better project structure
Expand Down
5 changes: 2 additions & 3 deletions crates/pevm/src/chain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
use std::error::Error as StdError;
use std::fmt::Debug;

use alloy_consensus::{Signed, TxLegacy};
use alloy_consensus::{Signed, TxLegacy, transaction::Recovered};
use alloy_primitives::{Address, B256};
use alloy_rpc_types_eth::{BlockTransactions, Header, Transaction};
use revm::{
Expand Down Expand Up @@ -68,8 +68,7 @@ pub trait PevmChain: Debug {
/// Mock RPC transaction for testing.
fn mock_rpc_tx(envelope: Self::Envelope, from: Address) -> Transaction<Self::Envelope> {
Transaction {
inner: envelope,
from,
inner: Recovered::new_unchecked(envelope, from),
block_hash: None,
block_number: None,
transaction_index: None,
Expand Down
2 changes: 1 addition & 1 deletion crates/pevm/src/chain/ethereum.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ impl PevmChain for PevmEthereum {
// TODO: Properly test this.
fn get_tx_env(&self, tx: &Self::Transaction) -> Result<TxEnv, EthereumTransactionParsingError> {
Ok(TxEnv {
caller: tx.from,
caller: tx.inner.signer(),
gas_limit: tx.gas_limit(),
gas_price: get_ethereum_gas_price(&tx.inner)?,
gas_priority_fee: tx.max_priority_fee_per_gas().map(U256::from),
Expand Down
4 changes: 2 additions & 2 deletions crates/pevm/src/chain/optimism.rs
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ impl PevmChain for PevmOptimism {
OpTxType::Deposit => {
let account = tx_result
.state
.get(&tx.from)
.get(tx.inner.inner.signer_ref())
.and_then(Option::as_ref)
.ok_or(CalculateReceiptRootError::OpDepositMissingSender)?;
let receipt = OpDepositReceipt {
Expand Down Expand Up @@ -234,7 +234,7 @@ impl PevmChain for PevmOptimism {
fn get_tx_env(&self, tx: &Self::Transaction) -> Result<TxEnv, OptimismTransactionParsingError> {
Ok(TxEnv {
optimism: get_optimism_fields(&tx.inner.inner)?,
caller: tx.from,
caller: tx.inner.inner.signer(),
gas_limit: tx.gas_limit(),
gas_price: get_optimism_gas_price(&tx.inner.inner)?,
gas_priority_fee: tx.max_priority_fee_per_gas().map(U256::from),
Expand Down
16 changes: 5 additions & 11 deletions crates/pevm/src/storage/rpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,10 @@ use std::{

use alloy_primitives::{Address, B256, U256};
use alloy_provider::{Network, Provider, RootProvider, network::BlockResponse};
use alloy_rpc_types_eth::{BlockId, BlockNumberOrTag, BlockTransactionsKind};
use alloy_rpc_types_eth::{BlockId, BlockNumberOrTag};
use alloy_transport::TransportError;
use alloy_transport_http::Http;
use hashbrown::HashMap;
use op_alloy_network::primitives::HeaderResponse;
use reqwest::Client;
use revm::{
precompile::{PrecompileSpecId, Precompiles},
primitives::{Bytecode, SpecId},
Expand All @@ -26,12 +24,10 @@ use crate::{AccountBasic, EvmAccount, Storage};

use super::{BlockHashes, Bytecodes, ChainState, EvmCode};

type RpcProvider<N> = RootProvider<Http<Client>, N>;

/// A storage that fetches state data via RPC for execution.
#[derive(Debug)]
pub struct RpcStorage<N: Network> {
provider: RpcProvider<N>,
provider: RootProvider<N>,
block_id: BlockId,
precompiles: &'static Precompiles,
/// `OnceLock` is used to lazy-initialize a Tokio multi-threaded runtime if no
Expand All @@ -53,7 +49,7 @@ pub struct RpcStorage<N: Network> {

impl<N: Network> RpcStorage<N> {
/// Create a new RPC Storage
pub fn new(provider: RpcProvider<N>, spec_id: SpecId, block_id: BlockId) -> Self {
pub fn new(provider: RootProvider<N>, spec_id: SpecId, block_id: BlockId) -> Self {
Self {
provider,
precompiles: Precompiles::new(PrecompileSpecId::from_spec_id(spec_id)),
Expand Down Expand Up @@ -229,10 +225,8 @@ impl<N: Network> Storage for RpcStorage<N> {

let block_hash = self
.block_on(self.fetch(|| {
self.provider.get_block_by_number(
BlockNumberOrTag::Number(*number),
BlockTransactionsKind::Hashes,
)
self.provider
.get_block_by_number(BlockNumberOrTag::Number(*number))
}))
.map(|block| block.unwrap().header().hash())?;

Expand Down
7 changes: 4 additions & 3 deletions crates/pevm/tests/mainnet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,14 @@ where
C: pevm::chain::PevmChain + PartialEq + Send + Sync,
{
use alloy_provider::{Provider, ProviderBuilder};
use alloy_rpc_types_eth::{BlockId, BlockTransactionsKind};
use alloy_rpc_types_eth::BlockId;

let provider = ProviderBuilder::new().network::<C::Network>().on_http(url);
let provider = ProviderBuilder::<_, _, C::Network>::default().on_http(url);

for &block_number in block_numbers {
let block = provider
.get_block(BlockId::number(block_number), BlockTransactionsKind::Full)
.get_block(BlockId::number(block_number))
.full()
.await
.unwrap()
.unwrap()
Expand Down
7 changes: 2 additions & 5 deletions crates/pevm/tests/snapshot_data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

use alloy_primitives::B256;
use alloy_provider::{Provider, ProviderBuilder};
use alloy_rpc_types_eth::{BlockNumberOrTag, BlockTransactionsKind};
use alloy_rpc_types_eth::BlockNumberOrTag;
use std::collections::BTreeMap;
use std::fs::File;

Expand All @@ -21,10 +21,7 @@ async fn snapshotted_mainnet_block_hashes() {

for (block_number, snapshotted_hash) in block_hashes {
let block = provider
.get_block_by_number(
BlockNumberOrTag::Number(block_number),
BlockTransactionsKind::Hashes,
)
.get_block_by_number(BlockNumberOrTag::Number(block_number))
.await
.unwrap()
.unwrap();
Expand Down