Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: bump revm #5792

Merged
merged 6 commits into from
Sep 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
350 changes: 68 additions & 282 deletions Cargo.lock

Large diffs are not rendered by default.

6 changes: 4 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -159,5 +159,7 @@ tikv-jemallocator = "0.5.4"
#ethers-solc = { path = "../ethers-rs/ethers-solc" }

[patch.crates-io]
revm = { git = "https://github.com/bluealloy/revm/", rev = "6b55b9c0ab264c000e087c2f54f2d8dc24b869aa" }
revm-primitives = { git = "https://github.com/bluealloy/revm/", rev = "6b55b9c0ab264c000e087c2f54f2d8dc24b869aa" }
revm = { git = "https://github.com/bluealloy/revm/", rev = "7eacc3a728b8a9cf3c15db609753e5d9f69e08ce" }
revm-interpreter = { git = "https://github.com/bluealloy/revm/", rev = "7eacc3a728b8a9cf3c15db609753e5d9f69e08ce" }
revm-precompile = { git = "https://github.com/bluealloy/revm/", rev = "7eacc3a728b8a9cf3c15db609753e5d9f69e08ce" }
revm-primitives = { git = "https://github.com/bluealloy/revm/", rev = "7eacc3a728b8a9cf3c15db609753e5d9f69e08ce" }
4 changes: 2 additions & 2 deletions crates/anvil/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -784,7 +784,7 @@ impl NodeConfig {

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

// need to update the dev signers and env with the chain id
self.set_chain_id(Some(chain_id));
env.cfg.chain_id = rU256::from(chain_id);
env.cfg.chain_id = chain_id;
env.tx.chain_id = chain_id.into();
chain_id
};
Expand Down
2 changes: 1 addition & 1 deletion crates/anvil/src/eth/backend/mem/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -365,7 +365,7 @@ impl Backend {
// update all settings related to the forked block
{
let mut env = self.env.write();
env.cfg.chain_id = rU256::from(fork.chain_id());
env.cfg.chain_id = fork.chain_id();

env.block = BlockEnv {
number: rU256::from(fork_block_number),
Expand Down
2 changes: 1 addition & 1 deletion crates/anvil/src/genesis.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ impl Genesis {
/// Applies all settings to the given `env`
pub fn apply(&self, env: &mut Env) {
if let Some(chain_id) = self.chain_id() {
env.cfg.chain_id = rU256::from(chain_id);
env.cfg.chain_id = chain_id;
}
if let Some(timestamp) = self.timestamp {
env.block.timestamp = rU256::from(timestamp);
Expand Down
1 change: 1 addition & 0 deletions crates/evm/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -66,5 +66,6 @@ walkdir = "2"
semver = "1"

[dev-dependencies]
ethers = { workspace = true, features = ["ethers-solc", "rustls"] }
foundry-utils.workspace = true
tempfile = "3"
19 changes: 12 additions & 7 deletions crates/evm/src/executor/backend/in_memory_db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,24 +81,28 @@ impl DatabaseCommit for MemDb {
///
/// This will also _always_ return `Some(AccountInfo)`:
///
/// 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>
/// 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>.
/// If an account is `NotExisting`, `Database(Ref)::basic` will always return `None` for the
/// requested `AccountInfo`. To prevent
///
/// This will ensure that a missing account is never marked as `NotExisting`
/// requested `AccountInfo`. To prevent this, we ensure that a missing account is never marked as
/// `NotExisting` by always returning `Some` with this type.
#[derive(Debug, Default, Clone)]
pub struct EmptyDBWrapper(EmptyDB);

impl DatabaseRef for EmptyDBWrapper {
type Error = DatabaseError;

fn basic(&self, address: B160) -> Result<Option<AccountInfo>, Self::Error> {
fn basic(&self, _address: B160) -> Result<Option<AccountInfo>, Self::Error> {
// Note: this will always return `Some(AccountInfo)`, for the reason explained above
Ok(Some(self.0.basic(address)?.unwrap_or_default()))
Ok(Some(AccountInfo::default()))
}

fn code_by_hash(&self, code_hash: B256) -> Result<Bytecode, Self::Error> {
Ok(self.0.code_by_hash(code_hash)?)
}

fn storage(&self, address: B160, index: U256) -> Result<U256, Self::Error> {
Ok(self.0.storage(address, index)?)
}
Expand Down Expand Up @@ -128,7 +132,8 @@ mod tests {
// insert the modified account info
db.insert_account_info(address, info);

// 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>
// 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>
let info = Database::basic(&mut db, address).unwrap();
assert!(info.is_none());
}
Expand Down
2 changes: 1 addition & 1 deletion crates/evm/src/executor/fork/cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -476,7 +476,7 @@ mod tests {
let s = r#"{
"meta": {
"cfg_env": {
"chain_id": "0x539",
"chain_id": 1337,
"spec_id": "LATEST",
"perf_all_precompiles_have_balance": false,
"disable_coinbase_tip": false,
Expand Down
2 changes: 1 addition & 1 deletion crates/evm/src/executor/fork/init.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ where
};

let mut cfg = CfgEnv::default();
cfg.chain_id = u256_to_ru256(override_chain_id.unwrap_or(rpc_chain_id.as_u64()).into());
cfg.chain_id = override_chain_id.unwrap_or(rpc_chain_id.as_u64());
cfg.memory_limit = memory_limit;
cfg.limit_contract_code_size = Some(usize::MAX);
// EIP-3607 rejects transactions from senders with deployed code.
Expand Down
2 changes: 1 addition & 1 deletion crates/evm/src/executor/fork/multi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -501,7 +501,7 @@ async fn create_fork(

// determine the cache path if caching is enabled
let cache_path = if fork.enable_caching {
Config::foundry_block_cache_dir(ru256_to_u256(meta.cfg_env.chain_id).as_u64(), number)
Config::foundry_block_cache_dir(meta.cfg_env.chain_id, number)
} else {
None
};
Expand Down
2 changes: 1 addition & 1 deletion crates/evm/src/executor/inspector/cheatcodes/env.rs
Original file line number Diff line number Diff line change
Expand Up @@ -547,7 +547,7 @@ pub fn apply<DB: DatabaseExt>(
}
HEVMCalls::ChainId(inner) => {
ensure!(inner.0 <= U256::from(u64::MAX), "Chain ID must be less than 2^64 - 1");
data.env.cfg.chain_id = inner.0.into();
data.env.cfg.chain_id = inner.0.as_u64();
Bytes::new()
}
HEVMCalls::TxGasPrice(inner) => {
Expand Down
6 changes: 3 additions & 3 deletions crates/evm/src/executor/inspector/stack.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ use revm::{
interpreter::{
return_revert, CallInputs, CreateInputs, Gas, InstructionResult, Interpreter, Memory, Stack,
},
primitives::{BlockEnv, Env, B160, B256},
primitives::{BlockEnv, Env, B160, B256, U256 as rU256},
EVMData, Inspector,
};
use std::{collections::BTreeMap, sync::Arc};
Expand Down Expand Up @@ -568,7 +568,7 @@ impl<DB: DatabaseExt> Inspector<DB> for InspectorStack {
(status, address, remaining_gas, retdata)
}

fn selfdestruct(&mut self, contract: B160, target: B160) {
fn selfdestruct(&mut self, contract: B160, target: B160, value: rU256) {
call_inspectors!(
[
&mut self.debugger,
Expand All @@ -579,7 +579,7 @@ impl<DB: DatabaseExt> Inspector<DB> for InspectorStack {
&mut self.chisel_state
],
|inspector| {
Inspector::<DB>::selfdestruct(inspector, contract, target);
Inspector::<DB>::selfdestruct(inspector, contract, target, value);
}
);
}
Expand Down
4 changes: 2 additions & 2 deletions crates/evm/src/executor/opts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ impl EvmOpts {
/// Returns the `revm::Env` configured with only local settings
pub fn local_evm_env(&self) -> revm::primitives::Env {
let mut cfg = CfgEnv::default();
cfg.chain_id = rU256::from(self.env.chain_id.unwrap_or(foundry_common::DEV_CHAIN_ID));
cfg.chain_id = self.env.chain_id.unwrap_or(foundry_common::DEV_CHAIN_ID);
cfg.spec_id = SpecId::MERGE;
cfg.limit_contract_code_size = self.env.code_size_limit.or(Some(usize::MAX));
cfg.memory_limit = self.memory_limit;
Expand Down Expand Up @@ -138,7 +138,7 @@ impl EvmOpts {
/// be at `~/.foundry/cache/mainnet/14435000/storage.json`
pub fn get_fork(&self, config: &Config, env: revm::primitives::Env) -> Option<CreateFork> {
let url = self.fork_url.clone()?;
let enable_caching = config.enable_caching(&url, env.cfg.chain_id.to::<u64>());
let enable_caching = config.enable_caching(&url, env.cfg.chain_id);
Some(CreateFork { url, enable_caching, env, evm_opts: self.clone() })
}

Expand Down
2 changes: 1 addition & 1 deletion crates/evm/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ pub fn apply_chain_and_block_specific_env_changes<T>(
env: &mut revm::primitives::Env,
block: &Block<T>,
) {
if let Ok(chain) = Chain::try_from(ru256_to_u256(env.cfg.chain_id)) {
if let Ok(chain) = Chain::try_from(env.cfg.chain_id) {
let block_number = block.number.unwrap_or_default();

match chain {
Expand Down
2 changes: 1 addition & 1 deletion crates/evm/test-data/storage.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"meta":{"cfg_env":{"chain_id":"0x1","spec_id":"LATEST","perf_all_precompiles_have_balance":false,"memory_limit":4294967295, "perf_analyse_created_bytecodes":"Analyse", "limit_contract_code_size": 24576, "disable_coinbase_tip": false},"block_env":{"number":"0xdc42b8","coinbase":"0x0000000000000000000000000000000000000000","timestamp":"0x1","difficulty":"0x0","basefee":"0x0","gas_limit":"0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"},"hosts":["mainnet.infura.io"]},"accounts":{"0x63091244180ae240c87d1f528f5f269134cb07b3":{"balance":"0x0","code_hash":"0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470","code":null,"nonce":0}},"storage":{"0x63091244180ae240c87d1f528f5f269134cb07b3":{"0x0":"0x0","0x1":"0x0","0x2":"0x0","0x3":"0x0","0x4":"0x0","0x5":"0x0","0x6":"0x0","0x7":"0x0","0x8":"0x0","0x9":"0x0"}},"block_hashes":{}}
{"meta":{"cfg_env":{"chain_id":1,"spec_id":"LATEST","perf_all_precompiles_have_balance":false,"memory_limit":4294967295, "perf_analyse_created_bytecodes":"Analyse", "limit_contract_code_size": 24576, "disable_coinbase_tip": false},"block_env":{"number":"0xdc42b8","coinbase":"0x0000000000000000000000000000000000000000","timestamp":"0x1","difficulty":"0x0","basefee":"0x0","gas_limit":"0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"},"hosts":["mainnet.infura.io"]},"accounts":{"0x63091244180ae240c87d1f528f5f269134cb07b3":{"balance":"0x0","code_hash":"0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470","code":null,"nonce":0}},"storage":{"0x63091244180ae240c87d1f528f5f269134cb07b3":{"0x0":"0x0","0x1":"0x0","0x2":"0x0","0x3":"0x0","0x4":"0x0","0x5":"0x0","0x6":"0x0","0x7":"0x0","0x8":"0x0","0x9":"0x0"}},"block_hashes":{}}