Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
6143b8c
fix(evm): top level files compile
Evalir Apr 2, 2023
ae4c7b3
fix(executor): most issues fixed
Evalir Apr 2, 2023
19ee3ca
fix(inspector): inspector top level files compile
Evalir Apr 3, 2023
f7c41f8
fix(executor): cheatcodes progress
Evalir Apr 3, 2023
8347406
feat(fork): fork ready
Evalir Apr 3, 2023
d690541
more progress
Evalir Apr 3, 2023
0e005e9
chore: bump revm to 3.1
Evalir Apr 4, 2023
5d06df9
feat: executor/fuzz/coverage progress, mark unknowns as TODOs
Evalir Apr 5, 2023
388430e
chore: move all manual conversions to use utils
Evalir Apr 11, 2023
f51d97f
chore: modify state changeset to use proper types, annoying type conv…
Evalir Apr 11, 2023
9a7e68d
chore: remove todos, handle encoding by casting back to ethers u256
Evalir Apr 11, 2023
65dfd8e
chore: bail on inspect/transact steps early instead of modifying revm…
Evalir Apr 11, 2023
b76c259
chore: properly handle execution result conversions
Evalir Apr 11, 2023
b5c8237
chore: more executor changes
Evalir Apr 14, 2023
3622a04
chore: misc evm changes
Evalir Apr 14, 2023
68c68c4
chore: core anvil changes
Evalir Apr 14, 2023
f446a25
chore: anvil changes
Evalir Apr 14, 2023
f60f66a
chore: last misc changes
Evalir Apr 14, 2023
1e6a7b4
chore: fix most lint issues
Evalir Apr 14, 2023
220674b
chore: more fmt
Evalir Apr 14, 2023
2874ee0
chore: cosmetics
Evalir Apr 17, 2023
658b2b7
chore: new fork-update changes
Evalir Apr 17, 2023
50bad80
chore: fmt
Evalir Apr 17, 2023
aa29c83
chore: remove actual lints
Evalir Apr 17, 2023
11e62aa
chore: fmt
Evalir Apr 18, 2023
2c680a9
Merge branch 'master' into Evalir/master
mattsse Apr 20, 2023
de3fc06
chore: fix most lints
Evalir Apr 20, 2023
3c155c6
chore: fix remaining lints
Evalir Apr 20, 2023
2732c71
Merge branch 'master' into master
Evalir Apr 21, 2023
0197e0f
chore: fmt
Evalir Apr 21, 2023
31181f3
Merge branch 'master' into master
Evalir Apr 22, 2023
668441d
chore: mark arg as mut
Evalir Apr 22, 2023
7011de0
fix: pass revert output data when filtering exec results
Evalir Apr 26, 2023
500547f
chore: fmt
Evalir Apr 26, 2023
3a51678
fix: test was erroneously set to fork at the same fork from the tx
Evalir Apr 26, 2023
fbf756a
fix: update broken test
Evalir Apr 27, 2023
a3153d3
fix: fix hashes that now are diff due to revm 3.0
Evalir Apr 27, 2023
9c114a5
Merge branch 'master' into master
Evalir Apr 27, 2023
de156a3
Merge branch 'master' into Evalir/master
Evalir Apr 28, 2023
bb72b36
chore: fix replaced instructionresult
Evalir Apr 28, 2023
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
343 changes: 127 additions & 216 deletions Cargo.lock

Large diffs are not rendered by default.

5 changes: 2 additions & 3 deletions anvil/core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,9 @@ license = "MIT OR Apache-2.0"
[dependencies]
# foundry internal
foundry-evm = { path = "../../evm" }
revm = { version = "2.3", default-features = false, features = [
revm = { version = "3.1.1", default-features = false, features = [
"std",
"k256",
"with-serde",
"serde",
"memory_limit",
] }

Expand Down
4 changes: 2 additions & 2 deletions anvil/core/src/eth/proof.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use ethers_core::{
types::{H256, U256},
utils::rlp,
};
use revm::KECCAK_EMPTY;
use revm::primitives::KECCAK_EMPTY;
// reexport for convenience
pub use ethers_core::types::{EIP1186ProofResponse as AccountProof, StorageProof};

Expand All @@ -28,7 +28,7 @@ impl Default for BasicAccount {
BasicAccount {
balance: 0.into(),
nonce: 0.into(),
code_hash: KECCAK_EMPTY,
code_hash: KECCAK_EMPTY.into(),
storage_root: KECCAK_NULL_RLP,
}
}
Expand Down
21 changes: 15 additions & 6 deletions anvil/core/src/eth/receipt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use ethers_core::{
rlp::{Decodable, DecoderError, Encodable, Rlp, RlpStream},
},
};
use foundry_evm::utils::{b256_to_h256, h256_to_b256};

#[derive(Clone, Debug, PartialEq, Eq)]
#[cfg_attr(feature = "fastrlp", derive(open_fastrlp::RlpEncodable, open_fastrlp::RlpDecodable))]
Expand All @@ -16,17 +17,25 @@ pub struct Log {
pub data: Bytes,
}

impl From<revm::Log> for Log {
fn from(log: revm::Log) -> Self {
let revm::Log { address, topics, data } = log;
Log { address, topics, data: data.into() }
impl From<revm::primitives::Log> for Log {
fn from(log: revm::primitives::Log) -> Self {
let revm::primitives::Log { address, topics, data } = log;
Log {
address: address.into(),
topics: topics.into_iter().map(b256_to_h256).collect(),
data: data.into(),
}
}
}

impl From<Log> for revm::Log {
impl From<Log> for revm::primitives::Log {
fn from(log: Log) -> Self {
let Log { address, topics, data } = log;
revm::Log { address, topics, data: data.0 }
revm::primitives::Log {
address: address.into(),
topics: topics.into_iter().map(h256_to_b256).collect(),
data: data.0,
}
}
}

Expand Down
35 changes: 19 additions & 16 deletions anvil/core/src/eth/transaction/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

use crate::eth::{
receipt::Log,
utils::{enveloped, to_access_list},
utils::{enveloped, to_revm_access_list},
};
use ethers_core::{
types::{
Expand All @@ -15,7 +15,10 @@ use ethers_core::{
},
};
use foundry_evm::trace::CallTraceArena;
use revm::{CreateScheme, Return, TransactTo, TxEnv};
use revm::{
interpreter::InstructionResult,
primitives::{CreateScheme, TransactTo, TxEnv},
};
use std::ops::Deref;

/// compatibility with `ethers-rs` types
Expand Down Expand Up @@ -1177,7 +1180,7 @@ impl PendingTransaction {
pub fn to_revm_tx_env(&self) -> TxEnv {
fn transact_to(kind: &TransactionKind) -> TransactTo {
match kind {
TransactionKind::Call(c) => TransactTo::Call(*c),
TransactionKind::Call(c) => TransactTo::Call((*c).into()),
TransactionKind::Create => TransactTo::Create(CreateScheme::Create),
}
}
Expand All @@ -1188,13 +1191,13 @@ impl PendingTransaction {
let chain_id = tx.chain_id();
let LegacyTransaction { nonce, gas_price, gas_limit, value, kind, input, .. } = tx;
TxEnv {
caller,
caller: caller.into(),
transact_to: transact_to(kind),
data: input.0.clone(),
chain_id,
nonce: Some(nonce.as_u64()),
value: *value,
gas_price: *gas_price,
value: (*value).into(),
gas_price: (*gas_price).into(),
gas_priority_fee: None,
gas_limit: gas_limit.as_u64(),
access_list: vec![],
Expand All @@ -1213,16 +1216,16 @@ impl PendingTransaction {
..
} = tx;
TxEnv {
caller,
caller: caller.into(),
transact_to: transact_to(kind),
data: input.0.clone(),
chain_id: Some(*chain_id),
nonce: Some(nonce.as_u64()),
value: *value,
gas_price: *gas_price,
value: (*value).into(),
gas_price: (*gas_price).into(),
gas_priority_fee: None,
gas_limit: gas_limit.as_u64(),
access_list: to_access_list(access_list.0.clone()),
access_list: to_revm_access_list(access_list.0.clone()),
}
}
TypedTransaction::EIP1559(tx) => {
Expand All @@ -1239,16 +1242,16 @@ impl PendingTransaction {
..
} = tx;
TxEnv {
caller,
caller: caller.into(),
transact_to: transact_to(kind),
data: input.0.clone(),
chain_id: Some(*chain_id),
nonce: Some(nonce.as_u64()),
value: *value,
gas_price: *max_fee_per_gas,
gas_priority_fee: Some(*max_priority_fee_per_gas),
value: (*value).into(),
gas_price: (*max_fee_per_gas).into(),
gas_priority_fee: Some((*max_priority_fee_per_gas).into()),
gas_limit: gas_limit.as_u64(),
access_list: to_access_list(access_list.0.clone()),
access_list: to_revm_access_list(access_list.0.clone()),
}
}
}
Expand All @@ -1266,7 +1269,7 @@ pub struct TransactionInfo {
pub logs: Vec<Log>,
pub logs_bloom: Bloom,
pub traces: CallTraceArena,
pub exit: Return,
pub exit: InstructionResult,
pub out: Option<Bytes>,
}

Expand Down
14 changes: 13 additions & 1 deletion anvil/core/src/eth/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ use ethers_core::{
rlp::{Encodable, RlpStream},
},
};
use foundry_evm::utils::h256_to_u256_be;
use foundry_evm::utils::{h160_to_b160, h256_to_u256_be, u256_to_ru256};
use revm::primitives::{B160, U256 as rU256};

pub fn enveloped<T: Encodable>(id: u8, v: &T, s: &mut RlpStream) {
let encoded = rlp::encode(v);
Expand All @@ -20,3 +21,14 @@ pub fn to_access_list(list: Vec<AccessListItem>) -> Vec<(Address, Vec<U256>)> {
.map(|item| (item.address, item.storage_keys.into_iter().map(h256_to_u256_be).collect()))
.collect()
}

pub fn to_revm_access_list(list: Vec<AccessListItem>) -> Vec<(B160, Vec<rU256>)> {
list.into_iter()
.map(|item| {
(
h160_to_b160(item.address),
item.storage_keys.into_iter().map(h256_to_u256_be).map(u256_to_ru256).collect(),
)
})
.collect()
}
2 changes: 1 addition & 1 deletion anvil/core/src/types.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use ethers_core::types::{H256, U256, U64};
use revm::SpecId;
use revm::primitives::SpecId;

#[cfg(feature = "serde")]
use serde::{de::Error, Deserializer, Serializer};
Expand Down
32 changes: 18 additions & 14 deletions anvil/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,13 @@ use ethers::{
types::BlockNumber,
utils::{format_ether, hex, to_checksum, WEI_IN_ETHER},
};
use forge::utils::{h256_to_b256, u256_to_ru256};
use foundry_common::{ProviderBuilder, ALCHEMY_FREE_TIER_CUPS, REQUEST_TIMEOUT};
use foundry_config::Config;
use foundry_evm::{
executor::fork::{BlockchainDb, BlockchainDbMeta, SharedBackend},
revm,
revm::{BlockEnv, CfgEnv, SpecId, TxEnv},
revm::primitives::{BlockEnv, CfgEnv, SpecId, TxEnv, U256 as rU256},
utils::apply_chain_and_block_specific_env_changes,
};
use parking_lot::RwLock;
Expand Down Expand Up @@ -748,10 +749,10 @@ impl NodeConfig {
/// *Note*: only memory based backend for now
pub(crate) async fn setup(&mut self) -> mem::Backend {
// configure the revm environment
let mut env = revm::Env {
let mut env = revm::primitives::Env {
cfg: CfgEnv {
spec_id: self.get_hardfork().into(),
chain_id: self.get_chain_id().into(),
chain_id: rU256::from(self.get_chain_id()),
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 All @@ -761,8 +762,8 @@ impl NodeConfig {
..Default::default()
},
block: BlockEnv {
gas_limit: self.gas_limit,
basefee: self.get_base_fee(),
gas_limit: self.gas_limit.into(),
basefee: self.get_base_fee().into(),
..Default::default()
},
tx: TxEnv { chain_id: self.get_chain_id().into(), ..Default::default() },
Expand Down Expand Up @@ -835,15 +836,18 @@ impl NodeConfig {

// we only use the gas limit value of the block if it is non-zero, since there are networks where this is not used and is always `0x0` which would inevitably result in `OutOfGas` errors as soon as the evm is about to record gas, See also <https://github.com/foundry-rs/foundry/issues/3247>

let gas_limit =
if block.gas_limit.is_zero() { env.block.gas_limit } else { block.gas_limit };
let gas_limit = if block.gas_limit.is_zero() {
env.block.gas_limit
} else {
u256_to_ru256(block.gas_limit)
};

env.block = BlockEnv {
number: fork_block_number.into(),
timestamp: block.timestamp,
difficulty: block.difficulty,
number: rU256::from(fork_block_number),
timestamp: block.timestamp.into(),
difficulty: block.difficulty.into(),
// ensures prevrandao is set
prevrandao: Some(block.mix_hash.unwrap_or_default()),
prevrandao: Some(block.mix_hash.unwrap_or_default()).map(h256_to_b256),
gas_limit,
// Keep previous `coinbase` and `basefee` value
coinbase: env.block.coinbase,
Expand All @@ -857,7 +861,7 @@ impl NodeConfig {
if self.base_fee.is_none() {
if let Some(base_fee) = block.base_fee_per_gas {
self.base_fee = Some(base_fee);
env.block.basefee = base_fee;
env.block.basefee = u256_to_ru256(base_fee);
// this is the base fee of the current block, but we need the base fee of
// the next block
let next_block_base_fee = fees.get_next_block_base_fee_per_gas(
Expand Down Expand Up @@ -892,7 +896,7 @@ impl NodeConfig {

// need to update the dev signers and env with the chain id
self.set_chain_id(Some(chain_id));
env.cfg.chain_id = chain_id.into();
env.cfg.chain_id = rU256::from(chain_id);
env.tx.chain_id = chain_id.into();
chain_id
};
Expand Down Expand Up @@ -946,7 +950,7 @@ impl NodeConfig {

let genesis = GenesisConfig {
timestamp: self.get_genesis_timestamp(),
balance: self.genesis_balance,
balance: self.genesis_balance.into(),
accounts: self.genesis_accounts.iter().map(|acc| acc.address()).collect(),
fork_genesis_account_infos: Arc::new(Default::default()),
genesis_init: self.genesis.clone(),
Expand Down
27 changes: 13 additions & 14 deletions anvil/src/eth/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ use crate::{
},
filter::{EthFilter, Filters, LogsFilter},
mem::transaction_build,
revm::TransactOut,
revm::primitives::Output,
ClientFork, LoggingManager, Miner, MiningMode, StorageInfo,
};
use anvil_core::{
Expand Down Expand Up @@ -55,11 +55,11 @@ use ethers::{
},
utils::rlp,
};
use forge::{executor::DatabaseRef, revm::BlockEnv};
use forge::{executor::DatabaseRef, revm::primitives::BlockEnv};
use foundry_common::ProviderBuilder;
use foundry_evm::{
executor::backend::DatabaseError,
revm::{return_ok, return_revert, Return},
revm::interpreter::{return_ok, return_revert, InstructionResult},
};
use futures::channel::mpsc::Receiver;
use parking_lot::RwLock;
Expand Down Expand Up @@ -1990,7 +1990,7 @@ impl EthApi {

// get the highest possible gas limit, either the request's set value or the currently
// configured gas limit
let mut highest_gas_limit = request.gas.unwrap_or(block_env.gas_limit);
let mut highest_gas_limit = request.gas.unwrap_or(block_env.gas_limit.into());

// check with the funds of the sender
if let Some(from) = request.from {
Expand Down Expand Up @@ -2029,7 +2029,7 @@ impl EthApi {
return_ok!() => {
// succeeded
}
Return::OutOfGas | Return::LackOfFundForGasLimit | Return::OutOfFund => {
InstructionResult::OutOfGas | InstructionResult::OutOfFund => {
return Err(InvalidTransactionError::OutOfGas(gas_limit).into())
}
// need to check if the revert was due to lack of gas or unrelated reason
Expand Down Expand Up @@ -2098,10 +2098,9 @@ impl EthApi {
}
last_highest_gas_limit = highest_gas_limit;
}
Return::Revert |
Return::OutOfGas |
Return::LackOfFundForGasLimit |
Return::OutOfFund => {
InstructionResult::Revert |
InstructionResult::OutOfGas |
InstructionResult::OutOfFund => {
lowest_gas_limit = mid_gas_limit;
}
reason => {
Expand Down Expand Up @@ -2339,16 +2338,16 @@ fn required_marker(provided_nonce: U256, on_chain_nonce: U256, from: Address) ->
}
}

fn convert_transact_out(out: &TransactOut) -> Bytes {
fn convert_transact_out(out: &Option<Output>) -> Bytes {
match out {
TransactOut::None => Default::default(),
TransactOut::Call(out) => out.to_vec().into(),
TransactOut::Create(out, _) => out.to_vec().into(),
None => Default::default(),
Some(Output::Call(out)) => out.to_vec().into(),
Some(Output::Create(out, _)) => out.to_vec().into(),
}
}

/// Returns an error if the `exit` code is _not_ ok
fn ensure_return_ok(exit: Return, out: &TransactOut) -> Result<Bytes> {
fn ensure_return_ok(exit: InstructionResult, out: &Option<Output>) -> Result<Bytes> {
let out = convert_transact_out(out);
match exit {
return_ok!() => Ok(out),
Expand Down
Loading