foundry_evm/inspectors/
script.rs1use alloy_primitives::Address;
2use evm2::{
3 EvmTypesHost, Inspector, InspectorConfig,
4 interpreter::{Interpreter, op},
5};
6use foundry_evm_core::utils::opcodes;
7
8const ADDRESS_IN_SCRIPT: &[u8] = b"Usage of `address(this)` detected in script contract. Script contracts are ephemeral and their addresses should not be relied upon.";
10
11#[derive(Clone, Debug, Default)]
15pub struct ScriptExecutionInspector {
16 pub script_address: Address,
18}
19
20impl<T: EvmTypesHost> Inspector<T> for ScriptExecutionInspector {
21 fn inspector_config(&self) -> InspectorConfig {
22 InspectorConfig::new().with_steps(opcodes([op::ADDRESS]))
23 }
24
25 fn step(&mut self, interp: &mut Interpreter<'_, '_, T>) {
26 let message = interp.message();
29 if interp.opcode() == op::ADDRESS
30 && message.destination == self.script_address
31 && message.code_address == self.script_address
32 {
33 foundry_cheatcodes::revert_frame(interp, ADDRESS_IN_SCRIPT);
34 }
35 }
36}