Skip to content

Commit 4bbc3be

Browse files
DaniPopesmikelodder7
authored andcommitted
chore: bump revm (foundry-rs#5792)
* chore: bump revm * chore: update env chain ID to u64 * chore: drop fork * fix tests * bump
1 parent 8621e54 commit 4bbc3be

File tree

14 files changed

+92
-300
lines changed

14 files changed

+92
-300
lines changed

Cargo.lock

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

crates/anvil/src/config.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -784,7 +784,7 @@ impl NodeConfig {
784784

785785
let mut cfg = CfgEnv::default();
786786
cfg.spec_id = self.get_hardfork().into();
787-
cfg.chain_id = rU256::from(self.get_chain_id());
787+
cfg.chain_id = self.get_chain_id();
788788
cfg.limit_contract_code_size = self.code_size_limit;
789789
// EIP-3607 rejects transactions from senders with deployed code.
790790
// If EIP-3607 is enabled it can cause issues during fuzz/invariant tests if the
@@ -936,7 +936,7 @@ latest block number: {latest_block}"
936936

937937
// need to update the dev signers and env with the chain id
938938
self.set_chain_id(Some(chain_id));
939-
env.cfg.chain_id = rU256::from(chain_id);
939+
env.cfg.chain_id = chain_id;
940940
env.tx.chain_id = chain_id.into();
941941
chain_id
942942
};

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -365,7 +365,7 @@ impl Backend {
365365
// update all settings related to the forked block
366366
{
367367
let mut env = self.env.write();
368-
env.cfg.chain_id = rU256::from(fork.chain_id());
368+
env.cfg.chain_id = fork.chain_id();
369369

370370
env.block = BlockEnv {
371371
number: rU256::from(fork_block_number),

crates/anvil/src/genesis.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ impl Genesis {
8686
/// Applies all settings to the given `env`
8787
pub fn apply(&self, env: &mut Env) {
8888
if let Some(chain_id) = self.chain_id() {
89-
env.cfg.chain_id = rU256::from(chain_id);
89+
env.cfg.chain_id = chain_id;
9090
}
9191
if let Some(timestamp) = self.timestamp {
9292
env.block.timestamp = rU256::from(timestamp);

crates/evm/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ walkdir = "2"
6666
semver = "1"
6767

6868
[dev-dependencies]
69+
ethers = { workspace = true, features = ["ethers-solc", "rustls"] }
6970
foundry-utils.workspace = true
7071
tempfile = "3"
7172

crates/evm/src/executor/backend/in_memory_db.rs

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -81,24 +81,28 @@ impl DatabaseCommit for MemDb {
8181
///
8282
/// This will also _always_ return `Some(AccountInfo)`:
8383
///
84-
/// The [`Database`](revm::Database) implementation for `CacheDB` manages an `AccountState` for the `DbAccount`, this will be set to `AccountState::NotExisting` if the account does not exist yet. This is because there's a distinction between "non-existing" and "empty", See <https://github.com/bluealloy/revm/blob/8f4348dc93022cffb3730d9db5d3ab1aad77676a/crates/revm/src/db/in_memory_db.rs#L81-L83>
84+
/// The [`Database`](revm::Database) implementation for `CacheDB` manages an `AccountState` for the
85+
/// `DbAccount`, this will be set to `AccountState::NotExisting` if the account does not exist yet.
86+
/// This is because there's a distinction between "non-existing" and "empty",
87+
/// see <https://github.com/bluealloy/revm/blob/8f4348dc93022cffb3730d9db5d3ab1aad77676a/crates/revm/src/db/in_memory_db.rs#L81-L83>.
8588
/// If an account is `NotExisting`, `Database(Ref)::basic` will always return `None` for the
86-
/// requested `AccountInfo`. To prevent
87-
///
88-
/// This will ensure that a missing account is never marked as `NotExisting`
89+
/// requested `AccountInfo`. To prevent this, we ensure that a missing account is never marked as
90+
/// `NotExisting` by always returning `Some` with this type.
8991
#[derive(Debug, Default, Clone)]
9092
pub struct EmptyDBWrapper(EmptyDB);
9193

9294
impl DatabaseRef for EmptyDBWrapper {
9395
type Error = DatabaseError;
9496

95-
fn basic(&self, address: B160) -> Result<Option<AccountInfo>, Self::Error> {
97+
fn basic(&self, _address: B160) -> Result<Option<AccountInfo>, Self::Error> {
9698
// Note: this will always return `Some(AccountInfo)`, for the reason explained above
97-
Ok(Some(self.0.basic(address)?.unwrap_or_default()))
99+
Ok(Some(AccountInfo::default()))
98100
}
101+
99102
fn code_by_hash(&self, code_hash: B256) -> Result<Bytecode, Self::Error> {
100103
Ok(self.0.code_by_hash(code_hash)?)
101104
}
105+
102106
fn storage(&self, address: B160, index: U256) -> Result<U256, Self::Error> {
103107
Ok(self.0.storage(address, index)?)
104108
}
@@ -128,7 +132,8 @@ mod tests {
128132
// insert the modified account info
129133
db.insert_account_info(address, info);
130134

131-
// when fetching again, the `AccountInfo` is still `None` because the state of the account is `AccountState::NotExisting`, See <https://github.com/bluealloy/revm/blob/8f4348dc93022cffb3730d9db5d3ab1aad77676a/crates/revm/src/db/in_memory_db.rs#L217-L226>
135+
// when fetching again, the `AccountInfo` is still `None` because the state of the account
136+
// is `AccountState::NotExisting`, see <https://github.com/bluealloy/revm/blob/8f4348dc93022cffb3730d9db5d3ab1aad77676a/crates/revm/src/db/in_memory_db.rs#L217-L226>
132137
let info = Database::basic(&mut db, address).unwrap();
133138
assert!(info.is_none());
134139
}

crates/evm/src/executor/fork/cache.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -476,7 +476,7 @@ mod tests {
476476
let s = r#"{
477477
"meta": {
478478
"cfg_env": {
479-
"chain_id": "0x539",
479+
"chain_id": 1337,
480480
"spec_id": "LATEST",
481481
"perf_all_precompiles_have_balance": false,
482482
"disable_coinbase_tip": false,

crates/evm/src/executor/fork/init.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ where
5959
};
6060

6161
let mut cfg = CfgEnv::default();
62-
cfg.chain_id = u256_to_ru256(override_chain_id.unwrap_or(rpc_chain_id.as_u64()).into());
62+
cfg.chain_id = override_chain_id.unwrap_or(rpc_chain_id.as_u64());
6363
cfg.memory_limit = memory_limit;
6464
cfg.limit_contract_code_size = Some(usize::MAX);
6565
// EIP-3607 rejects transactions from senders with deployed code.

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -501,7 +501,7 @@ async fn create_fork(
501501

502502
// determine the cache path if caching is enabled
503503
let cache_path = if fork.enable_caching {
504-
Config::foundry_block_cache_dir(ru256_to_u256(meta.cfg_env.chain_id).as_u64(), number)
504+
Config::foundry_block_cache_dir(meta.cfg_env.chain_id, number)
505505
} else {
506506
None
507507
};

crates/evm/src/executor/inspector/cheatcodes/env.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -547,7 +547,7 @@ pub fn apply<DB: DatabaseExt>(
547547
}
548548
HEVMCalls::ChainId(inner) => {
549549
ensure!(inner.0 <= U256::from(u64::MAX), "Chain ID must be less than 2^64 - 1");
550-
data.env.cfg.chain_id = inner.0.into();
550+
data.env.cfg.chain_id = inner.0.as_u64();
551551
Bytes::new()
552552
}
553553
HEVMCalls::TxGasPrice(inner) => {

0 commit comments

Comments
 (0)