Skip to content
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
36 changes: 19 additions & 17 deletions crates/cheatcodes/src/evm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ use foundry_common::{
};
use foundry_compilers::artifacts::EvmVersion;
use foundry_evm_core::{
FoundryBlock, FoundryCfg, FoundryTransaction,
backend::{DatabaseExt, FoundryJournalExt, RevertStateSnapshotAction},
constants::{CALLER, CHEATCODE_ADDRESS, HARDHAT_CONSOLE_ADDRESS, TEST_CONTRACT_ADDRESS},
env::FoundryContextExt,
Expand Down Expand Up @@ -481,15 +482,15 @@ impl<CTX: FoundryContextExt> Cheatcode<CTX> for chainIdCall {
fn apply_stateful(&self, ccx: &mut CheatsCtxt<'_, CTX>) -> Result {
let Self { newChainId } = self;
ensure!(*newChainId <= U256::from(u64::MAX), "chain ID must be less than 2^64");
ccx.ecx.cfg_mut().chain_id = newChainId.to();
ccx.ecx.cfg_mut().set_chain_id(newChainId.to());
Ok(Default::default())
}
}

impl<CTX: FoundryContextExt> Cheatcode<CTX> for coinbaseCall {
fn apply_stateful(&self, ccx: &mut CheatsCtxt<'_, CTX>) -> Result {
let Self { newCoinbase } = self;
ccx.ecx.block_mut().beneficiary = *newCoinbase;
ccx.ecx.block_mut().set_beneficiary(*newCoinbase);
Ok(Default::default())
}
}
Expand All @@ -502,7 +503,7 @@ impl<CTX: FoundryContextExt> Cheatcode<CTX> for difficultyCall {
"`difficulty` is not supported after the Paris hard fork, use `prevrandao` instead; \
see EIP-4399: https://eips.ethereum.org/EIPS/eip-4399"
);
ccx.ecx.block_mut().difficulty = *newDifficulty;
ccx.ecx.block_mut().set_difficulty(*newDifficulty);
Ok(Default::default())
}
}
Expand All @@ -511,7 +512,7 @@ impl<CTX: FoundryContextExt> Cheatcode<CTX> for feeCall {
fn apply_stateful(&self, ccx: &mut CheatsCtxt<'_, CTX>) -> Result {
let Self { newBasefee } = self;
ensure!(*newBasefee <= U256::from(u64::MAX), "base fee must be less than 2^64");
ccx.ecx.block_mut().basefee = newBasefee.saturating_to();
ccx.ecx.block_mut().set_basefee(newBasefee.saturating_to());
Ok(Default::default())
}
}
Expand All @@ -524,7 +525,7 @@ impl<CTX: FoundryContextExt> Cheatcode<CTX> for prevrandao_0Call {
"`prevrandao` is not supported before the Paris hard fork, use `difficulty` instead; \
see EIP-4399: https://eips.ethereum.org/EIPS/eip-4399"
);
ccx.ecx.block_mut().prevrandao = Some(*newPrevrandao);
ccx.ecx.block_mut().set_prevrandao(Some(*newPrevrandao));
Ok(Default::default())
}
}
Expand All @@ -537,7 +538,7 @@ impl<CTX: FoundryContextExt> Cheatcode<CTX> for prevrandao_1Call {
"`prevrandao` is not supported before the Paris hard fork, use `difficulty` instead; \
see EIP-4399: https://eips.ethereum.org/EIPS/eip-4399"
);
ccx.ecx.block_mut().prevrandao = Some((*newPrevrandao).into());
ccx.ecx.block_mut().set_prevrandao(Some((*newPrevrandao).into()));
Ok(Default::default())
}
}
Expand All @@ -550,9 +551,9 @@ impl<CTX: FoundryContextExt> Cheatcode<CTX> for blobhashesCall {
"`blobhashes` is not supported before the Cancun hard fork; \
see EIP-4844: https://eips.ethereum.org/EIPS/eip-4844"
);
ccx.ecx.tx_mut().blob_hashes.clone_from(hashes);
ccx.ecx.tx_mut().set_blob_hashes(hashes.clone());
// force this as 4844 txtype
ccx.ecx.tx_mut().tx_type = EIP4844_TX_TYPE_ID;
ccx.ecx.tx_mut().set_tx_type(EIP4844_TX_TYPE_ID);
Ok(Default::default())
}
}
Expand All @@ -572,7 +573,7 @@ impl<CTX: ContextTr> Cheatcode<CTX> for getBlobhashesCall {
impl<CTX: FoundryContextExt> Cheatcode<CTX> for rollCall {
fn apply_stateful(&self, ccx: &mut CheatsCtxt<'_, CTX>) -> Result {
let Self { newHeight } = self;
ccx.ecx.block_mut().number = *newHeight;
ccx.ecx.block_mut().set_number(*newHeight);
Ok(Default::default())
}
}
Expand All @@ -588,15 +589,15 @@ impl<CTX: FoundryContextExt> Cheatcode<CTX> for txGasPriceCall {
fn apply_stateful(&self, ccx: &mut CheatsCtxt<'_, CTX>) -> Result {
let Self { newGasPrice } = self;
ensure!(*newGasPrice <= U256::from(u64::MAX), "gas price must be less than 2^64");
ccx.ecx.tx_mut().gas_price = newGasPrice.saturating_to();
ccx.ecx.tx_mut().set_gas_price(newGasPrice.saturating_to());
Ok(Default::default())
}
}

impl<CTX: FoundryContextExt> Cheatcode<CTX> for warpCall {
fn apply_stateful(&self, ccx: &mut CheatsCtxt<'_, CTX>) -> Result {
let Self { newTimestamp } = self;
ccx.ecx.block_mut().timestamp = *newTimestamp;
ccx.ecx.block_mut().set_timestamp(*newTimestamp);
Ok(Default::default())
}
}
Expand Down Expand Up @@ -1136,17 +1137,18 @@ impl<CTX: CheatsCtxExt> Cheatcode<CTX> for executeTransactionCall {
let cached_env = ccx.ecx.to_env();

// Override env for isolated execution.
ccx.ecx.block_mut().basefee = 0;
ccx.ecx.block_mut().set_basefee(0);
*ccx.ecx.tx_mut() = tx_env;
ccx.ecx.tx_mut().gas_price = 0;
ccx.ecx.tx_mut().gas_priority_fee = None;
ccx.ecx.tx_mut().set_gas_price(0);
ccx.ecx.tx_mut().set_gas_priority_fee(None);

// Enable nonce checks for realistic simulation.
ccx.ecx.cfg_mut().disable_nonce_check = false;
ccx.ecx.cfg_mut().set_disable_nonce_check(false);

// EIP-3860: enforce initcode size limit.
ccx.ecx.cfg_mut().limit_contract_initcode_size =
Some(revm::primitives::eip3860::MAX_INITCODE_SIZE);
ccx.ecx
.cfg_mut()
.set_limit_contract_initcode_size(Some(revm::primitives::eip3860::MAX_INITCODE_SIZE));

// Snapshot the modified env for EVM construction.
let modified_env = ccx.ecx.to_env();
Expand Down
30 changes: 15 additions & 15 deletions crates/cheatcodes/src/inspector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ use foundry_common::{
mapping_slots::{MappingSlots, step as mapping_step},
};
use foundry_evm_core::{
Breakpoints, Env, FoundryInspectorExt,
Breakpoints, Env, FoundryInspectorExt, FoundryTransaction,
abi::Vm::stopExpectSafeMemoryCall,
backend::{DatabaseError, DatabaseExt, FoundryJournalExt, RevertDiagnostic},
constants::{CHEATCODE_ADDRESS, HARDHAT_CONSOLE_ADDRESS, MAGIC_ASSUME},
Expand Down Expand Up @@ -748,10 +748,10 @@ impl Cheatcodes {
/// access lists themselves.
fn apply_accesslist<CTX: FoundryContextExt>(&mut self, ecx: &mut CTX) {
if let Some(access_list) = &self.access_list {
ecx.tx_mut().access_list = access_list.clone();
ecx.tx_mut().set_access_list(access_list.clone());

if ecx.tx().tx_type() == TransactionType::Legacy as u8 {
ecx.tx_mut().tx_type = TransactionType::Eip2930 as u8;
ecx.tx_mut().set_tx_type(TransactionType::Eip2930 as u8);
}
}
}
Expand Down Expand Up @@ -791,7 +791,7 @@ impl Cheatcodes {
) -> Option<CallOutcome> {
// Apply custom execution evm version.
if let Some(spec_id) = self.execution_evm_version {
ecx.cfg_mut().spec = spec_id;
ecx.cfg_mut().set_spec(spec_id);
}

let gas = Gas::new(call.gas_limit);
Expand Down Expand Up @@ -930,7 +930,7 @@ impl Cheatcodes {
call.target_address = prank.new_caller;
call.caller = prank.new_caller;
if let Some(new_origin) = prank.new_origin {
ecx.tx_mut().caller = new_origin;
ecx.tx_mut().set_caller(new_origin);
}
}

Expand All @@ -947,7 +947,7 @@ impl Cheatcodes {

// At the target depth, or deeper, we set `tx.origin`
if let Some(new_origin) = prank.new_origin {
ecx.tx_mut().caller = new_origin;
ecx.tx_mut().set_caller(new_origin);
prank_applied = true;
}

Expand Down Expand Up @@ -976,7 +976,7 @@ impl Cheatcodes {
// At the target depth we set `msg.sender` & tx.origin.
// We are simulating the caller as being an EOA, so *both* must be set to the
// broadcast.origin.
ecx.tx_mut().caller = broadcast.new_origin;
ecx.tx_mut().set_caller(broadcast.new_origin);

call.caller = broadcast.new_origin;
// Add a `legacy` transaction to the VecDeque. We use a legacy transaction here
Expand Down Expand Up @@ -1212,7 +1212,7 @@ impl<CTX: CheatsCtxExt> Inspector<CTX> for Cheatcodes {
*ecx.block_mut() = block;
}
if let Some(gas_price) = self.gas_price.take() {
ecx.tx_mut().gas_price = gas_price;
ecx.tx_mut().set_gas_price(gas_price);
}

// Record gas for current frame.
Expand Down Expand Up @@ -1327,7 +1327,7 @@ impl<CTX: CheatsCtxExt> Inspector<CTX> for Cheatcodes {
if let Some(prank) = &self.get_prank(curr_depth)
&& curr_depth == prank.depth
{
ecx.tx_mut().caller = prank.prank_origin;
ecx.tx_mut().set_caller(prank.prank_origin);

// Clean single-call prank once we have returned to the original depth
if prank.single_call {
Expand All @@ -1339,7 +1339,7 @@ impl<CTX: CheatsCtxExt> Inspector<CTX> for Cheatcodes {
if let Some(broadcast) = &self.broadcast
&& curr_depth == broadcast.depth
{
ecx.tx_mut().caller = broadcast.original_origin;
ecx.tx_mut().set_caller(broadcast.original_origin);

// Clean single-call broadcast once we have returned to the original depth
if broadcast.single_call {
Expand Down Expand Up @@ -1719,7 +1719,7 @@ impl<CTX: CheatsCtxExt> Inspector<CTX> for Cheatcodes {
fn create(&mut self, ecx: &mut CTX, mut input: &mut CreateInputs) -> Option<CreateOutcome> {
// Apply custom execution evm version.
if let Some(spec_id) = self.execution_evm_version {
ecx.cfg_mut().spec = spec_id;
ecx.cfg_mut().set_spec(spec_id);
}

let gas = Gas::new(input.gas_limit());
Expand Down Expand Up @@ -1757,7 +1757,7 @@ impl<CTX: CheatsCtxExt> Inspector<CTX> for Cheatcodes {

// At the target depth, or deeper, we set `tx.origin`
if let Some(new_origin) = prank.new_origin {
ecx.tx_mut().caller = new_origin;
ecx.tx_mut().set_caller(new_origin);
prank_applied = true;
}

Expand Down Expand Up @@ -1786,7 +1786,7 @@ impl<CTX: CheatsCtxExt> Inspector<CTX> for Cheatcodes {
});
}

ecx.tx_mut().caller = broadcast.new_origin;
ecx.tx_mut().set_caller(broadcast.new_origin);

if curr_depth == broadcast.depth || broadcast.deploy_from_code {
// Reset deploy from code flag for upcoming calls;
Expand Down Expand Up @@ -1851,7 +1851,7 @@ impl<CTX: CheatsCtxExt> Inspector<CTX> for Cheatcodes {
if let Some(prank) = &self.get_prank(curr_depth)
&& curr_depth == prank.depth
{
ecx.tx_mut().caller = prank.prank_origin;
ecx.tx_mut().set_caller(prank.prank_origin);

// Clean single-call prank once we have returned to the original depth
if prank.single_call {
Expand All @@ -1863,7 +1863,7 @@ impl<CTX: CheatsCtxExt> Inspector<CTX> for Cheatcodes {
if let Some(broadcast) = &self.broadcast
&& curr_depth == broadcast.depth
{
ecx.tx_mut().caller = broadcast.original_origin;
ecx.tx_mut().set_caller(broadcast.original_origin);

// Clean single-call broadcast once we have returned to the original depth
if broadcast.single_call {
Expand Down
Loading
Loading