@@ -212,7 +212,12 @@ pub trait StackState<'config>: Backend {
212
212
fn log ( & mut self , address : H160 , topics : Vec < H256 > , data : Vec < u8 > ) ;
213
213
fn set_deleted ( & mut self , address : H160 ) ;
214
214
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 > ;
216
221
fn transfer ( & mut self , transfer : Transfer ) -> Result < ( ) , ExitError > ;
217
222
fn reset_balance ( & mut self , address : H160 ) ;
218
223
fn touch ( & mut self , address : H160 ) ;
@@ -327,14 +332,15 @@ impl<'config, 'precompiles, S: StackState<'config>, P: PrecompileSet>
327
332
kind : RuntimeKind :: Execute ,
328
333
inner : MaybeBorrowed :: Borrowed ( runtime) ,
329
334
} ) ;
330
- let ( reason, _, _) = self . execute_with_call_stack ( & mut call_stack) ;
335
+ let ( reason, _, _) = self . execute_with_call_stack ( & mut call_stack, None ) ;
331
336
reason
332
337
}
333
338
334
339
/// Execute using Runtimes on the call_stack until it returns.
335
340
fn execute_with_call_stack (
336
341
& mut self ,
337
342
call_stack : & mut Vec < TaggedRuntime < ' _ > > ,
343
+ caller : Option < H160 > ,
338
344
) -> ( ExitReason , Option < H160 > , Vec < u8 > ) {
339
345
// This `interrupt_runtime` is used to pass the runtime obtained from the
340
346
// `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>
378
384
created_address,
379
385
reason,
380
386
runtime. inner . machine ( ) . return_value ( ) ,
387
+ caller,
381
388
) ;
382
389
( reason, maybe_address, return_data)
383
390
}
@@ -486,7 +493,7 @@ impl<'config, 'precompiles, S: StackState<'config>, P: PrecompileSet>
486
493
Capture :: Trap ( rt) => {
487
494
let mut cs = Vec :: with_capacity ( DEFAULT_CALL_STACK_CAPACITY ) ;
488
495
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 ) ;
490
497
emit_exit ! ( s, v)
491
498
}
492
499
}
@@ -544,7 +551,7 @@ impl<'config, 'precompiles, S: StackState<'config>, P: PrecompileSet>
544
551
Capture :: Trap ( rt) => {
545
552
let mut cs = Vec :: with_capacity ( DEFAULT_CALL_STACK_CAPACITY ) ;
546
553
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 ) ;
548
555
emit_exit ! ( s, v)
549
556
}
550
557
}
@@ -675,7 +682,7 @@ impl<'config, 'precompiles, S: StackState<'config>, P: PrecompileSet>
675
682
Capture :: Trap ( rt) => {
676
683
let mut cs = Vec :: with_capacity ( DEFAULT_CALL_STACK_CAPACITY ) ;
677
684
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 ) ) ;
679
686
emit_exit ! ( s, v)
680
687
}
681
688
}
@@ -1028,6 +1035,7 @@ impl<'config, 'precompiles, S: StackState<'config>, P: PrecompileSet>
1028
1035
created_address : H160 ,
1029
1036
reason : ExitReason ,
1030
1037
return_data : Vec < u8 > ,
1038
+ caller : Option < H160 > ,
1031
1039
) -> ( ExitReason , Option < H160 > , Vec < u8 > ) {
1032
1040
fn check_first_byte ( config : & Config , code : & [ u8 ] ) -> Result < ( ) , ExitError > {
1033
1041
if config. disallow_executable_format && Some ( & Opcode :: EOFMAGIC . as_u8 ( ) ) == code. first ( )
@@ -1073,10 +1081,13 @@ impl<'config, 'precompiles, S: StackState<'config>, P: PrecompileSet>
1073
1081
return ( e. into ( ) , None , Vec :: new ( ) ) ;
1074
1082
}
1075
1083
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
+ }
1076
1088
if let Err ( e) = exit_result {
1077
1089
return ( e. into ( ) , None , Vec :: new ( ) ) ;
1078
1090
}
1079
- self . state . set_code ( address, out) ;
1080
1091
( ExitReason :: Succeed ( s) , Some ( address) , Vec :: new ( ) )
1081
1092
}
1082
1093
Err ( e) => {
@@ -1523,7 +1534,7 @@ impl<'config, S: StackState<'config>, P: PrecompileSet> PrecompileHandle
1523
1534
let mut call_stack = Vec :: with_capacity ( DEFAULT_CALL_STACK_CAPACITY ) ;
1524
1535
call_stack. push ( rt. 0 ) ;
1525
1536
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 ) ;
1527
1538
emit_exit ! ( reason, return_data)
1528
1539
}
1529
1540
}
0 commit comments