@@ -31,10 +31,10 @@ class AddressBalance:
3131 keep_gas = 100000
3232
3333 """Possible calls list to make as a first call"""
34- first_calls : List [Opcode ] = []
34+ first_call_opcodes : List [Opcode ] = []
3535
3636 """Possible calls list to make as a second call"""
37- second_calls : List [Opcode ] = []
37+ second_call_opcodes : List [Opcode ] = []
3838
3939 """Balance map that we put in different accounts"""
4040 balance : AddressBalance
@@ -44,17 +44,13 @@ class AddressBalance:
4444
4545 def __init__ (self , scenario_input : ScenarioGeneratorInput ):
4646 """Define possible call combinations given the fork."""
47- self .first_calls = [
47+ self .first_call_opcodes = [
4848 callcode
4949 for callcode , evm_type in scenario_input .fork .call_opcodes ()
5050 if evm_type == EVMCodeType .LEGACY
5151 ]
52- self .second_calls = [
53- callcode
54- for callcode , evm_type in scenario_input .fork .call_opcodes ()
55- if evm_type == EVMCodeType .LEGACY
56- ]
57- self .second_calls .append (Op .NOOP )
52+ self .second_call_opcodes = self .first_call_opcodes [:]
53+ self .second_call_opcodes .append (Op .NOOP )
5854 self .scenario_input = scenario_input
5955 self .balance = self .AddressBalance ()
6056
@@ -73,15 +69,17 @@ def generate(self) -> List[Scenario]:
7369 """
7470 scenarios_list : List [Scenario ] = []
7571
76- for first_call in self .first_calls :
77- for second_call in self .second_calls :
72+ for first_call in self .first_call_opcodes :
73+ for second_call in self .second_call_opcodes :
7874 if second_call == Op .NOOP :
79- self ._generate_one_call_scenarios (first_call , scenarios_list )
75+ scenarios_list . append ( self ._generate_one_call_scenario (first_call ) )
8076 else :
81- self ._generate_two_call_scenarios (first_call , second_call , scenarios_list )
77+ scenarios_list .append (
78+ self ._generate_two_call_scenario (first_call , second_call )
79+ )
8280 return scenarios_list
8381
84- def _generate_one_call_scenarios (self , first_call : Opcode , scenarios_list : List [ Scenario ]) :
82+ def _generate_one_call_scenario (self , first_call : Opcode ) -> Scenario :
8583 """
8684 Generate scenario for only one call
8785 root_contract -(CALL)-> scenario_contract -(first_call)-> operation_contract.
@@ -117,47 +115,43 @@ def _generate_one_call_scenarios(self, first_call: Opcode, scenarios_list: List[
117115 balance = balance .root_contract_balance ,
118116 )
119117
120- scenarios_list .append (
121- Scenario (
122- name = f"scenario_{ first_call } " ,
123- code = root_contract ,
124- env = ScenarioEnvironment (
125- # Define address on which behalf program is executed
126- code_address = (
127- scenario_contract
128- if first_call == Op .CALLCODE or first_call == Op .DELEGATECALL
129- else operation_contract
130- ),
131- # Define code_caller for Op.CALLER
132- code_caller = (
133- root_contract if first_call == Op .DELEGATECALL else scenario_contract
134- ),
135- # Define balance for Op.BALANCE
136- selfbalance = (
137- balance .scenario_contract_balance
138- if first_call in [Op .DELEGATECALL , Op .CALLCODE ]
139- else (
140- balance .program_selfbalance
141- if first_call == Op .STATICCALL
142- else balance .first_call_value + balance .program_selfbalance
143- )
144- ),
145- ext_balance = scenario_input .external_balance ,
146- call_value = (
147- 0
148- if first_call in [Op .STATICCALL , Op .DELEGATECALL ]
149- else balance .first_call_value
150- ),
151- call_dataload_0 = int (scenario_input .external_address .hex (), 16 ),
152- call_datasize = 40 ,
153- has_static = True if first_call == Op .STATICCALL else False ,
118+ return Scenario (
119+ name = f"scenario_{ first_call } " ,
120+ code = root_contract ,
121+ env = ScenarioEnvironment (
122+ # Define address on which behalf program is executed
123+ code_address = (
124+ scenario_contract
125+ if first_call == Op .CALLCODE or first_call == Op .DELEGATECALL
126+ else operation_contract
154127 ),
155- )
128+ # Define code_caller for Op.CALLER
129+ code_caller = (
130+ root_contract if first_call == Op .DELEGATECALL else scenario_contract
131+ ),
132+ # Define balance for Op.BALANCE
133+ selfbalance = (
134+ balance .scenario_contract_balance
135+ if first_call in [Op .DELEGATECALL , Op .CALLCODE ]
136+ else (
137+ balance .program_selfbalance
138+ if first_call == Op .STATICCALL
139+ else balance .first_call_value + balance .program_selfbalance
140+ )
141+ ),
142+ ext_balance = scenario_input .external_balance ,
143+ call_value = (
144+ 0
145+ if first_call in [Op .STATICCALL , Op .DELEGATECALL ]
146+ else balance .first_call_value
147+ ),
148+ call_dataload_0 = int (scenario_input .external_address .hex (), 16 ),
149+ call_datasize = 40 ,
150+ has_static = True if first_call == Op .STATICCALL else False ,
151+ ),
156152 )
157153
158- def _generate_two_call_scenarios (
159- self , first_call : Opcode , second_call : Opcode , scenarios_list : List [Scenario ]
160- ):
154+ def _generate_two_call_scenario (self , first_call : Opcode , second_call : Opcode ) -> Scenario :
161155 """
162156 Generate scenario for two types of calls combination
163157 root_contract -(CALL)-> scenario_contract -(first_call)-> sub_contract
@@ -269,33 +263,29 @@ def _compute_callvalue() -> int:
269263 + Op .RETURN (0 , 32 ),
270264 )
271265
272- scenarios_list .append (
273- Scenario (
274- name = f"scenario_{ first_call } _{ second_call } " ,
275- code = root_contract ,
276- env = ScenarioEnvironment (
277- # Define address on which behalf program is executed
278- code_address = (
279- operation_contract
280- if second_call not in [Op .CALLCODE , Op .DELEGATECALL ]
281- else (
282- sub_contract
283- if first_call not in [Op .CALLCODE , Op .DELEGATECALL ]
284- else scenario_contract
285- )
286- ),
287- # Define code_caller for Op.CALLER
288- code_caller = _compute_code_caller (),
289- selfbalance = _compute_selfbalance (),
290- ext_balance = scenario_input .external_balance ,
291- call_value = _compute_callvalue (),
292- call_dataload_0 = int (scenario_input .external_address .hex (), 16 ),
293- call_datasize = 40 ,
294- has_static = (
295- True
296- if first_call == Op .STATICCALL or second_call == Op .STATICCALL
297- else False
298- ),
266+ return Scenario (
267+ name = f"scenario_{ first_call } _{ second_call } " ,
268+ code = root_contract ,
269+ env = ScenarioEnvironment (
270+ # Define address on which behalf program is executed
271+ code_address = (
272+ operation_contract
273+ if second_call not in [Op .CALLCODE , Op .DELEGATECALL ]
274+ else (
275+ sub_contract
276+ if first_call not in [Op .CALLCODE , Op .DELEGATECALL ]
277+ else scenario_contract
278+ )
299279 ),
300- )
280+ # Define code_caller for Op.CALLER
281+ code_caller = _compute_code_caller (),
282+ selfbalance = _compute_selfbalance (),
283+ ext_balance = scenario_input .external_balance ,
284+ call_value = _compute_callvalue (),
285+ call_dataload_0 = int (scenario_input .external_address .hex (), 16 ),
286+ call_datasize = 40 ,
287+ has_static = (
288+ True if first_call == Op .STATICCALL or second_call == Op .STATICCALL else False
289+ ),
290+ ),
301291 )
0 commit comments