From 47370fe77e6ef71166123d1fb2ce029f600ec35b Mon Sep 17 00:00:00 2001 From: Agusrodri Date: Thu, 23 May 2024 15:36:16 -0700 Subject: [PATCH 1/3] modify set_code to receive caller --- src/executor/stack/executor.rs | 7 +++++-- src/executor/stack/memory.rs | 3 ++- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/src/executor/stack/executor.rs b/src/executor/stack/executor.rs index b02d9b05..b8229012 100644 --- a/src/executor/stack/executor.rs +++ b/src/executor/stack/executor.rs @@ -212,7 +212,7 @@ pub trait StackState<'config>: Backend { fn log(&mut self, address: H160, topics: Vec, data: Vec); fn set_deleted(&mut self, address: H160); fn set_created(&mut self, address: H160); - fn set_code(&mut self, address: H160, code: Vec); + fn set_code(&mut self, address: H160, code: Vec, caller: Option) -> Result<(), ExitError>; fn transfer(&mut self, transfer: Transfer) -> Result<(), ExitError>; fn reset_balance(&mut self, address: H160); fn touch(&mut self, address: H160); @@ -1073,10 +1073,13 @@ impl<'config, 'precompiles, S: StackState<'config>, P: PrecompileSet> return (e.into(), None, Vec::new()); } let exit_result = self.exit_substate(StackExitKind::Succeeded); + let set_code_result = self.state.set_code(address, out, caller); + if let Err(e) = set_code_result { + return (e.into(), None, Vec::new()); + } if let Err(e) = exit_result { return (e.into(), None, Vec::new()); } - self.state.set_code(address, out); (ExitReason::Succeed(s), Some(address), Vec::new()) } Err(e) => { diff --git a/src/executor/stack/memory.rs b/src/executor/stack/memory.rs index f14d6ca9..ebffd94c 100644 --- a/src/executor/stack/memory.rs +++ b/src/executor/stack/memory.rs @@ -594,8 +594,9 @@ impl<'config, B: Backend> StackState<'config> for MemoryStackState<'_, 'config, self.substate.set_created(address) } - fn set_code(&mut self, address: H160, code: Vec) { + fn set_code(&mut self, address: H160, code: Vec, _caller: Option) -> Result<(), ExitError> { self.substate.set_code(address, code, self.backend); + Ok(()) } fn transfer(&mut self, transfer: Transfer) -> Result<(), ExitError> { From 9dd150e5a7cbbb892f84489cfa2fbc0db0258b33 Mon Sep 17 00:00:00 2001 From: Agusrodri Date: Thu, 23 May 2024 15:36:16 -0700 Subject: [PATCH 2/3] more changes --- src/executor/stack/executor.rs | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/executor/stack/executor.rs b/src/executor/stack/executor.rs index b8229012..a31dc8c1 100644 --- a/src/executor/stack/executor.rs +++ b/src/executor/stack/executor.rs @@ -327,7 +327,7 @@ impl<'config, 'precompiles, S: StackState<'config>, P: PrecompileSet> kind: RuntimeKind::Execute, inner: MaybeBorrowed::Borrowed(runtime), }); - let (reason, _, _) = self.execute_with_call_stack(&mut call_stack); + let (reason, _, _) = self.execute_with_call_stack(&mut call_stack, None); reason } @@ -335,6 +335,7 @@ impl<'config, 'precompiles, S: StackState<'config>, P: PrecompileSet> fn execute_with_call_stack( &mut self, call_stack: &mut Vec>, + caller: Option, ) -> (ExitReason, Option, Vec) { // This `interrupt_runtime` is used to pass the runtime obtained from the // `Capture::Trap` branch in the match below back to the top of the call stack. @@ -378,6 +379,7 @@ impl<'config, 'precompiles, S: StackState<'config>, P: PrecompileSet> created_address, reason, runtime.inner.machine().return_value(), + caller, ); (reason, maybe_address, return_data) } @@ -486,7 +488,7 @@ impl<'config, 'precompiles, S: StackState<'config>, P: PrecompileSet> Capture::Trap(rt) => { let mut cs = Vec::with_capacity(DEFAULT_CALL_STACK_CAPACITY); cs.push(rt.0); - let (s, _, v) = self.execute_with_call_stack(&mut cs); + let (s, _, v) = self.execute_with_call_stack(&mut cs, None); emit_exit!(s, v) } } @@ -544,7 +546,7 @@ impl<'config, 'precompiles, S: StackState<'config>, P: PrecompileSet> Capture::Trap(rt) => { let mut cs = Vec::with_capacity(DEFAULT_CALL_STACK_CAPACITY); cs.push(rt.0); - let (s, _, v) = self.execute_with_call_stack(&mut cs); + let (s, _, v) = self.execute_with_call_stack(&mut cs, None); emit_exit!(s, v) } } @@ -675,7 +677,7 @@ impl<'config, 'precompiles, S: StackState<'config>, P: PrecompileSet> Capture::Trap(rt) => { let mut cs = Vec::with_capacity(DEFAULT_CALL_STACK_CAPACITY); cs.push(rt.0); - let (s, _, v) = self.execute_with_call_stack(&mut cs); + let (s, _, v) = self.execute_with_call_stack(&mut cs, Some(caller)); emit_exit!(s, v) } } @@ -1028,6 +1030,7 @@ impl<'config, 'precompiles, S: StackState<'config>, P: PrecompileSet> created_address: H160, reason: ExitReason, return_data: Vec, + caller: Option ) -> (ExitReason, Option, Vec) { fn check_first_byte(config: &Config, code: &[u8]) -> Result<(), ExitError> { if config.disallow_executable_format && Some(&Opcode::EOFMAGIC.as_u8()) == code.first() @@ -1526,7 +1529,7 @@ impl<'config, S: StackState<'config>, P: PrecompileSet> PrecompileHandle let mut call_stack = Vec::with_capacity(DEFAULT_CALL_STACK_CAPACITY); call_stack.push(rt.0); let (reason, _, return_data) = - self.executor.execute_with_call_stack(&mut call_stack); + self.executor.execute_with_call_stack(&mut call_stack, None); emit_exit!(reason, return_data) } } From 4737aecce2f1b278384709c0b19fe08825685445 Mon Sep 17 00:00:00 2001 From: girazoki Date: Fri, 7 Mar 2025 15:48:08 +0100 Subject: [PATCH 3/3] fmt --- src/executor/stack/executor.rs | 9 +++++++-- src/executor/stack/memory.rs | 7 ++++++- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/src/executor/stack/executor.rs b/src/executor/stack/executor.rs index a31dc8c1..d6b3677c 100644 --- a/src/executor/stack/executor.rs +++ b/src/executor/stack/executor.rs @@ -212,7 +212,12 @@ pub trait StackState<'config>: Backend { fn log(&mut self, address: H160, topics: Vec, data: Vec); fn set_deleted(&mut self, address: H160); fn set_created(&mut self, address: H160); - fn set_code(&mut self, address: H160, code: Vec, caller: Option) -> Result<(), ExitError>; + fn set_code( + &mut self, + address: H160, + code: Vec, + caller: Option, + ) -> Result<(), ExitError>; fn transfer(&mut self, transfer: Transfer) -> Result<(), ExitError>; fn reset_balance(&mut self, address: H160); fn touch(&mut self, address: H160); @@ -1030,7 +1035,7 @@ impl<'config, 'precompiles, S: StackState<'config>, P: PrecompileSet> created_address: H160, reason: ExitReason, return_data: Vec, - caller: Option + caller: Option, ) -> (ExitReason, Option, Vec) { fn check_first_byte(config: &Config, code: &[u8]) -> Result<(), ExitError> { if config.disallow_executable_format && Some(&Opcode::EOFMAGIC.as_u8()) == code.first() diff --git a/src/executor/stack/memory.rs b/src/executor/stack/memory.rs index ebffd94c..e1e6f4d0 100644 --- a/src/executor/stack/memory.rs +++ b/src/executor/stack/memory.rs @@ -594,7 +594,12 @@ impl<'config, B: Backend> StackState<'config> for MemoryStackState<'_, 'config, self.substate.set_created(address) } - fn set_code(&mut self, address: H160, code: Vec, _caller: Option) -> Result<(), ExitError> { + fn set_code( + &mut self, + address: H160, + code: Vec, + _caller: Option, + ) -> Result<(), ExitError> { self.substate.set_code(address, code, self.backend); Ok(()) }