Skip to content

Commit 0983417

Browse files
authored
Merge branch 'master' into refactor/anvil_txtype_enveloppe_macro
2 parents 6c7b300 + 2fe3a4b commit 0983417

File tree

8 files changed

+225
-231
lines changed

8 files changed

+225
-231
lines changed

Cargo.lock

Lines changed: 164 additions & 146 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/anvil/core/src/eth/transaction/mod.rs

Lines changed: 10 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -944,30 +944,16 @@ impl TypedReceipt {
944944
fn convert_receipt_to_rpc(
945945
receipt: ReceiptWithBloom<Receipt<alloy_primitives::Log>>,
946946
) -> ReceiptWithBloom<Receipt<alloy_rpc_types::Log>> {
947-
let rpc_logs: Vec<alloy_rpc_types::Log> = receipt
948-
.receipt
949-
.logs
950-
.into_iter()
951-
.map(|log| alloy_rpc_types::Log {
952-
inner: log,
953-
block_hash: None,
954-
block_number: None,
955-
block_timestamp: None,
956-
transaction_hash: None,
957-
transaction_index: None,
958-
log_index: None,
959-
removed: false,
960-
})
961-
.collect();
962-
963-
ReceiptWithBloom {
964-
receipt: Receipt {
965-
status: receipt.receipt.status,
966-
cumulative_gas_used: receipt.receipt.cumulative_gas_used,
967-
logs: rpc_logs,
968-
},
969-
logs_bloom: receipt.logs_bloom,
970-
}
947+
receipt.map_logs(|log| alloy_rpc_types::Log {
948+
inner: log,
949+
block_hash: None,
950+
block_number: None,
951+
block_timestamp: None,
952+
transaction_hash: None,
953+
transaction_index: None,
954+
log_index: None,
955+
removed: false,
956+
})
971957
}
972958

973959
impl TypedReceiptRpc {

crates/anvil/src/config.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1211,7 +1211,6 @@ impl NodeConfig {
12111211
.initial_backoff(self.fork_retry_backoff.as_millis() as u64)
12121212
.compute_units_per_second(self.compute_units_per_second)
12131213
.max_retry(self.fork_request_retries)
1214-
.initial_backoff(1000)
12151214
.headers(self.fork_headers.clone())
12161215
.build()
12171216
.wrap_err("failed to establish provider to fork url")?,

crates/anvil/src/eth/backend/mem/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -813,8 +813,8 @@ impl Backend {
813813
precompiles_map.extend(self.env.read().networks.precompiles());
814814

815815
if let Some(factory) = &self.precompile_factory {
816-
for (precompile, _) in &factory.precompiles() {
817-
precompiles_map.insert(precompile.id().name().to_string(), *precompile.address());
816+
for (address, precompile) in factory.precompiles() {
817+
precompiles_map.insert(precompile.precompile_id().to_string(), address);
818818
}
819819
}
820820

crates/anvil/src/evm.rs

Lines changed: 24 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,44 @@
11
use alloy_evm::{
22
Database, Evm,
33
eth::EthEvmContext,
4-
precompiles::{DynPrecompile, PrecompileInput, PrecompilesMap},
4+
precompiles::{DynPrecompile, PrecompilesMap},
55
};
6-
6+
use alloy_primitives::Address;
77
use foundry_evm::core::either_evm::EitherEvm;
88
use op_revm::OpContext;
9-
use revm::{Inspector, precompile::Precompile};
9+
use revm::Inspector;
1010
use std::fmt::Debug;
1111

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

1919
/// Inject custom precompiles into the EVM dynamically.
2020
pub fn inject_custom_precompiles<DB, I>(
2121
evm: &mut EitherEvm<DB, I, PrecompilesMap>,
22-
precompiles: Vec<(Precompile, u64)>,
22+
precompiles: Vec<(Address, DynPrecompile)>,
2323
) where
2424
DB: Database,
2525
I: Inspector<EthEvmContext<DB>> + Inspector<OpContext<DB>>,
2626
{
27-
for (precompile, gas) in precompiles {
28-
let addr = *precompile.address();
29-
let func = *precompile.precompile();
30-
evm.precompiles_mut().apply_precompile(&addr, move |_| {
31-
Some(DynPrecompile::from(move |input: PrecompileInput<'_>| func(input.data, gas)))
32-
});
27+
for (addr, precompile) in precompiles {
28+
evm.precompiles_mut().apply_precompile(&addr, move |_| Some(precompile));
3329
}
3430
}
3531

3632
#[cfg(test)]
3733
mod tests {
38-
use std::{borrow::Cow, convert::Infallible};
34+
use std::convert::Infallible;
3935

4036
use crate::{PrecompileFactory, inject_custom_precompiles};
41-
use alloy_evm::{EthEvm, Evm, EvmEnv, eth::EthEvmContext, precompiles::PrecompilesMap};
37+
use alloy_evm::{
38+
EthEvm, Evm, EvmEnv,
39+
eth::EthEvmContext,
40+
precompiles::{DynPrecompile, PrecompilesMap},
41+
};
4242
use alloy_op_evm::OpEvm;
4343
use alloy_primitives::{Address, Bytes, TxKind, U256, address};
4444
use foundry_evm::core::either_evm::EitherEvm;
@@ -52,10 +52,7 @@ mod tests {
5252
handler::{EthPrecompiles, instructions::EthInstructions},
5353
inspector::NoOpInspector,
5454
interpreter::interpreter::EthInterpreter,
55-
precompile::{
56-
Precompile, PrecompileId, PrecompileOutput, PrecompileResult, PrecompileSpecId,
57-
Precompiles,
58-
},
55+
precompile::{PrecompileOutput, PrecompileSpecId, Precompiles},
5956
primitives::hardfork::SpecId,
6057
};
6158

@@ -73,24 +70,21 @@ mod tests {
7370
struct CustomPrecompileFactory;
7471

7572
impl PrecompileFactory for CustomPrecompileFactory {
76-
fn precompiles(&self) -> Vec<(Precompile, u64)> {
73+
fn precompiles(&self) -> Vec<(Address, DynPrecompile)> {
74+
use alloy_evm::precompiles::PrecompileInput;
7775
vec![(
78-
Precompile::from((
79-
PrecompileId::Custom(Cow::Borrowed("custom_echo")),
80-
PRECOMPILE_ADDR,
81-
custom_echo_precompile as fn(&[u8], u64) -> PrecompileResult,
82-
)),
83-
1000,
76+
PRECOMPILE_ADDR,
77+
DynPrecompile::from(|input: PrecompileInput<'_>| {
78+
Ok(PrecompileOutput {
79+
bytes: Bytes::copy_from_slice(input.data),
80+
gas_used: 0,
81+
reverted: false,
82+
})
83+
}),
8484
)]
8585
}
8686
}
8787

88-
/// Custom precompile that echoes the input data.
89-
/// In this example it uses `0xdeadbeef` as the input data, returning it as output.
90-
fn custom_echo_precompile(input: &[u8], _gas_limit: u64) -> PrecompileResult {
91-
Ok(PrecompileOutput { bytes: Bytes::copy_from_slice(input), gas_used: 0, reverted: false })
92-
}
93-
9488
/// Creates a new EVM instance with the custom precompile factory.
9589
fn create_eth_evm(
9690
spec: SpecId,

crates/anvil/src/hardfork.rs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -54,11 +54,10 @@ pub fn spec_id_from_ethereum_hardfork(hardfork: EthereumHardfork) -> SpecId {
5454
EthereumHardfork::Cancun => SpecId::CANCUN,
5555
EthereumHardfork::Prague => SpecId::PRAGUE,
5656
EthereumHardfork::Osaka => SpecId::OSAKA,
57-
EthereumHardfork::Bpo1
58-
| EthereumHardfork::Bpo2
59-
| EthereumHardfork::Bpo3
60-
| EthereumHardfork::Bpo4
61-
| EthereumHardfork::Bpo5 => unimplemented!(),
57+
EthereumHardfork::Bpo1 | EthereumHardfork::Bpo2 => SpecId::OSAKA,
58+
EthereumHardfork::Bpo3 | EthereumHardfork::Bpo4 | EthereumHardfork::Bpo5 => {
59+
unimplemented!()
60+
}
6261
f => unreachable!("unimplemented {}", f),
6362
}
6463
}
@@ -75,7 +74,7 @@ pub fn spec_id_from_optimism_hardfork(hardfork: OpHardfork) -> OpSpecId {
7574
OpHardfork::Holocene => OpSpecId::HOLOCENE,
7675
OpHardfork::Isthmus => OpSpecId::ISTHMUS,
7776
OpHardfork::Interop => OpSpecId::INTEROP,
78-
OpHardfork::Jovian => OpSpecId::ISTHMUS,
77+
OpHardfork::Jovian => OpSpecId::JOVIAN,
7978
f => unreachable!("unimplemented {}", f),
8079
}
8180
}

crates/anvil/tests/it/fork.rs

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,7 @@ use foundry_config::Config;
2626
use foundry_evm_networks::NetworkConfigs;
2727
use foundry_test_utils::rpc::{self, next_http_rpc_endpoint, next_rpc_endpoint};
2828
use futures::StreamExt;
29-
use revm::precompile::{Precompile, PrecompileId, PrecompileOutput, PrecompileResult};
3029
use std::{
31-
borrow::Cow,
3230
collections::{BTreeMap, BTreeSet},
3331
sync::Arc,
3432
thread::sleep,
@@ -1868,22 +1866,22 @@ async fn test_config_with_osaka_hardfork() {
18681866

18691867
#[tokio::test(flavor = "multi_thread")]
18701868
async fn test_config_with_osaka_hardfork_with_precompile_factory() {
1871-
fn custom_echo_precompile(input: &[u8], _gas_limit: u64) -> PrecompileResult {
1872-
Ok(PrecompileOutput { bytes: Bytes::copy_from_slice(input), gas_used: 0, reverted: false })
1873-
}
1874-
18751869
#[derive(Debug)]
18761870
struct CustomPrecompileFactory;
18771871

18781872
impl PrecompileFactory for CustomPrecompileFactory {
1879-
fn precompiles(&self) -> Vec<(Precompile, u64)> {
1873+
fn precompiles(&self) -> Vec<(Address, alloy_evm::precompiles::DynPrecompile)> {
18801874
vec![(
1881-
Precompile::from((
1882-
PrecompileId::Custom(Cow::Borrowed("custom_echo")),
1883-
address!("0x0000000000000000000000000000000000000071"),
1884-
custom_echo_precompile as fn(&[u8], u64) -> PrecompileResult,
1885-
)),
1886-
1000,
1875+
address!("0x0000000000000000000000000000000000000071"),
1876+
alloy_evm::precompiles::DynPrecompile::from(
1877+
|input: alloy_evm::precompiles::PrecompileInput<'_>| {
1878+
Ok(revm::precompile::PrecompileOutput {
1879+
bytes: Bytes::copy_from_slice(input.data),
1880+
gas_used: 0,
1881+
reverted: false,
1882+
})
1883+
},
1884+
),
18871885
)]
18881886
}
18891887
}

flake.lock

Lines changed: 9 additions & 9 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)