Skip to content

Commit 3e12d88

Browse files
mattsseDaniPopes
andauthored
chore: bump revm (#6281)
* chore: bump revm * allow aurora * revert on invalid * chore: use is_err * fix: add return checks again * fucking clippy * lets try this again * chore: update another condition * ffs * test: bump snekmate memory limit --------- Co-authored-by: DaniPopes <[email protected]>
1 parent 43dda85 commit 3e12d88

35 files changed

+246
-338
lines changed

Cargo.lock

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

Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,3 +211,6 @@ alloy-dyn-abi = { git = "https://github.com/alloy-rs/core/" }
211211
alloy-primitives = { git = "https://github.com/alloy-rs/core/" }
212212
alloy-json-abi = { git = "https://github.com/alloy-rs/core/" }
213213
alloy-sol-types = { git = "https://github.com/alloy-rs/core/" }
214+
215+
revm = { git = "https://github.com/bluealloy/revm", rev = "1609e07c68048909ad1682c98cf2b9baa76310b5" }
216+
revm-primitives = { git = "https://github.com/bluealloy/revm", rev = "1609e07c68048909ad1682c98cf2b9baa76310b5" }

crates/anvil/src/eth/backend/db.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ pub trait Db:
136136
/// Deserialize and add all chain data to the backend storage
137137
fn load_state(&mut self, state: SerializableState) -> DatabaseResult<bool> {
138138
for (addr, account) in state.accounts.into_iter() {
139-
let old_account_nonce = DatabaseRef::basic(self, addr.to_alloy())
139+
let old_account_nonce = DatabaseRef::basic_ref(self, addr.to_alloy())
140140
.ok()
141141
.and_then(|acc| acc.map(|acc| acc.nonce))
142142
.unwrap_or_default();
@@ -288,20 +288,20 @@ impl StateDb {
288288

289289
impl DatabaseRef for StateDb {
290290
type Error = DatabaseError;
291-
fn basic(&self, address: B160) -> DatabaseResult<Option<AccountInfo>> {
292-
self.0.basic(address)
291+
fn basic_ref(&self, address: B160) -> DatabaseResult<Option<AccountInfo>> {
292+
self.0.basic_ref(address)
293293
}
294294

295-
fn code_by_hash(&self, code_hash: B256) -> DatabaseResult<Bytecode> {
296-
self.0.code_by_hash(code_hash)
295+
fn code_by_hash_ref(&self, code_hash: B256) -> DatabaseResult<Bytecode> {
296+
self.0.code_by_hash_ref(code_hash)
297297
}
298298

299-
fn storage(&self, address: B160, index: rU256) -> DatabaseResult<rU256> {
300-
self.0.storage(address, index)
299+
fn storage_ref(&self, address: B160, index: rU256) -> DatabaseResult<rU256> {
300+
self.0.storage_ref(address, index)
301301
}
302302

303-
fn block_hash(&self, number: rU256) -> DatabaseResult<B256> {
304-
self.0.block_hash(number)
303+
fn block_hash_ref(&self, number: rU256) -> DatabaseResult<B256> {
304+
self.0.block_hash_ref(number)
305305
}
306306
}
307307

crates/anvil/src/eth/backend/genesis.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -103,21 +103,21 @@ pub(crate) struct AtGenesisStateDb<'a> {
103103

104104
impl<'a> DatabaseRef for AtGenesisStateDb<'a> {
105105
type Error = DatabaseError;
106-
fn basic(&self, address: aAddress) -> DatabaseResult<Option<AccountInfo>> {
106+
fn basic_ref(&self, address: aAddress) -> DatabaseResult<Option<AccountInfo>> {
107107
if let Some(acc) = self.accounts.get(&(address.to_ethers())).cloned() {
108108
return Ok(Some(acc))
109109
}
110-
self.db.basic(address)
110+
self.db.basic_ref(address)
111111
}
112112

113-
fn code_by_hash(&self, code_hash: B256) -> DatabaseResult<Bytecode> {
113+
fn code_by_hash_ref(&self, code_hash: B256) -> DatabaseResult<Bytecode> {
114114
if let Some((_, acc)) = self.accounts.iter().find(|(_, acc)| acc.code_hash == code_hash) {
115115
return Ok(acc.code.clone().unwrap_or_default())
116116
}
117-
self.db.code_by_hash(code_hash)
117+
self.db.code_by_hash_ref(code_hash)
118118
}
119119

120-
fn storage(&self, address: aAddress, index: U256) -> DatabaseResult<U256> {
120+
fn storage_ref(&self, address: aAddress, index: U256) -> DatabaseResult<U256> {
121121
if let Some(acc) = self
122122
.genesis
123123
.as_ref()
@@ -130,11 +130,11 @@ impl<'a> DatabaseRef for AtGenesisStateDb<'a> {
130130
.unwrap_or_default();
131131
return Ok(value.into_uint().to_alloy())
132132
}
133-
self.db.storage(address, index)
133+
self.db.storage_ref(address, index)
134134
}
135135

136-
fn block_hash(&self, number: U256) -> DatabaseResult<B256> {
137-
self.db.block_hash(number)
136+
fn block_hash_ref(&self, number: U256) -> DatabaseResult<B256> {
137+
self.db.block_hash_ref(number)
138138
}
139139
}
140140

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

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ impl Db for MemDb {
4242
let code = if let Some(code) = v.info.code {
4343
code
4444
} else {
45-
self.inner.code_by_hash(v.info.code_hash)?
45+
self.inner.code_by_hash_ref(v.info.code_hash)?
4646
}
4747
.to_checked();
4848
Ok((
@@ -177,13 +177,13 @@ mod tests {
177177

178178
load_db.load_state(state).unwrap();
179179

180-
let loaded_account = load_db.basic(test_addr.to_alloy()).unwrap().unwrap();
180+
let loaded_account = load_db.basic_ref(test_addr.to_alloy()).unwrap().unwrap();
181181

182182
assert_eq!(loaded_account.balance, rU256::from(123456));
183-
assert_eq!(load_db.code_by_hash(loaded_account.code_hash).unwrap(), contract_code);
183+
assert_eq!(load_db.code_by_hash_ref(loaded_account.code_hash).unwrap(), contract_code);
184184
assert_eq!(loaded_account.nonce, 1234);
185185
assert_eq!(
186-
load_db.storage(test_addr.to_alloy(), rU256::from(1234567)).unwrap(),
186+
load_db.storage_ref(test_addr.to_alloy(), rU256::from(1234567)).unwrap(),
187187
rU256::from(1)
188188
);
189189
}
@@ -241,15 +241,21 @@ mod tests {
241241

242242
db.load_state(new_state).unwrap();
243243

244-
let loaded_account = db.basic(test_addr.to_alloy()).unwrap().unwrap();
245-
let loaded_account2 = db.basic(test_addr2.to_alloy()).unwrap().unwrap();
244+
let loaded_account = db.basic_ref(test_addr.to_alloy()).unwrap().unwrap();
245+
let loaded_account2 = db.basic_ref(test_addr2.to_alloy()).unwrap().unwrap();
246246

247247
assert_eq!(loaded_account2.nonce, 1);
248248

249249
assert_eq!(loaded_account.balance, rU256::from(100100));
250-
assert_eq!(db.code_by_hash(loaded_account.code_hash).unwrap(), contract_code);
250+
assert_eq!(db.code_by_hash_ref(loaded_account.code_hash).unwrap(), contract_code);
251251
assert_eq!(loaded_account.nonce, 1234);
252-
assert_eq!(db.storage(test_addr.to_alloy(), rU256::from(1234567)).unwrap(), rU256::from(1));
253-
assert_eq!(db.storage(test_addr.to_alloy(), rU256::from(1234568)).unwrap(), rU256::from(5));
252+
assert_eq!(
253+
db.storage_ref(test_addr.to_alloy(), rU256::from(1234567)).unwrap(),
254+
rU256::from(1)
255+
);
256+
assert_eq!(
257+
db.storage_ref(test_addr.to_alloy(), rU256::from(1234568)).unwrap(),
258+
rU256::from(5)
259+
);
254260
}
255261
}

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

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -48,23 +48,17 @@ impl Inspector {
4848

4949
impl<DB: Database> revm::Inspector<DB> for Inspector {
5050
#[inline]
51-
fn initialize_interp(
52-
&mut self,
53-
interp: &mut Interpreter,
54-
data: &mut EVMData<'_, DB>,
55-
) -> InstructionResult {
51+
fn initialize_interp(&mut self, interp: &mut Interpreter<'_>, data: &mut EVMData<'_, DB>) {
5652
call_inspectors!([&mut self.tracer], |inspector| {
5753
inspector.initialize_interp(interp, data);
5854
});
59-
InstructionResult::Continue
6055
}
6156

6257
#[inline]
63-
fn step(&mut self, interp: &mut Interpreter, data: &mut EVMData<'_, DB>) -> InstructionResult {
58+
fn step(&mut self, interp: &mut Interpreter<'_>, data: &mut EVMData<'_, DB>) {
6459
call_inspectors!([&mut self.tracer], |inspector| {
6560
inspector.step(interp, data);
6661
});
67-
InstructionResult::Continue
6862
}
6963

7064
#[inline]
@@ -81,16 +75,10 @@ impl<DB: Database> revm::Inspector<DB> for Inspector {
8175
}
8276

8377
#[inline]
84-
fn step_end(
85-
&mut self,
86-
interp: &mut Interpreter,
87-
data: &mut EVMData<'_, DB>,
88-
eval: InstructionResult,
89-
) -> InstructionResult {
78+
fn step_end(&mut self, interp: &mut Interpreter<'_>, data: &mut EVMData<'_, DB>) {
9079
call_inspectors!([&mut self.tracer], |inspector| {
91-
inspector.step_end(interp, data, eval);
80+
inspector.step_end(interp, data);
9281
});
93-
eval
9482
}
9583

9684
#[inline]

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

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,7 @@ impl Backend {
267267
// accounts concurrently by spawning the job to a new task
268268
genesis_accounts_futures.push(tokio::task::spawn(async move {
269269
let db = db.read().await;
270-
let info = db.basic(address.to_alloy())?.unwrap_or_default();
270+
let info = db.basic_ref(address.to_alloy())?.unwrap_or_default();
271271
Ok::<_, DatabaseError>((address, info))
272272
}));
273273
}
@@ -341,7 +341,7 @@ impl Backend {
341341

342342
/// Returns the `AccountInfo` from the database
343343
pub async fn get_account(&self, address: Address) -> DatabaseResult<AccountInfo> {
344-
Ok(self.db.read().await.basic(address.to_alloy())?.unwrap_or_default())
344+
Ok(self.db.read().await.basic_ref(address.to_alloy())?.unwrap_or_default())
345345
}
346346

347347
/// Whether we're forked off some remote client
@@ -1148,7 +1148,7 @@ impl Backend {
11481148
let to = if let Some(to) = request.to {
11491149
to.to_alloy()
11501150
} else {
1151-
let nonce = state.basic(from)?.unwrap_or_default().nonce;
1151+
let nonce = state.basic_ref(from)?.unwrap_or_default().nonce;
11521152
from.create(nonce)
11531153
};
11541154

@@ -1675,7 +1675,7 @@ impl Backend {
16751675
) -> Result<H256, BlockchainError> {
16761676
self.with_database_at(block_request, |db, _| {
16771677
trace!(target: "backend", "get storage for {:?} at {:?}", address, index);
1678-
let val = db.storage(address.to_alloy(), index.to_alloy())?;
1678+
let val = db.storage_ref(address.to_alloy(), index.to_alloy())?;
16791679
Ok(u256_to_h256_be(val.to_ethers()))
16801680
})
16811681
.await?
@@ -1702,15 +1702,15 @@ impl Backend {
17021702
D: DatabaseRef<Error = DatabaseError>,
17031703
{
17041704
trace!(target: "backend", "get code for {:?}", address);
1705-
let account = state.basic(address.to_alloy())?.unwrap_or_default();
1705+
let account = state.basic_ref(address.to_alloy())?.unwrap_or_default();
17061706
if account.code_hash == KECCAK_EMPTY {
17071707
// if the code hash is `KECCAK_EMPTY`, we check no further
17081708
return Ok(Default::default())
17091709
}
17101710
let code = if let Some(code) = account.code {
17111711
code
17121712
} else {
1713-
state.code_by_hash(account.code_hash)?
1713+
state.code_by_hash_ref(account.code_hash)?
17141714
};
17151715
Ok(code.bytes()[..code.len()].to_vec().into())
17161716
}
@@ -1736,7 +1736,7 @@ impl Backend {
17361736
D: DatabaseRef<Error = DatabaseError>,
17371737
{
17381738
trace!(target: "backend", "get balance for {:?}", address);
1739-
Ok(state.basic(address.to_alloy())?.unwrap_or_default().balance.to_ethers())
1739+
Ok(state.basic_ref(address.to_alloy())?.unwrap_or_default().balance.to_ethers())
17401740
}
17411741

17421742
/// Returns the nonce of the address
@@ -1759,7 +1759,7 @@ impl Backend {
17591759
};
17601760
self.with_database_at(final_block_request, |db, _| {
17611761
trace!(target: "backend", "get nonce for {:?}", address);
1762-
Ok(db.basic(address.to_alloy())?.unwrap_or_default().nonce.into())
1762+
Ok(db.basic_ref(address.to_alloy())?.unwrap_or_default().nonce.into())
17631763
})
17641764
.await?
17651765
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ where
116116
{
117117
let mut cache_db = CacheDB::new(state);
118118
for (account, account_overrides) in overrides.iter() {
119-
let mut account_info = cache_db.basic((*account).to_alloy())?.unwrap_or_default();
119+
let mut account_info = cache_db.basic_ref((*account).to_alloy())?.unwrap_or_default();
120120

121121
if let Some(nonce) = account_overrides.nonce {
122122
account_info.nonce = nonce;

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -478,7 +478,7 @@ mod tests {
478478

479479
let loaded = storage.get(&one).unwrap();
480480

481-
let acc = loaded.basic(addr.to_alloy()).unwrap().unwrap();
481+
let acc = loaded.basic_ref(addr.to_alloy()).unwrap().unwrap();
482482
assert_eq!(acc.balance, rU256::from(1337u64));
483483
}
484484

@@ -508,7 +508,7 @@ mod tests {
508508
let hash = H256::from_uint(&U256::from(idx));
509509
let addr = Address::from(hash);
510510
let loaded = storage.get(&hash).unwrap();
511-
let acc = loaded.basic(addr.to_alloy()).unwrap().unwrap();
511+
let acc = loaded.basic_ref(addr.to_alloy()).unwrap().unwrap();
512512
let balance = (idx * 2) as u64;
513513
assert_eq!(acc.balance, rU256::from(balance));
514514
}

crates/anvil/src/eth/util.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
1-
use ethers::{abi::Address, types::H160};
1+
use ethers::abi::Address;
22
use foundry_evm::revm::{self, precompile::Precompiles, primitives::SpecId};
3+
use foundry_utils::types::ToEthers;
34
use std::fmt;
45

56
pub fn get_precompiles_for(spec_id: SpecId) -> Vec<Address> {
67
Precompiles::new(to_precompile_id(spec_id))
78
.addresses()
89
.into_iter()
9-
.map(|item| H160::from_slice(item))
10+
.copied()
11+
.map(|item| item.to_ethers())
1012
.collect()
1113
}
1214

0 commit comments

Comments
 (0)