diff --git a/Cargo.lock b/Cargo.lock index 6e65f0fcb281..a96ecd6ede09 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3587,7 +3587,7 @@ dependencies = [ [[package]] name = "revm" version = "1.2.0" -source = "git+https://github.com/bluealloy/revm#db1812f5f53b1b00c9f1bc4a0b7484dd291b4b9c" +source = "git+https://github.com/bluealloy/revm#7a5a2cdddf253c8500ba46eef3f05c1f1c59f0d1" dependencies = [ "arrayref", "auto_impl", @@ -3603,7 +3603,7 @@ dependencies = [ [[package]] name = "revm_precompiles" version = "0.4.0" -source = "git+https://github.com/bluealloy/revm#db1812f5f53b1b00c9f1bc4a0b7484dd291b4b9c" +source = "git+https://github.com/bluealloy/revm#7a5a2cdddf253c8500ba46eef3f05c1f1c59f0d1" dependencies = [ "bytes", "k256", diff --git a/evm/src/executor/inspector/cheatcodes/env.rs b/evm/src/executor/inspector/cheatcodes/env.rs index 0ce0ef8a9edf..cea7a966d4d3 100644 --- a/evm/src/executor/inspector/cheatcodes/env.rs +++ b/evm/src/executor/inspector/cheatcodes/env.rs @@ -41,8 +41,9 @@ fn prank( new_caller, new_origin, // Note: When calling a cheatcode, the depth is not increased. Because of that, the depth - // we actually want to prank at is 1 level deeper. - depth: depth + 1, + // we actually want to prank at is 1 level deeper. However, because pranks are applied + // *before* the depth is increased, we need to go a whole TWO levels deeper! + depth: depth + 2, single_call, }; diff --git a/evm/src/executor/inspector/cheatcodes/mod.rs b/evm/src/executor/inspector/cheatcodes/mod.rs index efca2167beb1..52878cd302d9 100644 --- a/evm/src/executor/inspector/cheatcodes/mod.rs +++ b/evm/src/executor/inspector/cheatcodes/mod.rs @@ -87,7 +87,7 @@ where fn call( &mut self, data: &mut EVMData<'_, DB>, - call: &CallInputs, + call: &mut CallInputs, _: bool, ) -> (Return, Gas, Bytes) { if call.contract == *CHEATCODE_ADDRESS { @@ -116,34 +116,26 @@ where } } - (Return::Continue, Gas::new(call.gas_limit), Bytes::new()) - } - } - - fn initialize_interp( - &mut self, - interpreter: &mut Interpreter, - data: &mut EVMData<'_, DB>, - _: bool, - ) -> Return { - // Apply our prank - if let Some(prank) = &self.prank { - if data.subroutine.depth() >= prank.depth && - interpreter.contract.caller == prank.prank_caller - { - // At the target depth we set `msg.sender` - if data.subroutine.depth() == prank.depth { - interpreter.contract.caller = prank.new_caller; - } - - // At the target depth, or deeper, we set `tx.origin` - if let Some(new_origin) = prank.new_origin { - data.env.tx.caller = new_origin; + // Apply our prank + if let Some(prank) = &self.prank { + if data.subroutine.depth() >= prank.depth && + call.context.caller == prank.prank_caller + { + // At the target depth we set `msg.sender` + if data.subroutine.depth() == prank.depth { + call.context.caller = prank.new_caller; + call.transfer.source = prank.new_caller; + } + + // At the target depth, or deeper, we set `tx.origin` + if let Some(new_origin) = prank.new_origin { + data.env.tx.caller = new_origin; + } } } - } - Return::Continue + (Return::Continue, Gas::new(call.gas_limit), Bytes::new()) + } } fn step(&mut self, interpreter: &mut Interpreter, _: &mut EVMData<'_, DB>, _: bool) -> Return { @@ -271,6 +263,29 @@ where (status, remaining_gas, retdata) } + fn create( + &mut self, + data: &mut EVMData<'_, DB>, + call: &mut CreateInputs, + ) -> (Return, Option
, Gas, Bytes) { + // Apply our prank + if let Some(prank) = &self.prank { + if data.subroutine.depth() >= prank.depth && call.caller == prank.prank_caller { + // At the target depth we set `msg.sender` + if data.subroutine.depth() == prank.depth { + call.caller = prank.new_caller; + } + + // At the target depth, or deeper, we set `tx.origin` + if let Some(new_origin) = prank.new_origin { + data.env.tx.caller = new_origin; + } + } + } + + (Return::Continue, None, Gas::new(call.gas_limit), Bytes::new()) + } + fn create_end( &mut self, data: &mut EVMData<'_, DB>, diff --git a/evm/src/executor/inspector/debugger.rs b/evm/src/executor/inspector/debugger.rs index 900af7cdbd2f..5c0feb241d1d 100644 --- a/evm/src/executor/inspector/debugger.rs +++ b/evm/src/executor/inspector/debugger.rs @@ -97,7 +97,7 @@ where fn call( &mut self, data: &mut EVMData<'_, DB>, - call: &CallInputs, + call: &mut CallInputs, _: bool, ) -> (Return, Gas, Bytes) { self.enter(data.subroutine.depth() as usize, call.contract, false); @@ -201,7 +201,7 @@ where fn create( &mut self, data: &mut EVMData<'_, DB>, - call: &CreateInputs, + call: &mut CreateInputs, ) -> (Return, Option
, Gas, Bytes) { // TODO: Does this increase gas cost? data.subroutine.load_account(call.caller, data.db); diff --git a/evm/src/executor/inspector/logs.rs b/evm/src/executor/inspector/logs.rs index a00e7f6193f0..33390c5e8f97 100644 --- a/evm/src/executor/inspector/logs.rs +++ b/evm/src/executor/inspector/logs.rs @@ -61,7 +61,7 @@ where fn call( &mut self, _: &mut EVMData<'_, DB>, - call: &CallInputs, + call: &mut CallInputs, _: bool, ) -> (Return, Gas, Bytes) { if call.contract == *HARDHAT_CONSOLE_ADDRESS { diff --git a/evm/src/executor/inspector/stack.rs b/evm/src/executor/inspector/stack.rs index 7110c5c37c47..b651d5a4666e 100644 --- a/evm/src/executor/inspector/stack.rs +++ b/evm/src/executor/inspector/stack.rs @@ -109,7 +109,7 @@ where fn call( &mut self, data: &mut EVMData<'_, DB>, - call: &CallInputs, + call: &mut CallInputs, is_static: bool, ) -> (Return, Gas, Bytes) { call_inspectors!( @@ -164,7 +164,7 @@ where fn create( &mut self, data: &mut EVMData<'_, DB>, - call: &CreateInputs, + call: &mut CreateInputs, ) -> (Return, Option
, Gas, Bytes) { call_inspectors!( inspector, diff --git a/evm/src/executor/inspector/tracer.rs b/evm/src/executor/inspector/tracer.rs index 91eb1548a24c..c6da35b8e34e 100644 --- a/evm/src/executor/inspector/tracer.rs +++ b/evm/src/executor/inspector/tracer.rs @@ -65,7 +65,7 @@ where fn call( &mut self, data: &mut EVMData<'_, DB>, - call: &CallInputs, + call: &mut CallInputs, _: bool, ) -> (Return, Gas, Bytes) { if call.contract != *HARDHAT_CONSOLE_ADDRESS { @@ -119,7 +119,7 @@ where fn create( &mut self, data: &mut EVMData<'_, DB>, - call: &CreateInputs, + call: &mut CreateInputs, ) -> (Return, Option
, Gas, Bytes) { // TODO: Does this increase gas cost? data.subroutine.load_account(call.caller, data.db);