Skip to content

Commit 938f1e9

Browse files
authored
Update stack.rs
1 parent f12aae4 commit 938f1e9

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

crates/evm/evm/src/inspectors/stack.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -789,6 +789,16 @@ impl Inspector<&mut dyn DatabaseExt> for InspectorStackRefMut<'_> {
789789
],
790790
|inspector| inspector.step(interpreter, ecx),
791791
);
792+
793+
// Check for address(this) usage in the main script contract, but ignore if it's within a DELEGATECALL context
794+
if let Some(script_addr) = self.inner.script_address {
795+
if interpreter.current_opcode() == opcode::ADDRESS &&
796+
interpreter.contract.address == script_addr &&
797+
interpreter.call_context().scheme != CallScheme::DelegateCall
798+
{
799+
tracing::warn!(target: "forge::script", script_address=%script_addr, "Usage of `address(this)` detected directly in script contract. Script contracts are ephemeral and their addresses should not be relied upon.");
800+
}
801+
}
792802
}
793803

794804
fn step_end(

0 commit comments

Comments
 (0)