Skip to content

Commit cc24b6b

Browse files
mattssezerosnacksonbjerg
authored
chore: bump revm 31 (#12461)
* chore: bump revm 31 * use transfer in Celo precompile, temp commit to clarify blockers * access journaled_state directly to set storage of account * fixes * fixes --------- Co-authored-by: zerosnacks <[email protected]> Co-authored-by: Oliver Nordbjerg <[email protected]>
1 parent 806792b commit cc24b6b

File tree

8 files changed

+372
-231
lines changed

8 files changed

+372
-231
lines changed

Cargo.lock

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

Cargo.toml

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,7 @@ foundry-compilers = { version = "0.19.5", default-features = false, features = [
228228
"rustls",
229229
"svm-solc",
230230
] }
231-
foundry-fork-db = "0.19"
231+
foundry-fork-db = "0.20"
232232
solang-parser = { version = "=0.3.9", package = "foundry-solang-parser" }
233233
solar = { package = "solar-compiler", version = "=0.1.8", default-features = false }
234234
svm = { package = "svm-rs", version = "0.5", default-features = false, features = [
@@ -281,17 +281,17 @@ alloy-rlp = "0.3"
281281
alloy-trie = "0.9"
282282

283283
## op-alloy
284-
op-alloy-consensus = "0.20.0"
285-
op-alloy-rpc-types = "0.20.0"
284+
op-alloy-consensus = "0.22.0"
285+
op-alloy-rpc-types = "0.22.0"
286286
op-alloy-flz = "0.13.1"
287287

288288
## revm
289-
revm = { version = "30.2.0", default-features = false }
290-
revm-inspectors = { version = "0.31.2", features = ["serde"] }
291-
op-revm = { version = "11.1.2", default-features = false }
289+
revm = { version = "31.0.0", default-features = false }
290+
revm-inspectors = { version = "0.32.0", features = ["serde"] }
291+
op-revm = { version = "12.0.0", default-features = false }
292292
## alloy-evm
293-
alloy-evm = "0.22.3"
294-
alloy-op-evm = "0.22.3"
293+
alloy-evm = "0.23.1"
294+
alloy-op-evm = "0.23.1"
295295

296296
## cli
297297
anstream = "0.6"

crates/anvil/src/eth/error.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,7 @@ where
165165
OpTransactionError::HaltedDepositPostRegolith => {
166166
Self::DepositTransactionUnsupported
167167
}
168+
OpTransactionError::MissingEnvelopedTx => Self::InvalidTransaction(err.into()),
168169
},
169170
EVMError::Header(err) => match err {
170171
InvalidHeader::ExcessBlobGasNotSet => Self::ExcessBlobGasNotSet,
@@ -320,6 +321,9 @@ pub enum InvalidTransactionError {
320321
/// Deposit transaction error post regolith
321322
#[error("op-deposit failure post regolith")]
322323
DepositTxErrorPostRegolith,
324+
/// Missing enveloped transaction
325+
#[error("missing enveloped transaction")]
326+
MissingEnvelopedTx,
323327
}
324328

325329
impl From<InvalidTransaction> for InvalidTransactionError {
@@ -384,6 +388,7 @@ impl From<OpTransactionError> for InvalidTransactionError {
384388
OpTransactionError::Base(err) => err.into(),
385389
OpTransactionError::DepositSystemTxPostRegolith
386390
| OpTransactionError::HaltedDepositPostRegolith => Self::DepositTxErrorPostRegolith,
391+
OpTransactionError::MissingEnvelopedTx => Self::MissingEnvelopedTx,
387392
}
388393
}
389394
}

crates/cheatcodes/src/inspector.rs

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,6 @@ use revm::{
6262
interpreter_types::{Jumps, LoopControl, MemoryTr},
6363
},
6464
primitives::hardfork::SpecId,
65-
state::EvmStorageSlot,
6665
};
6766
use serde_json::Value;
6867
use std::{
@@ -317,8 +316,10 @@ impl ArbitraryStorage {
317316
/// - update account's storage with given value.
318317
pub fn save(&mut self, ecx: Ecx, address: Address, slot: U256, data: U256) {
319318
self.values.get_mut(&address).expect("missing arbitrary address entry").insert(slot, data);
320-
if let Ok(mut account) = ecx.journaled_state.load_account(address) {
321-
account.storage.insert(slot, EvmStorageSlot::new(data, 0));
319+
if ecx.journaled_state.load_account(address).is_ok() {
320+
ecx.journaled_state
321+
.sstore(address, slot, data)
322+
.expect("could not set arbitrary storage value");
322323
}
323324
}
324325

@@ -335,15 +336,17 @@ impl ArbitraryStorage {
335336
None => {
336337
storage_cache.insert(slot, new_value);
337338
// Update source storage with new value.
338-
if let Ok(mut source_account) = ecx.journaled_state.load_account(*source) {
339-
source_account.storage.insert(slot, EvmStorageSlot::new(new_value, 0));
339+
if ecx.journaled_state.load_account(*source).is_ok() {
340+
ecx.journaled_state
341+
.sstore(*source, slot, new_value)
342+
.expect("could not copy arbitrary storage value");
340343
}
341344
new_value
342345
}
343346
};
344347
// Update target storage with new value.
345-
if let Ok(mut target_account) = ecx.journaled_state.load_account(target) {
346-
target_account.storage.insert(slot, EvmStorageSlot::new(value, 0));
348+
if ecx.journaled_state.load_account(target).is_ok() {
349+
ecx.journaled_state.sstore(target, slot, value).expect("could not set storage");
347350
}
348351
value
349352
}

crates/cheatcodes/src/utils.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -260,8 +260,9 @@ impl Cheatcode for copyStorageCall {
260260

261261
if let Ok(from_account) = ccx.ecx.journaled_state.load_account(*from) {
262262
let from_storage = from_account.storage.clone();
263-
if let Ok(mut to_account) = ccx.ecx.journaled_state.load_account(*to) {
264-
to_account.storage = from_storage;
263+
if ccx.ecx.journaled_state.load_account(*to).is_ok() {
264+
// SAFETY: We ensured the account was already loaded.
265+
ccx.ecx.journaled_state.state.get_mut(to).unwrap().storage = from_storage;
265266
if let Some(arbitrary_storage) = &mut ccx.state.arbitrary_storage {
266267
arbitrary_storage.mark_copy(from, to);
267268
}

crates/evm/core/src/backend/mod.rs

Lines changed: 18 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1423,39 +1423,37 @@ impl DatabaseExt for Backend {
14231423
) -> Result<(), BackendError> {
14241424
// Fetch the account from the journaled state. Will create a new account if it does
14251425
// not already exist.
1426-
let mut state_acc = journaled_state.load_account(self, *target)?;
1426+
let mut state_acc = journaled_state.load_account_mut(self, *target)?;
14271427

14281428
// Set the account's bytecode and code hash, if the `bytecode` field is present.
14291429
if let Some(bytecode) = source.code.as_ref() {
1430-
state_acc.info.code_hash = keccak256(bytecode);
1430+
let bytecode_hash = keccak256(bytecode);
14311431
let bytecode = Bytecode::new_raw(bytecode.0.clone().into());
1432-
state_acc.info.code = Some(bytecode);
1432+
state_acc.set_code(bytecode_hash, bytecode);
14331433
}
14341434

1435+
// Set the account's balance.
1436+
state_acc.set_balance(source.balance);
1437+
14351438
// Set the account's storage, if the `storage` field is present.
1436-
if let Some(storage) = source.storage.as_ref() {
1437-
state_acc.storage = storage
1438-
.iter()
1439-
.map(|(slot, value)| {
1439+
if let Some(acc) = journaled_state.state.get_mut(target) {
1440+
if let Some(storage) = source.storage.as_ref() {
1441+
for (slot, value) in storage {
14401442
let slot = U256::from_be_bytes(slot.0);
1441-
(
1443+
acc.storage.insert(
14421444
slot,
14431445
EvmStorageSlot::new_changed(
1444-
state_acc
1445-
.storage
1446-
.get(&slot)
1447-
.map(|s| s.present_value)
1448-
.unwrap_or_default(),
1446+
acc.storage.get(&slot).map(|s| s.present_value).unwrap_or_default(),
14491447
U256::from_be_bytes(value.0),
14501448
0,
14511449
),
1452-
)
1453-
})
1454-
.collect();
1455-
}
1456-
// Set the account's nonce and balance.
1457-
state_acc.info.nonce = source.nonce.unwrap_or_default();
1458-
state_acc.info.balance = source.balance;
1450+
);
1451+
}
1452+
}
1453+
1454+
// Set the account's nonce.
1455+
acc.info.nonce = source.nonce.unwrap_or_default();
1456+
};
14591457

14601458
// Touch the account to ensure the loaded information persists if called in `setUp`.
14611459
journaled_state.touch(*target);

crates/evm/core/src/fork/multi.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ use crate::Env;
88
use alloy_consensus::BlockHeader;
99
use alloy_primitives::{U256, map::HashMap};
1010
use alloy_provider::network::BlockResponse;
11-
use foundry_common::provider::RetryProvider;
1211
use foundry_config::Config;
1312
use foundry_fork_db::{BackendHandler, BlockchainDb, SharedBackend, cache::BlockchainDbMeta};
1413
use futures::{
@@ -202,8 +201,7 @@ impl MultiFork {
202201
}
203202
}
204203

205-
type Handler = BackendHandler<RetryProvider>;
206-
204+
type Handler = BackendHandler;
207205
type CreateFuture =
208206
Pin<Box<dyn Future<Output = eyre::Result<(ForkId, CreatedFork, Handler)>> + Send>>;
209207
type CreateSender = OneshotSender<eyre::Result<(ForkId, SharedBackend, Env)>>;

crates/evm/networks/src/celo/transfer.rs

Lines changed: 24 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ pub fn precompile() -> DynPrecompile {
3838
/// Celo transfer precompile implementation.
3939
///
4040
/// Uses load_account to modify balances directly, making it compatible with PrecompilesMap.
41-
pub fn celo_transfer_precompile(input: PrecompileInput<'_>) -> PrecompileResult {
41+
pub fn celo_transfer_precompile(mut input: PrecompileInput<'_>) -> PrecompileResult {
4242
// Check minimum gas requirement
4343
if input.gas < CELO_TRANSFER_GAS_COST {
4444
return Err(PrecompileError::OutOfGas);
@@ -62,44 +62,39 @@ pub fn celo_transfer_precompile(input: PrecompileInput<'_>) -> PrecompileResult
6262
let value = U256::from_be_slice(value_bytes);
6363

6464
// Perform the transfer using load_account to modify balances directly
65-
let mut internals = input.internals;
65+
let internals = input.internals_mut();
6666

6767
// Load and check the from account balance first
68-
{
69-
let from_account = match internals.load_account(from_address) {
70-
Ok(account) => account,
71-
Err(e) => {
72-
return Err(PrecompileError::Other(format!("Failed to load from account: {e:?}")));
73-
}
74-
};
75-
76-
// Check if from account has sufficient balance
77-
if from_account.data.info.balance < value {
78-
return Err(PrecompileError::Other("Insufficient balance".into()));
68+
69+
let from_account = match internals.load_account(from_address) {
70+
Ok(account) => account,
71+
Err(e) => {
72+
return Err(PrecompileError::Other(format!("Failed to load from account: {e:?}")));
7973
}
74+
};
8075

81-
// Deduct balance from the from account
82-
from_account.data.info.balance -= value;
76+
// Check if from account has sufficient balance
77+
if from_account.data.info.balance < value {
78+
return Err(PrecompileError::Other("Insufficient balance".into()));
8379
}
8480

85-
// Load and update the to account
86-
{
87-
let to_account = match internals.load_account(to_address) {
88-
Ok(account) => account,
89-
Err(e) => {
90-
return Err(PrecompileError::Other(format!("Failed to load to account: {e:?}")));
91-
}
92-
};
93-
94-
// Check for overflow in to account
95-
if to_account.data.info.balance.checked_add(value).is_none() {
96-
return Err(PrecompileError::Other("Balance overflow in to account".into()));
81+
let to_account = match internals.load_account(to_address) {
82+
Ok(account) => account,
83+
Err(e) => {
84+
return Err(PrecompileError::Other(format!("Failed to load to account: {e:?}")));
9785
}
86+
};
9887

99-
// Add balance to the to account
100-
to_account.data.info.balance += value;
88+
// Check for overflow in to account
89+
if to_account.data.info.balance.checked_add(value).is_none() {
90+
return Err(PrecompileError::Other("Balance overflow in to account".into()));
10191
}
10292

93+
// Transfer the value between accounts
94+
internals
95+
.transfer(from_address, to_address, value)
96+
.map_err(|e| PrecompileError::Other(format!("Failed to perform transfer: {e:?}")))?;
97+
10398
// No output data for successful transfer
10499
Ok(PrecompileOutput::new(CELO_TRANSFER_GAS_COST, alloy_primitives::Bytes::new()))
105100
}

0 commit comments

Comments
 (0)