From c6be1aad72659a8eaa4f8e375c926c336cb7f657 Mon Sep 17 00:00:00 2001 From: GregTheDev Date: Wed, 6 Aug 2025 00:17:30 +0700 Subject: [PATCH 1/2] chore: fix regressions --- crates/cheatcodes/src/credible.rs | 60 ++++++++++++------------------ crates/cheatcodes/src/inspector.rs | 28 ++------------ 2 files changed, 28 insertions(+), 60 deletions(-) diff --git a/crates/cheatcodes/src/credible.rs b/crates/cheatcodes/src/credible.rs index 0d85d93fcf7e4..569e4dda28904 100644 --- a/crates/cheatcodes/src/credible.rs +++ b/crates/cheatcodes/src/credible.rs @@ -1,6 +1,6 @@ use crate::{inspector::Ecx, Cheatcode, Cheatcodes, CheatcodesExecutor, CheatsCtxt, Result, Vm::*}; use alloy_primitives::{Bytes, FixedBytes, TxKind}; -use alloy_sol_types::{Revert, SolError, SolValue}; +use alloy_sol_types::{Revert, SolError}; use assertion_executor::{ db::{fork_db::ForkDb, DatabaseCommit, DatabaseRef}, primitives::{ @@ -108,8 +108,7 @@ pub fn execute_assertion( ecx: Ecx, executor: &mut dyn CheatcodesExecutor, cheats: &mut Cheatcodes, - is_create: bool, -) -> Result, crate::Error> { +) -> Result<(), crate::Error> { let spec_id = ecx.cfg.spec; let block = ecx.block.clone(); let state = ecx.journaled_state.state.clone(); @@ -173,12 +172,6 @@ pub fn execute_assertion( .validate_transaction_ext_db(block.clone(), tx_env.clone(), &mut fork_db, &mut ext_db) .map_err(|e| format!("Assertion Executor Error: {e:#?}"))?; - ecx.journaled_state.inner.checkpoint(); - - if let Some(expected) = &mut cheats.expected_revert { - expected.max_depth = max(ecx.journaled_state.depth(), expected.max_depth); - } - let mut inspector = executor.get_inspector(cheats); // if transaction execution reverted, log the revert reason if !tx_validation.result_and_state.result.is_success() { @@ -194,6 +187,15 @@ pub fn execute_assertion( let tx_gas_used = tx_validation.result_and_state.result.gas_used(); if total_assertions_ran != 1 { + // If assertions were not executed, we need to update expert revert depth to + // allow for matching on this revert condition, as we will not execute against + // test evm in this case. + ecx.journaled_state.inner.checkpoint(); + + std::mem::drop(inspector); + if let Some(expected) = &mut cheats.expected_revert { + expected.max_depth = max(ecx.journaled_state.depth(), expected.max_depth); + } bail!("Expected 1 assertion to be executed, but {total_assertions_ran} were executed."); } @@ -220,7 +222,19 @@ pub fn execute_assertion( ); inspector.console_log(&assertion_gas_message); + // Drop the inspector to avoid borrow checker issues + std::mem::drop(inspector); + if !tx_validation.is_valid() { + // If invalidated, we don't execute against test evm, so we must update expected depth + // for expect revert cheatcode. + ecx.journaled_state.inner.checkpoint(); + + if let Some(expected) = &mut cheats.expected_revert { + expected.max_depth = max(ecx.journaled_state.depth(), expected.max_depth); + } + + let mut inspector = executor.get_inspector(cheats); match &assertion_fn_result.result { AssertionFunctionExecutionResult::AssertionContractDeployFailure(result) => { inspector.console_log(&format!( @@ -239,34 +253,8 @@ pub fn execute_assertion( return Err(crate::Error::from(output.clone())); } } - } else { - let journaled_state = &mut ecx.journaled_state.state; - for (address, account) in tx_validation.result_and_state.state { - let journaled_acct = journaled_state.get_mut(&address); - match journaled_acct { - Some(journaled_acct) => { - journaled_acct.info = account.info; - journaled_acct.status = journaled_acct.status.union(account.status); - for (index, value) in account.storage.iter() { - journaled_acct.storage.insert(*index, value.clone()); - } - } - None => { - journaled_state.insert(address, account); - } - } - } - } - - if is_create { - let address: Option
= - tx_validation.result_and_state.result.output().map(|output| { - Address::abi_decode(output).expect("Could not decode address from create output") - }); - Ok(address) - } else { - Ok(None) } + Ok(()) } fn decode_invalidated_assertion(execution_result: &ExecutionResult) -> Revert { diff --git a/crates/cheatcodes/src/inspector.rs b/crates/cheatcodes/src/inspector.rs index df6bdcd0ddf3d..8a9e4a7ffc27b 100644 --- a/crates/cheatcodes/src/inspector.rs +++ b/crates/cheatcodes/src/inspector.rs @@ -994,22 +994,14 @@ impl Cheatcodes { kind: TxKind::Call(call.target_address), }; - let call_outcome = match crate::credible::execute_assertion( + return match crate::credible::execute_assertion( &assertion, tx_attributes, ecx, executor, self, - false, ) { - Ok(_) => Some(CallOutcome { - result: InterpreterResult { - result: InstructionResult::Return, - output: Default::default(), - gas, - }, - memory_offset: call.return_memory_offset.clone(), - }), + Ok(_) => None, Err(err) => Some(CallOutcome { result: InterpreterResult { result: InstructionResult::Revert, @@ -1019,8 +1011,6 @@ impl Cheatcodes { memory_offset: call.return_memory_offset.clone(), }), }; - - return call_outcome; } None @@ -1712,22 +1702,14 @@ impl Inspector> for Cheatcodes { kind: TxKind::Create, }; - let call_outcome = match crate::credible::execute_assertion( + return match crate::credible::execute_assertion( &assertion, tx_attributes, ecx, &mut TransparentCheatcodesExecutor, self, - true, ) { - Ok(address) => Some(CreateOutcome { - result: InterpreterResult { - result: InstructionResult::Return, - output: Default::default(), - gas, - }, - address, - }), + Ok(_) => None, Err(err) => Some(CreateOutcome { result: InterpreterResult { result: InstructionResult::Revert, @@ -1737,8 +1719,6 @@ impl Inspector> for Cheatcodes { address: None, }), }; - - return call_outcome; } None From 0abe44bdac9a3cf8efc1c051fc1e90a279b20842 Mon Sep 17 00:00:00 2001 From: GregTheDev Date: Wed, 6 Aug 2025 00:26:19 +0700 Subject: [PATCH 2/2] Update crates/cheatcodes/src/credible.rs Co-authored-by: Frederik Signed-off-by: GregTheDev --- crates/cheatcodes/src/credible.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/cheatcodes/src/credible.rs b/crates/cheatcodes/src/credible.rs index 569e4dda28904..e8d7c77d70165 100644 --- a/crates/cheatcodes/src/credible.rs +++ b/crates/cheatcodes/src/credible.rs @@ -187,7 +187,7 @@ pub fn execute_assertion( let tx_gas_used = tx_validation.result_and_state.result.gas_used(); if total_assertions_ran != 1 { - // If assertions were not executed, we need to update expert revert depth to + // If assertions were not executed, we need to update expect revert depth to // allow for matching on this revert condition, as we will not execute against // test evm in this case. ecx.journaled_state.inner.checkpoint();