@@ -2,7 +2,9 @@ use crate::{
22 instructions:: InstructionProvider , EthFrame , ExecuteCommitEvm , ExecuteEvm , Handler ,
33 MainnetHandler , PrecompileProvider ,
44} ;
5- use context:: { result:: ResultAndState , ContextSetters , ContextTr , Evm , JournalTr , TxEnv } ;
5+ use context:: {
6+ result:: ResultAndState , ContextSetters , ContextTr , Evm , JournalTr , TransactionType , TxEnv ,
7+ } ;
68use database_interface:: DatabaseCommit ;
79use interpreter:: { interpreter:: EthInterpreter , InterpreterResult } ;
810use primitives:: { address, eip7825, Address , Bytes , TxKind } ;
@@ -16,15 +18,28 @@ pub const SYSTEM_ADDRESS: Address = address!("0xffffffffffffffffffffffffffffffff
1618/// The caller is set to be [`SYSTEM_ADDRESS`].
1719///
1820/// It is used inside [`SystemCallEvm`] and [`SystemCallCommitEvm`] traits to prepare EVM for system call execution.
19- pub trait SystemCallTx {
21+ pub trait SystemCallTx : Sized {
2022 /// Creates new transaction for system call.
21- fn new_system_tx ( data : Bytes , system_contract_address : Address ) -> Self ;
23+ fn new_system_tx ( system_contract_address : Address , data : Bytes ) -> Self {
24+ Self :: new_system_tx_with_caller ( SYSTEM_ADDRESS , system_contract_address, data)
25+ }
26+
27+ fn new_system_tx_with_caller (
28+ caller : Address ,
29+ system_contract_address : Address ,
30+ data : Bytes ,
31+ ) -> Self ;
2232}
2333
2434impl SystemCallTx for TxEnv {
25- fn new_system_tx ( data : Bytes , system_contract_address : Address ) -> Self {
35+ fn new_system_tx_with_caller (
36+ caller : Address ,
37+ system_contract_address : Address ,
38+ data : Bytes ,
39+ ) -> Self {
2640 TxEnv {
27- caller : SYSTEM_ADDRESS ,
41+ tx_type : TransactionType :: Legacy as u8 ,
42+ caller,
2843 data,
2944 kind : TxKind :: Call ( system_contract_address) ,
3045 gas_limit : eip7825:: TX_GAS_LIMIT_CAP ,
@@ -44,12 +59,22 @@ pub trait SystemCallEvm: ExecuteEvm {
4459 /// given values.
4560 ///
4661 /// Block values are taken into account and will determent how system call will be executed.
47- fn transact_system_call (
62+ fn transact_system_call_with_caller (
4863 & mut self ,
64+ caller : Address ,
4965 system_contract_address : Address ,
5066 data : Bytes ,
5167 ) -> Result < Self :: ExecutionResult , Self :: Error > ;
5268
69+ /// Calls [`SystemCallEvm::transact_system_call_with_caller`] with [`SYSTEM_ADDRESS`] as a caller.
70+ fn transact_system_call (
71+ & mut self ,
72+ system_contract_address : Address ,
73+ data : Bytes ,
74+ ) -> Result < Self :: ExecutionResult , Self :: Error > {
75+ self . transact_system_call_with_caller ( SYSTEM_ADDRESS , system_contract_address, data)
76+ }
77+
5378 /// Transact the system call and finalize.
5479 ///
5580 /// Internally calls combo of `transact_system_call` and `finalize` functions.
@@ -58,7 +83,22 @@ pub trait SystemCallEvm: ExecuteEvm {
5883 system_contract_address : Address ,
5984 data : Bytes ,
6085 ) -> Result < ResultAndState < Self :: ExecutionResult , Self :: State > , Self :: Error > {
61- let result = self . transact_system_call ( system_contract_address, data) ?;
86+ self . transact_system_call_with_caller_finalize (
87+ SYSTEM_ADDRESS ,
88+ system_contract_address,
89+ data,
90+ )
91+ }
92+
93+ /// Calls [`SystemCallEvm::transact_system_call_with_caller`] and `finalize` functions.
94+ fn transact_system_call_with_caller_finalize (
95+ & mut self ,
96+ caller : Address ,
97+ system_contract_address : Address ,
98+ data : Bytes ,
99+ ) -> Result < ResultAndState < Self :: ExecutionResult , Self :: State > , Self :: Error > {
100+ let result =
101+ self . transact_system_call_with_caller ( caller, system_contract_address, data) ?;
62102 let state = self . finalize ( ) ;
63103 Ok ( ResultAndState :: new ( result, state) )
64104 }
@@ -71,6 +111,16 @@ pub trait SystemCallCommitEvm: SystemCallEvm + ExecuteCommitEvm {
71111 & mut self ,
72112 system_contract_address : Address ,
73113 data : Bytes ,
114+ ) -> Result < Self :: ExecutionResult , Self :: Error > {
115+ self . transact_system_call_with_caller_commit ( SYSTEM_ADDRESS , system_contract_address, data)
116+ }
117+
118+ /// Calls [`SystemCallCommitEvm::transact_system_call_commit`] with [`SYSTEM_ADDRESS`] as a caller.
119+ fn transact_system_call_with_caller_commit (
120+ & mut self ,
121+ caller : Address ,
122+ system_contract_address : Address ,
123+ data : Bytes ,
74124 ) -> Result < Self :: ExecutionResult , Self :: Error > ;
75125}
76126
@@ -80,13 +130,18 @@ where
80130 INST : InstructionProvider < Context = CTX , InterpreterTypes = EthInterpreter > ,
81131 PRECOMPILES : PrecompileProvider < CTX , Output = InterpreterResult > ,
82132{
83- fn transact_system_call (
133+ fn transact_system_call_with_caller (
84134 & mut self ,
135+ caller : Address ,
85136 system_contract_address : Address ,
86137 data : Bytes ,
87138 ) -> Result < Self :: ExecutionResult , Self :: Error > {
88139 // set tx fields.
89- self . set_tx ( CTX :: Tx :: new_system_tx ( data, system_contract_address) ) ;
140+ self . set_tx ( CTX :: Tx :: new_system_tx_with_caller (
141+ caller,
142+ system_contract_address,
143+ data,
144+ ) ) ;
90145 // create handler
91146 let mut handler = MainnetHandler :: < _ , _ , EthFrame < _ , _ , _ > > :: default ( ) ;
92147 handler. run_system_call ( self )
@@ -100,12 +155,13 @@ where
100155 INST : InstructionProvider < Context = CTX , InterpreterTypes = EthInterpreter > ,
101156 PRECOMPILES : PrecompileProvider < CTX , Output = InterpreterResult > ,
102157{
103- fn transact_system_call_commit (
158+ fn transact_system_call_with_caller_commit (
104159 & mut self ,
160+ caller : Address ,
105161 system_contract_address : Address ,
106162 data : Bytes ,
107163 ) -> Result < Self :: ExecutionResult , Self :: Error > {
108- self . transact_system_call_finalize ( system_contract_address, data)
164+ self . transact_system_call_with_caller_finalize ( caller , system_contract_address, data)
109165 . map ( |output| {
110166 self . db_mut ( ) . commit ( output. state ) ;
111167 output. result
0 commit comments