Skip to content

Commit fc83ff9

Browse files
girazokiAgusrodri
andauthored
Bring changes set code (#312)
* modify set_code to receive caller * more changes * fmt --------- Co-authored-by: Agusrodri <[email protected]>
1 parent 4ecc569 commit fc83ff9

File tree

2 files changed

+25
-8
lines changed

2 files changed

+25
-8
lines changed

src/executor/stack/executor.rs

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,12 @@ pub trait StackState<'config>: Backend {
212212
fn log(&mut self, address: H160, topics: Vec<H256>, data: Vec<u8>);
213213
fn set_deleted(&mut self, address: H160);
214214
fn set_created(&mut self, address: H160);
215-
fn set_code(&mut self, address: H160, code: Vec<u8>);
215+
fn set_code(
216+
&mut self,
217+
address: H160,
218+
code: Vec<u8>,
219+
caller: Option<H160>,
220+
) -> Result<(), ExitError>;
216221
fn transfer(&mut self, transfer: Transfer) -> Result<(), ExitError>;
217222
fn reset_balance(&mut self, address: H160);
218223
fn touch(&mut self, address: H160);
@@ -327,14 +332,15 @@ impl<'config, 'precompiles, S: StackState<'config>, P: PrecompileSet>
327332
kind: RuntimeKind::Execute,
328333
inner: MaybeBorrowed::Borrowed(runtime),
329334
});
330-
let (reason, _, _) = self.execute_with_call_stack(&mut call_stack);
335+
let (reason, _, _) = self.execute_with_call_stack(&mut call_stack, None);
331336
reason
332337
}
333338

334339
/// Execute using Runtimes on the call_stack until it returns.
335340
fn execute_with_call_stack(
336341
&mut self,
337342
call_stack: &mut Vec<TaggedRuntime<'_>>,
343+
caller: Option<H160>,
338344
) -> (ExitReason, Option<H160>, Vec<u8>) {
339345
// This `interrupt_runtime` is used to pass the runtime obtained from the
340346
// `Capture::Trap` branch in the match below back to the top of the call stack.
@@ -378,6 +384,7 @@ impl<'config, 'precompiles, S: StackState<'config>, P: PrecompileSet>
378384
created_address,
379385
reason,
380386
runtime.inner.machine().return_value(),
387+
caller,
381388
);
382389
(reason, maybe_address, return_data)
383390
}
@@ -486,7 +493,7 @@ impl<'config, 'precompiles, S: StackState<'config>, P: PrecompileSet>
486493
Capture::Trap(rt) => {
487494
let mut cs = Vec::with_capacity(DEFAULT_CALL_STACK_CAPACITY);
488495
cs.push(rt.0);
489-
let (s, _, v) = self.execute_with_call_stack(&mut cs);
496+
let (s, _, v) = self.execute_with_call_stack(&mut cs, None);
490497
emit_exit!(s, v)
491498
}
492499
}
@@ -544,7 +551,7 @@ impl<'config, 'precompiles, S: StackState<'config>, P: PrecompileSet>
544551
Capture::Trap(rt) => {
545552
let mut cs = Vec::with_capacity(DEFAULT_CALL_STACK_CAPACITY);
546553
cs.push(rt.0);
547-
let (s, _, v) = self.execute_with_call_stack(&mut cs);
554+
let (s, _, v) = self.execute_with_call_stack(&mut cs, None);
548555
emit_exit!(s, v)
549556
}
550557
}
@@ -675,7 +682,7 @@ impl<'config, 'precompiles, S: StackState<'config>, P: PrecompileSet>
675682
Capture::Trap(rt) => {
676683
let mut cs = Vec::with_capacity(DEFAULT_CALL_STACK_CAPACITY);
677684
cs.push(rt.0);
678-
let (s, _, v) = self.execute_with_call_stack(&mut cs);
685+
let (s, _, v) = self.execute_with_call_stack(&mut cs, Some(caller));
679686
emit_exit!(s, v)
680687
}
681688
}
@@ -1028,6 +1035,7 @@ impl<'config, 'precompiles, S: StackState<'config>, P: PrecompileSet>
10281035
created_address: H160,
10291036
reason: ExitReason,
10301037
return_data: Vec<u8>,
1038+
caller: Option<H160>,
10311039
) -> (ExitReason, Option<H160>, Vec<u8>) {
10321040
fn check_first_byte(config: &Config, code: &[u8]) -> Result<(), ExitError> {
10331041
if config.disallow_executable_format && Some(&Opcode::EOFMAGIC.as_u8()) == code.first()
@@ -1073,10 +1081,13 @@ impl<'config, 'precompiles, S: StackState<'config>, P: PrecompileSet>
10731081
return (e.into(), None, Vec::new());
10741082
}
10751083
let exit_result = self.exit_substate(StackExitKind::Succeeded);
1084+
let set_code_result = self.state.set_code(address, out, caller);
1085+
if let Err(e) = set_code_result {
1086+
return (e.into(), None, Vec::new());
1087+
}
10761088
if let Err(e) = exit_result {
10771089
return (e.into(), None, Vec::new());
10781090
}
1079-
self.state.set_code(address, out);
10801091
(ExitReason::Succeed(s), Some(address), Vec::new())
10811092
}
10821093
Err(e) => {
@@ -1523,7 +1534,7 @@ impl<'config, S: StackState<'config>, P: PrecompileSet> PrecompileHandle
15231534
let mut call_stack = Vec::with_capacity(DEFAULT_CALL_STACK_CAPACITY);
15241535
call_stack.push(rt.0);
15251536
let (reason, _, return_data) =
1526-
self.executor.execute_with_call_stack(&mut call_stack);
1537+
self.executor.execute_with_call_stack(&mut call_stack, None);
15271538
emit_exit!(reason, return_data)
15281539
}
15291540
}

src/executor/stack/memory.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -594,8 +594,14 @@ impl<'config, B: Backend> StackState<'config> for MemoryStackState<'_, 'config,
594594
self.substate.set_created(address)
595595
}
596596

597-
fn set_code(&mut self, address: H160, code: Vec<u8>) {
597+
fn set_code(
598+
&mut self,
599+
address: H160,
600+
code: Vec<u8>,
601+
_caller: Option<H160>,
602+
) -> Result<(), ExitError> {
598603
self.substate.set_code(address, code, self.backend);
604+
Ok(())
599605
}
600606

601607
fn transfer(&mut self, transfer: Transfer) -> Result<(), ExitError> {

0 commit comments

Comments
 (0)