Skip to content
Merged
Show file tree
Hide file tree
Changes from 8 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
90 changes: 52 additions & 38 deletions Cargo.lock

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

20 changes: 10 additions & 10 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ foundry-linking = { path = "crates/linking" }
# solc & compilation utilities
foundry-block-explorers = { version = "0.20.0", default-features = false }
foundry-compilers = { version = "0.18.2", default-features = false }
foundry-fork-db = "0.17"
foundry-fork-db = "0.18"
solang-parser = { version = "=0.3.9", package = "foundry-solang-parser" }
solar-ast = { version = "=0.1.5", default-features = false }
solar-parse = { version = "=0.1.5", default-features = false }
Expand Down Expand Up @@ -262,13 +262,13 @@ op-alloy-rpc-types = "0.18.13"
op-alloy-flz = "0.13.1"

## revm
revm = { version = "28.0.0", default-features = false }
revm-inspectors = { version = "0.28.0", features = ["serde"] }
op-revm = { version = "9.0.1", default-features = false }
revm = { version = "29.0.0", default-features = false }
revm-inspectors = { version = "0.29.0", features = ["serde"] }
op-revm = { version = "10.0.0", default-features = false }

## alloy-evm
alloy-evm = "0.18.3"
alloy-op-evm = "0.18.3"
alloy-evm = "0.19.0"
alloy-op-evm = "0.19.0"

## cli
anstream = "0.6"
Expand Down Expand Up @@ -399,18 +399,18 @@ idna_adapter = "=1.1.0"
# alloy-transport-ws = { git = "https://github.com/alloy-rs/alloy", rev = "7fab7ee" }

## alloy-evm
# alloy-evm = { git = "https://github.com/alloy-rs/evm.git", rev = "7762adc" }
# alloy-op-evm = { git = "https://github.com/alloy-rs/evm.git", rev = "7762adc" }
# alloy-evm = { git = "https://github.com/alloy-rs/evm.git", rev = "3c6cebb" }
# alloy-op-evm = { git = "https://github.com/alloy-rs/evm.git", rev = "3c6cebb" }

## revm
# revm = { git = "https://github.com/bluealloy/revm.git", rev = "d9cda3a" }
# op-revm = { git = "https://github.com/bluealloy/revm.git", rev = "d9cda3a" }
# revm-inspectors = { git = "https://github.com/paradigmxyz/revm-inspectors.git", rev = "956bc98" }
# revm-inspectors = { git = "https://github.com/zerosnacks/revm-inspectors.git", rev = "74e215d" }

## foundry
# foundry-block-explorers = { git = "https://github.com/foundry-rs/block-explorers.git", rev = "e09cb89" }
# foundry-compilers = { git = "https://github.com/foundry-rs/compilers.git", rev = "e4a9b04" }
# foundry-fork-db = { git = "https://github.com/foundry-rs/foundry-fork-db", rev = "50683eb" }
# foundry-fork-db = { git = "https://github.com/foundry-rs/foundry-fork-db", rev = "eee6563" }

## solar
# solar-ast = { git = "https://github.com/paradigmxyz/solar.git", branch = "main" }
Expand Down
19 changes: 11 additions & 8 deletions crates/anvil/src/evm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,25 +6,27 @@ use alloy_evm::{

use foundry_evm_core::either_evm::EitherEvm;
use op_revm::OpContext;
use revm::{Inspector, precompile::PrecompileWithAddress};
use revm::{Inspector, precompile::Precompile};
use std::fmt::Debug;

/// Object-safe trait that enables injecting extra precompiles when using
/// `anvil` as a library.
pub trait PrecompileFactory: Send + Sync + Unpin + Debug {
/// Returns a set of precompiles to extend the EVM with.
fn precompiles(&self) -> Vec<(PrecompileWithAddress, u64)>;
fn precompiles(&self) -> Vec<(Precompile, u64)>;
}

/// Inject precompiles into the EVM dynamically.
pub fn inject_precompiles<DB, I>(
evm: &mut EitherEvm<DB, I, PrecompilesMap>,
precompiles: Vec<(PrecompileWithAddress, u64)>,
precompiles: Vec<(Precompile, u64)>,
) where
DB: Database,
I: Inspector<EthEvmContext<DB>> + Inspector<OpContext<DB>>,
{
for (PrecompileWithAddress(addr, func), gas) in precompiles {
for (precompile, gas) in precompiles {
let addr = *precompile.address();
let func = *precompile.precompile();
evm.precompiles_mut().apply_precompile(&addr, move |_| {
Some(DynPrecompile::from(move |input: PrecompileInput<'_>| func(input.data, gas)))
});
Expand All @@ -33,7 +35,7 @@ pub fn inject_precompiles<DB, I>(

#[cfg(test)]
mod tests {
use std::convert::Infallible;
use std::{borrow::Cow, convert::Infallible};

use alloy_evm::{EthEvm, Evm, EvmEnv, eth::EthEvmContext, precompiles::PrecompilesMap};
use alloy_op_evm::OpEvm;
Expand All @@ -49,7 +51,7 @@ mod tests {
inspector::NoOpInspector,
interpreter::interpreter::EthInterpreter,
precompile::{
PrecompileOutput, PrecompileResult, PrecompileSpecId, PrecompileWithAddress,
Precompile, PrecompileId, PrecompileOutput, PrecompileResult, PrecompileSpecId,
Precompiles,
},
primitives::hardfork::SpecId,
Expand All @@ -71,9 +73,10 @@ mod tests {
struct CustomPrecompileFactory;

impl PrecompileFactory for CustomPrecompileFactory {
fn precompiles(&self) -> Vec<(PrecompileWithAddress, u64)> {
fn precompiles(&self) -> Vec<(Precompile, u64)> {
vec![(
PrecompileWithAddress::from((
Precompile::from((
PrecompileId::Custom(Cow::Borrowed("custom_echo")),
PRECOMPILE_ADDR,
custom_echo_precompile as fn(&[u8], u64) -> PrecompileResult,
)),
Expand Down
Loading