Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 873b506

Browse files
authoredMay 22, 2025··
chore(deps): upgrade to revm23/alloy1.0.5 (#104)
* chore(deps): upgrade to revm22/alloy0.14 * chore: alloy1.0.5/revm23 fixes * chore: more fixes * chore: keep optional validation * chore: nicer auth list wrangling * fix: proper selector parsing * chore: no underscore * chore: validate on example * chore: keep selector as option * feat: version bump * chore: vendor alloydb, fix example * chore: clippy * chore: docs * chore: improve code style * chore: backticks * chore: more docs * chore: do not use SAFETY disclaimers, as its not unsafe code
1 parent 0f21f79 commit 873b506

File tree

13 files changed

+285
-79
lines changed

13 files changed

+285
-79
lines changed
 

‎Cargo.toml

Lines changed: 25 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "trevm"
3-
version = "0.20.11"
3+
version = "0.23.0"
44
rust-version = "1.83.0"
55
edition = "2021"
66
authors = ["init4"]
@@ -26,24 +26,37 @@ use-self = "warn"
2626
option-if-let-else = "warn"
2727
redundant-clone = "warn"
2828

29+
[[example]]
30+
name = "basic_transact"
31+
32+
[[example]]
33+
name = "fork_ref_transact"
34+
required-features = ["alloy-db"]
35+
2936
[dependencies]
30-
alloy = { version = "0.12.6", default-features = false, features = ["consensus", "rpc-types-mev", "eips", "k256", "std", "rlp", "sol-types"] }
37+
alloy = { version = "1.0.5", default-features = false, features = [
38+
"consensus",
39+
"rpc-types-mev",
40+
"eips",
41+
"k256",
42+
"std",
43+
"rlp",
44+
"sol-types",
45+
] }
3146

32-
revm = { version = "20.0.0", default-features = false }
47+
revm = { version = "23.1.0", default-features = false }
3348

3449
dashmap = { version = "6.1.0", optional = true }
35-
tracing = { version = "0.1.41", optional = true}
50+
tracing = { version = "0.1.41", optional = true }
3651
thiserror = "2.0.11"
3752

53+
tokio = { version = "1.44", optional = true }
54+
3855
[dev-dependencies]
39-
revm = { version = "20.0.0", features = [
40-
"serde-json",
41-
"std",
42-
"alloydb",
43-
] }
56+
revm = { version = "23.1.0", features = ["serde-json", "std", "alloydb"] }
4457
trevm = { path = ".", features = ["test-utils"] }
4558

46-
alloy = { version = "0.12.6", features = ["providers"]}
59+
alloy = { version = "1.0.5", features = ["providers", "transports"] }
4760

4861
# misc
4962
eyre = "0.6"
@@ -63,6 +76,8 @@ default = [
6376
"revm/secp256k1",
6477
]
6578

79+
alloy-db = ["dep:tokio"]
80+
6681
call = ["optional_eip3607", "optional_no_base_fee"]
6782

6883
concurrent-db = ["dep:dashmap"]

‎examples/fork_ref_transact.rs

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
//! This example demonstrates how to query storage slots of a contract, using
2-
//! [`AlloyDB`].
3-
4-
//! This example is currently disabled while waiting for revm @ 14.0.4
2+
//! [`AlloyDb`].
53
64
use alloy::{
75
eips::BlockId,
@@ -11,10 +9,7 @@ use alloy::{
119
sol_types::SolCall,
1210
};
1311
use revm::{context::TxEnv, database::WrapDatabaseAsync};
14-
use trevm::{
15-
revm::database::{AlloyDB, CacheDB},
16-
NoopBlock, NoopCfg, TrevmBuilder, Tx,
17-
};
12+
use trevm::{db::alloy::AlloyDb, revm::database::CacheDB, NoopBlock, NoopCfg, TrevmBuilder, Tx};
1813

1914
sol! {
2015
#[allow(missing_docs)]
@@ -42,7 +37,7 @@ async fn main() -> eyre::Result<()> {
4237
// create ethers client and wrap it in Arc<M>
4338
let rpc_url = "https://mainnet.infura.io/v3/c60b0bb42f8a4c6481ecd229eddaca27";
4439

45-
let client = ProviderBuilder::new().on_http(rpc_url.parse()?);
40+
let client = ProviderBuilder::new().connect_http(rpc_url.parse()?);
4641

4742
// ----------------------------------------------------------- //
4843
// Storage slots of UniV2Pair contract //
@@ -57,7 +52,7 @@ async fn main() -> eyre::Result<()> {
5752
// =========================================================== //
5853

5954
// initialize new AlloyDB
60-
let alloydb = WrapDatabaseAsync::new(AlloyDB::new(client, BlockId::default())).unwrap();
55+
let alloydb = WrapDatabaseAsync::new(AlloyDb::new(client, BlockId::default())).unwrap();
6156

6257
// initialise empty in-memory-db
6358
let cache_db = CacheDB::new(alloydb);
@@ -78,7 +73,7 @@ async fn main() -> eyre::Result<()> {
7873
let output = evm.output().expect("Execution halted");
7974

8075
// decode bytes to reserves + ts via alloy's abi decode
81-
let return_vals = getReservesCall::abi_decode_returns(output, true)?;
76+
let return_vals = getReservesCall::abi_decode_returns_validate(output)?;
8277

8378
// Print emulated getReserves() call output
8479
println!("Reserve0: {:#?}", return_vals.reserve0);

‎src/db/alloy.rs

Lines changed: 154 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,154 @@
1+
use alloy::{
2+
eips::BlockId,
3+
primitives::{StorageValue, U256},
4+
providers::{
5+
network::{primitives::HeaderResponse, BlockResponse},
6+
Network, Provider,
7+
},
8+
transports::TransportError,
9+
};
10+
use core::error::Error;
11+
use revm::{
12+
database_interface::{async_db::DatabaseAsyncRef, DBErrorMarker},
13+
primitives::{Address, B256},
14+
state::{AccountInfo, Bytecode},
15+
};
16+
use std::fmt::Display;
17+
18+
/// A type alias for the storage key used in the database.
19+
/// We use this instead of alloy's [`alloy::primitives::StorageKey`] as Revm requires
20+
/// the actual type to be an [`U256`] instead of a [`B256`].
21+
pub type StorageKey = U256;
22+
23+
/// An error that can occur when using [`AlloyDb`].
24+
#[derive(Debug)]
25+
pub struct DBTransportError(pub TransportError);
26+
27+
impl DBErrorMarker for DBTransportError {}
28+
29+
impl Display for DBTransportError {
30+
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
31+
write!(f, "Transport error: {}", self.0)
32+
}
33+
}
34+
35+
impl Error for DBTransportError {}
36+
37+
impl From<TransportError> for DBTransportError {
38+
fn from(e: TransportError) -> Self {
39+
Self(e)
40+
}
41+
}
42+
43+
/// An alloy-powered REVM [`Database`][revm::database_interface::Database].
44+
///
45+
/// When accessing the database, it'll use the given provider to fetch the corresponding account's data.
46+
#[derive(Debug)]
47+
pub struct AlloyDb<N: Network, P: Provider<N>> {
48+
/// The provider to fetch the data from.
49+
provider: P,
50+
/// The block number on which the queries will be based on.
51+
block_number: BlockId,
52+
_marker: core::marker::PhantomData<fn() -> N>,
53+
}
54+
55+
impl<N: Network, P: Provider<N>> AlloyDb<N, P> {
56+
/// Creates a new AlloyDB instance, with a [`Provider`] and a block.
57+
pub fn new(provider: P, block_number: BlockId) -> Self {
58+
Self { provider, block_number, _marker: core::marker::PhantomData }
59+
}
60+
61+
/// Sets the block number on which the queries will be based on.
62+
pub const fn set_block_number(&mut self, block_number: BlockId) {
63+
self.block_number = block_number;
64+
}
65+
}
66+
67+
impl<N: Network, P: Provider<N>> DatabaseAsyncRef for AlloyDb<N, P> {
68+
type Error = DBTransportError;
69+
70+
async fn basic_async_ref(&self, address: Address) -> Result<Option<AccountInfo>, Self::Error> {
71+
let nonce = self.provider.get_transaction_count(address).block_id(self.block_number);
72+
let balance = self.provider.get_balance(address).block_id(self.block_number);
73+
let code = self.provider.get_code_at(address).block_id(self.block_number);
74+
75+
let (nonce, balance, code) = tokio::join!(nonce, balance, code,);
76+
77+
let balance = balance?;
78+
let code = Bytecode::new_raw(code?.0.into());
79+
let code_hash = code.hash_slow();
80+
let nonce = nonce?;
81+
82+
Ok(Some(AccountInfo::new(balance, nonce, code_hash, code)))
83+
}
84+
85+
async fn block_hash_async_ref(&self, number: u64) -> Result<B256, Self::Error> {
86+
let block = self
87+
.provider
88+
// We know number <= u64::MAX, so we can safely convert it to u64
89+
.get_block_by_number(number.into())
90+
.await?;
91+
// If the number is given, the block is supposed to be finalized, so unwrapping is safe.
92+
Ok(B256::new(*block.unwrap().header().hash()))
93+
}
94+
95+
async fn code_by_hash_async_ref(&self, _code_hash: B256) -> Result<Bytecode, Self::Error> {
96+
panic!("This should not be called, as the code is already loaded");
97+
// This is not needed, as the code is already loaded with basic_ref
98+
}
99+
100+
async fn storage_async_ref(
101+
&self,
102+
address: Address,
103+
index: StorageKey,
104+
) -> Result<StorageValue, Self::Error> {
105+
Ok(self.provider.get_storage_at(address, index).block_id(self.block_number).await?)
106+
}
107+
}
108+
109+
#[cfg(test)]
110+
mod tests {
111+
use super::*;
112+
use alloy::providers::ProviderBuilder;
113+
use revm::database_interface::{DatabaseRef, WrapDatabaseAsync};
114+
115+
#[test]
116+
#[ignore = "flaky RPC"]
117+
fn can_get_basic() {
118+
let client = ProviderBuilder::new().connect_http(
119+
"https://mainnet.infura.io/v3/c60b0bb42f8a4c6481ecd229eddaca27".parse().unwrap(),
120+
);
121+
let alloydb = AlloyDb::new(client, BlockId::from(16148323));
122+
let wrapped_alloydb = WrapDatabaseAsync::new(alloydb).unwrap();
123+
124+
// ETH/USDT pair on Uniswap V2
125+
let address: Address = "0x0d4a11d5EEaaC28EC3F61d100daF4d40471f1852".parse().unwrap();
126+
127+
let acc_info = wrapped_alloydb.basic_ref(address).unwrap().unwrap();
128+
assert!(acc_info.exists());
129+
}
130+
}
131+
132+
// This code has been reproduced from the original AlloyDB implementation
133+
// contained in revm.
134+
// <https://github.com/bluealloy/revm>
135+
// The original license is included below:
136+
//
137+
// MIT License
138+
// Copyright (c) 2021-2025 draganrakita
139+
// Permission is hereby granted, free of charge, to any person obtaining a copy
140+
// of this software and associated documentation files (the "Software"), to deal
141+
// in the Software without restriction, including without limitation the rights
142+
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
143+
// copies of the Software, and to permit persons to whom the Software is
144+
// furnished to do so, subject to the following conditions:
145+
// The above copyright notice and this permission notice shall be included in all
146+
// copies or substantial portions of the Software.
147+
//
148+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
149+
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
150+
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
151+
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
152+
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
153+
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
154+
// SOFTWARE.

‎src/db/mod.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,7 @@ pub use traits::{ArcUpgradeError, CachingDb, StateAcc, TryCachingDb, TryStateAcc
99
/// Cache-on-write database. A memory cache that caches only on write, not on
1010
/// read. Intended to wrap some other caching database.
1111
pub mod cow;
12+
13+
#[cfg(feature = "alloy-db")]
14+
/// Alloy-powered revm Database implementation that fetches data over the network.
15+
pub mod alloy;

‎src/driver/alloy.rs

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,10 @@ use crate::{
44
trevm_bail, trevm_ensure, trevm_try, Block, BundleDriver, DriveBundleResult,
55
};
66
use alloy::{
7-
consensus::{Transaction, TxEip4844Variant, TxEnvelope},
7+
consensus::{
8+
crypto::RecoveryError, transaction::SignerRecoverable, Transaction, TxEip4844Variant,
9+
TxEnvelope,
10+
},
811
eips::{eip2718::Decodable2718, BlockNumberOrTag},
912
primitives::{bytes::Buf, keccak256, Address, Bytes, TxKind, U256},
1013
rpc::types::mev::{
@@ -35,7 +38,7 @@ pub enum BundleError<Db: Database> {
3538
/// An error occurred while decoding a transaction contained in the bundle.
3639
TransactionDecodingError(alloy::eips::eip2718::Eip2718Error),
3740
/// An error occurred while recovering the sender of a transaction.
38-
TransactionSenderRecoveryError(alloy::primitives::SignatureError),
41+
TransactionSenderRecoveryError(alloy::consensus::crypto::RecoveryError),
3942
/// An error occurred while running the EVM.
4043
EVMError {
4144
/// The error that occurred while running the EVM.
@@ -71,7 +74,7 @@ impl<Db: Database> From<alloy::eips::eip2718::Eip2718Error> for BundleError<Db>
7174

7275
impl<Db: Database> From<alloy::primitives::SignatureError> for BundleError<Db> {
7376
fn from(err: alloy::primitives::SignatureError) -> Self {
74-
Self::TransactionSenderRecoveryError(err)
77+
Self::TransactionSenderRecoveryError(err.into())
7578
}
7679
}
7780

@@ -91,6 +94,12 @@ impl<Db: Database> std::error::Error for BundleError<Db> {
9194
}
9295
}
9396

97+
impl<Db: Database> From<RecoveryError> for BundleError<Db> {
98+
fn from(err: RecoveryError) -> Self {
99+
Self::TransactionSenderRecoveryError(err)
100+
}
101+
}
102+
94103
impl<Db: Database> core::fmt::Debug for BundleError<Db> {
95104
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
96105
match self {

‎src/evm.rs

Lines changed: 32 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -96,12 +96,12 @@ where
9696

9797
/// Deconstruct the [`Trevm`] into the backing DB, dropping all other types.
9898
pub fn into_db(self) -> Db {
99-
self.inner.data.ctx.journaled_state.database
99+
self.inner.ctx.journaled_state.database
100100
}
101101

102102
/// Get the id of the currently running hardfork spec.
103103
pub fn spec_id(&self) -> SpecId {
104-
self.inner.data.ctx.cfg().spec()
104+
self.inner.ctx.cfg().spec()
105105
}
106106

107107
/// Set the [SpecId], modifying the EVM handlers accordingly. This function
@@ -712,7 +712,7 @@ where
712712
/// [`Eip-170`]: https://eips.ethereum.org/EIPS/eip-170
713713
pub fn set_code_size_limit(&mut self, limit: usize) -> Option<usize> {
714714
let mut csl = None;
715-
self.inner.data.ctx.modify_cfg(|cfg| {
715+
self.inner.ctx.modify_cfg(|cfg| {
716716
csl = cfg.limit_contract_code_size.replace(limit);
717717
});
718718
csl
@@ -724,7 +724,7 @@ where
724724
/// [`Eip-170`]: https://eips.ethereum.org/EIPS/eip-170
725725
pub fn disable_code_size_limit(&mut self) -> Option<usize> {
726726
let mut csl = None;
727-
self.inner.data.ctx.modify_cfg(|cfg| csl = cfg.limit_contract_code_size.take());
727+
self.inner.ctx.modify_cfg(|cfg| csl = cfg.limit_contract_code_size.take());
728728
csl
729729
}
730730

@@ -766,7 +766,7 @@ where
766766
cfg.fill_cfg(&mut self.inner);
767767

768768
let mut this = f(self);
769-
this.inner.data.ctx.modify_cfg(|cfg| *cfg = previous);
769+
this.inner.ctx.modify_cfg(|cfg| *cfg = previous);
770770
this
771771
}
772772

@@ -810,10 +810,7 @@ where
810810
#[cfg(feature = "memory_limit")]
811811
pub fn set_memory_limit(&mut self, new_limit: u64) -> u64 {
812812
let mut ml = 0;
813-
self.inner
814-
.data
815-
.ctx
816-
.modify_cfg(|cfg| ml = core::mem::replace(&mut cfg.memory_limit, new_limit));
813+
self.inner.ctx.modify_cfg(|cfg| ml = core::mem::replace(&mut cfg.memory_limit, new_limit));
817814
ml
818815
}
819816

@@ -822,13 +819,13 @@ where
822819
/// execution doesn't fail.
823820
#[cfg(feature = "optional_balance_check")]
824821
pub fn disable_balance_check(&mut self) {
825-
self.inner.data.ctx.modify_cfg(|cfg| cfg.disable_balance_check = true)
822+
self.inner.ctx.modify_cfg(|cfg| cfg.disable_balance_check = true)
826823
}
827824

828825
/// Enable balance checks. See [`Self::disable_balance_check`].
829826
#[cfg(feature = "optional_balance_check")]
830827
pub fn enable_balance_check(&mut self) {
831-
self.inner.data.ctx.modify_cfg(|cfg| cfg.disable_balance_check = false)
828+
self.inner.ctx.modify_cfg(|cfg| cfg.disable_balance_check = false)
832829
}
833830

834831
/// Run a closure with balance checks disabled, then restore the previous
@@ -841,7 +838,7 @@ where
841838
let previous = self.inner.cfg().disable_balance_check;
842839
self.disable_balance_check();
843840
let mut new = f(self);
844-
new.inner.data.ctx.modify_cfg(|cfg| cfg.disable_balance_check = previous);
841+
new.inner.ctx.modify_cfg(|cfg| cfg.disable_balance_check = previous);
845842
new
846843
}
847844

@@ -850,13 +847,13 @@ where
850847
/// simulating large transactions like forge scripts.
851848
#[cfg(feature = "optional_block_gas_limit")]
852849
pub fn disable_block_gas_limit(&mut self) {
853-
self.inner.data.ctx.modify_cfg(|cfg| cfg.disable_block_gas_limit = true);
850+
self.inner.ctx.modify_cfg(|cfg| cfg.disable_block_gas_limit = true);
854851
}
855852

856853
/// Enable block gas limits. See [`Self::disable_block_gas_limit`].
857854
#[cfg(feature = "optional_block_gas_limit")]
858855
pub fn enable_block_gas_limit(&mut self) {
859-
self.inner.data.ctx.modify_cfg(|cfg| cfg.disable_block_gas_limit = false);
856+
self.inner.ctx.modify_cfg(|cfg| cfg.disable_block_gas_limit = false);
860857
}
861858

862859
/// Run a closure with block gas limits disabled, then restore the previous
@@ -869,7 +866,7 @@ where
869866
let previous = self.inner.cfg().disable_block_gas_limit;
870867
self.disable_block_gas_limit();
871868
let mut new = f(self);
872-
new.inner.data.ctx.modify_cfg(|cfg| cfg.disable_block_gas_limit = previous);
869+
new.inner.ctx.modify_cfg(|cfg| cfg.disable_block_gas_limit = previous);
873870
new
874871
}
875872

@@ -879,15 +876,15 @@ where
879876
/// [EIP-3607]: https://eips.ethereum.org/EIPS/eip-3607
880877
#[cfg(feature = "optional_eip3607")]
881878
pub fn disable_eip3607(&mut self) {
882-
self.inner.data.ctx.modify_cfg(|cfg| cfg.disable_eip3607 = true);
879+
self.inner.ctx.modify_cfg(|cfg| cfg.disable_eip3607 = true);
883880
}
884881

885882
/// Enable [EIP-3607]. See [`Self::disable_eip3607`].
886883
///
887884
/// [EIP-3607]: https://eips.ethereum.org/EIPS/eip-3607
888885
#[cfg(feature = "optional_eip3607")]
889886
pub fn enable_eip3607(&mut self) {
890-
self.inner.data.ctx.modify_cfg(|cfg| cfg.disable_eip3607 = false);
887+
self.inner.ctx.modify_cfg(|cfg| cfg.disable_eip3607 = false);
891888
}
892889

893890
/// Run a closure with [EIP-3607] disabled, then restore the previous
@@ -901,7 +898,7 @@ where
901898
self.disable_eip3607();
902899

903900
let mut new = f(self);
904-
new.inner.data.ctx.modify_cfg(|cfg| cfg.disable_eip3607 = previous);
901+
new.inner.ctx.modify_cfg(|cfg| cfg.disable_eip3607 = previous);
905902
new
906903
}
907904

@@ -911,15 +908,15 @@ where
911908
/// [EIP-1559]: https://eips.ethereum.org/EIPS/eip-1559
912909
#[cfg(feature = "optional_no_base_fee")]
913910
pub fn disable_base_fee(&mut self) {
914-
self.inner.data.ctx.modify_cfg(|cfg| cfg.disable_base_fee = true)
911+
self.inner.ctx.modify_cfg(|cfg| cfg.disable_base_fee = true)
915912
}
916913

917914
/// Enable [EIP-1559] base fee checks. See [`Self::disable_base_fee`].
918915
///
919916
/// [EIP-1559]: https://eips.ethereum.org/EIPS/eip-1559
920917
#[cfg(feature = "optional_no_base_fee")]
921918
pub fn enable_base_fee(&mut self) {
922-
self.inner.data.ctx.modify_cfg(|cfg| cfg.disable_base_fee = false)
919+
self.inner.ctx.modify_cfg(|cfg| cfg.disable_base_fee = false)
923920
}
924921

925922
/// Run a closure with [EIP-1559] base fee checks disabled, then restore the
@@ -935,19 +932,19 @@ where
935932
self.disable_base_fee();
936933

937934
let mut new = f(self);
938-
new.inner.data.ctx.modify_cfg(|cfg| cfg.disable_base_fee = previous);
935+
new.inner.ctx.modify_cfg(|cfg| cfg.disable_base_fee = previous);
939936
new
940937
}
941938

942939
/// Disable nonce checks. This allows transactions to be sent with
943940
/// incorrect nonces, and is useful for things like system transactions.
944941
pub fn disable_nonce_check(&mut self) {
945-
self.inner.data.ctx.modify_cfg(|cfg| cfg.disable_nonce_check = true)
942+
self.inner.ctx.modify_cfg(|cfg| cfg.disable_nonce_check = true)
946943
}
947944

948945
/// Enable nonce checks. See [`Self::disable_nonce_check`].
949946
pub fn enable_nonce_check(&mut self) {
950-
self.inner.data.ctx.modify_cfg(|cfg| cfg.disable_nonce_check = false)
947+
self.inner.ctx.modify_cfg(|cfg| cfg.disable_nonce_check = false)
951948
}
952949

953950
/// Run a closure with nonce checks disabled, then restore the previous
@@ -961,7 +958,7 @@ where
961958
self.disable_nonce_check();
962959

963960
let mut new = f(self);
964-
new.inner.data.ctx.modify_cfg(|cfg| cfg.disable_nonce_check = previous);
961+
new.inner.ctx.modify_cfg(|cfg| cfg.disable_nonce_check = previous);
965962
new
966963
}
967964
}
@@ -1080,7 +1077,7 @@ where
10801077
b.fill_block(&mut self.inner);
10811078

10821079
let mut this = f(self);
1083-
this.inner.data.ctx.set_block(previous);
1080+
this.inner.ctx.set_block(previous);
10841081
this
10851082
}
10861083

@@ -1100,11 +1097,11 @@ where
11001097

11011098
match f(self) {
11021099
Ok(mut evm) => {
1103-
evm.inner.data.ctx.set_block(previous);
1100+
evm.inner.ctx.set_block(previous);
11041101
Ok(evm)
11051102
}
11061103
Err(mut evm) => {
1107-
evm.inner.data.ctx.set_block(previous);
1104+
evm.inner.ctx.set_block(previous);
11081105
Err(evm)
11091106
}
11101107
}
@@ -1363,7 +1360,7 @@ where
13631360
let previous = self.inner.tx().clone();
13641361
t.fill_tx(&mut self.inner);
13651362
let mut this = f(self);
1366-
this.inner.data.ctx.set_tx(previous);
1363+
this.inner.ctx.set_tx(previous);
13671364
this
13681365
}
13691366

@@ -1383,11 +1380,11 @@ where
13831380
t.fill_tx(&mut self.inner);
13841381
match f(self) {
13851382
Ok(mut evm) => {
1386-
evm.inner.data.ctx.set_tx(previous);
1383+
evm.inner.ctx.set_tx(previous);
13871384
Ok(evm)
13881385
}
13891386
Err(mut evm) => {
1390-
evm.inner.data.ctx.set_tx(previous);
1387+
evm.inner.ctx.set_tx(previous);
13911388
Err(evm)
13921389
}
13931390
}
@@ -1983,7 +1980,11 @@ where
19831980
where
19841981
T::Return: alloy::sol_types::SolType,
19851982
{
1986-
self.output().map(|output| T::abi_decode_returns(output, validate))
1983+
if validate {
1984+
return self.output().map(|output| T::abi_decode_returns_validate(output));
1985+
}
1986+
1987+
self.output().map(|output| T::abi_decode_returns(output))
19871988
}
19881989

19891990
/// Get the gas used by the transaction.

‎src/ext.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,6 @@ where
176176
Ctx: ContextTr,
177177
{
178178
fn db_mut_ext(&mut self) -> &mut Ctx::Db {
179-
self.data.ctx.db()
179+
self.ctx.db()
180180
}
181181
}

‎src/fill/alloy.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -337,7 +337,13 @@ impl Tx for alloy::rpc::types::TransactionRequest {
337337
*gas_priority_fee = self.max_priority_fee_per_gas;
338338
*blob_hashes = self.blob_versioned_hashes.clone().unwrap_or_default();
339339
*max_fee_per_blob_gas = self.max_fee_per_blob_gas.unwrap_or_default();
340-
*authorization_list = self.authorization_list.clone().unwrap_or_default();
340+
*authorization_list = self
341+
.authorization_list
342+
.iter()
343+
.flatten()
344+
.cloned()
345+
.map(revm::context::either::Either::Left)
346+
.collect();
341347
}
342348
}
343349

‎src/fill/fillers.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -73,11 +73,11 @@ impl Cfg for GasEstimationFiller {
7373
&self,
7474
evm: &mut revm::context::Evm<crate::helpers::Ctx<Db>, Insp, Inst, Prec>,
7575
) {
76-
evm.data.ctx.modify_cfg(|cfg_env| self.fill_cfg_env(cfg_env));
76+
evm.ctx.modify_cfg(|cfg_env| self.fill_cfg_env(cfg_env));
7777

78-
let chain_id = evm.data.ctx.cfg.chain_id;
78+
let chain_id = evm.ctx.cfg.chain_id;
7979

80-
evm.data.ctx.modify_tx(|tx_env| {
80+
evm.ctx.modify_tx(|tx_env| {
8181
tx_env.chain_id = Some(chain_id);
8282
});
8383
}
@@ -107,11 +107,11 @@ impl Cfg for CallFiller {
107107
&self,
108108
evm: &mut revm::context::Evm<crate::helpers::Ctx<Db>, Insp, Inst, Prec>,
109109
) {
110-
evm.data.ctx.modify_cfg(|cfg_env| self.fill_cfg_env(cfg_env));
110+
evm.ctx.modify_cfg(|cfg_env| self.fill_cfg_env(cfg_env));
111111

112-
let chain_id = evm.data.ctx.cfg.chain_id;
112+
let chain_id = evm.ctx.cfg.chain_id;
113113

114-
evm.data.ctx.modify_tx(|tx_env| {
114+
evm.ctx.modify_tx(|tx_env| {
115115
tx_env.chain_id = Some(chain_id);
116116
});
117117
}

‎src/fill/traits.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ pub trait Tx: Send + Sync {
2323
where
2424
Self: Sized,
2525
{
26-
evm.data.ctx.modify_tx(|tx_env| self.fill_tx_env(tx_env));
26+
evm.ctx.modify_tx(|tx_env| self.fill_tx_env(tx_env));
2727
}
2828
}
2929

@@ -71,7 +71,7 @@ pub trait Block: Send + Sync {
7171
where
7272
Self: Sized,
7373
{
74-
evm.data.ctx.modify_block(|block_env| self.fill_block_env(block_env));
74+
evm.ctx.modify_block(|block_env| self.fill_block_env(block_env));
7575
}
7676

7777
/// Get the transaction count hint from the filler. This can be used for
@@ -134,7 +134,7 @@ pub trait Cfg: Send + Sync {
134134
where
135135
Self: Sized,
136136
{
137-
evm.data.ctx.modify_cfg(|cfg_env| self.fill_cfg_env(cfg_env));
137+
evm.ctx.modify_cfg(|cfg_env| self.fill_cfg_env(cfg_env));
138138
}
139139
}
140140

‎src/inspectors/spanning.rs

Lines changed: 30 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1-
use alloy::hex;
1+
use alloy::{consensus::constants::SELECTOR_LEN, hex};
22
use revm::{
3+
context::{ContextTr, LocalContextTr},
34
interpreter::{
4-
CallInputs, CallOutcome, CreateInputs, CreateOutcome, EOFCreateInputs, Interpreter,
5-
InterpreterTypes,
5+
CallInput, CallInputs, CallOutcome, CreateInputs, CreateOutcome, EOFCreateInputs,
6+
Interpreter, InterpreterTypes,
67
},
78
Inspector,
89
};
@@ -112,14 +113,17 @@ impl SpanningInspector {
112113
}
113114

114115
/// Create a span for a `CALL`-family opcode.
115-
fn span_call<Ctx>(&self, _context: &Ctx, inputs: &CallInputs) -> Span {
116-
let mut selector = inputs.input.clone();
117-
selector.truncate(4);
116+
fn span_call<Ctx>(&self, context: &mut Ctx, inputs: &CallInputs) -> Span
117+
where
118+
Ctx: ContextTr,
119+
{
120+
let selector = resolve_selector(inputs, context).map(hex::encode);
121+
118122
runtime_level_span!(
119123
self.level,
120124
"call",
121125
input_len = inputs.input.len(),
122-
selector = hex::encode(&selector),
126+
selector,
123127
gas_limit = inputs.gas_limit,
124128
bytecode_address = %inputs.bytecode_address,
125129
target_addrses = %inputs.target_address,
@@ -130,7 +134,10 @@ impl SpanningInspector {
130134
}
131135

132136
/// Create, enter, and store a span for a `CALL`-family opcode.
133-
fn enter_call<Ctx>(&mut self, context: &Ctx, inputs: &CallInputs) {
137+
fn enter_call<Ctx>(&mut self, context: &mut Ctx, inputs: &CallInputs)
138+
where
139+
Ctx: ContextTr,
140+
{
134141
self.active.push(self.span_call(context, inputs).entered())
135142
}
136143

@@ -172,6 +179,7 @@ impl SpanningInspector {
172179
impl<Ctx, Int> Inspector<Ctx, Int> for SpanningInspector
173180
where
174181
Int: InterpreterTypes,
182+
Ctx: ContextTr,
175183
{
176184
fn initialize_interp(&mut self, interp: &mut Interpreter<Int>, context: &mut Ctx) {
177185
self.init(interp, context);
@@ -218,3 +226,17 @@ where
218226
self.exit_span();
219227
}
220228
}
229+
230+
/// Resolve a selector from the [CallInputs].
231+
fn resolve_selector(inputs: &CallInputs, ctx: &mut impl ContextTr) -> Option<[u8; SELECTOR_LEN]> {
232+
match &inputs.input {
233+
CallInput::SharedBuffer(range) => {
234+
let raw = ctx.local().shared_memory_buffer_slice(range.clone());
235+
236+
raw?.get(..SELECTOR_LEN).map(TryInto::try_into).and_then(Result::ok)
237+
}
238+
CallInput::Bytes(bytes) => {
239+
bytes.as_ref().get(..SELECTOR_LEN).map(TryInto::try_into).and_then(Result::ok)
240+
}
241+
}
242+
}

‎src/system/eip6110.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ where
6060
logs.into_iter().filter(|log| log.address == MAINNET_DEPOSIT_CONTRACT_ADDRESS).map(|log| {
6161
// We assume that the log is valid because it was emitted by the
6262
// deposit contract.
63-
let decoded_log = DepositEvent::decode_log(log, false).expect("invalid log");
63+
let decoded_log = DepositEvent::decode_log(log).expect("invalid log");
6464
parse_deposit_from_log(&decoded_log)
6565
})
6666
}
@@ -74,7 +74,7 @@ pub fn accumulate_deposits_from_logs<'a>(
7474
|log| {
7575
// We assume that the log is valid because it was emitted by the
7676
// deposit contract.
77-
let decoded_log = DepositEvent::decode_log(log, false).expect("invalid log");
77+
let decoded_log = DepositEvent::decode_log(log).expect("invalid log");
7878
accumulate_deposit_from_log(&decoded_log, out);
7979
},
8080
);

‎src/system/mod.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ fn cleanup_syscall<Db, Insp>(
108108
});
109109

110110
// Restore the nonce check
111-
evm.data.ctx.modify_cfg(|cfg| cfg.disable_nonce_check = previous_nonce_check);
111+
evm.ctx.modify_cfg(|cfg| cfg.disable_nonce_check = previous_nonce_check);
112112

113113
// Remove the system caller and fees from the state
114114
let state = &mut result.state;
@@ -136,18 +136,18 @@ where
136136

137137
let limit = evm.tx().gas_limit();
138138

139-
let block = &mut evm.data.ctx.block;
139+
let block = &mut evm.ctx.block;
140140

141141
let old_gas_limit = core::mem::replace(&mut block.gas_limit, limit);
142142
let old_base_fee = core::mem::take(&mut block.basefee);
143-
let previous_nonce_check = std::mem::replace(&mut evm.data.ctx.cfg.disable_nonce_check, true);
143+
let previous_nonce_check = std::mem::replace(&mut evm.ctx.cfg.disable_nonce_check, true);
144144

145145
let mut result = evm.inspect_replay()?;
146146

147147
// Cleanup the syscall.
148148
cleanup_syscall(evm, &mut result, syscall, old_gas_limit, old_base_fee, previous_nonce_check);
149149

150-
evm.data.ctx.db().commit(result.state);
150+
evm.ctx.db().commit(result.state);
151151

152152
// apply result, remove receipt from block outputs.
153153
Ok(result.result)

0 commit comments

Comments
 (0)
Please sign in to comment.