Skip to content

Commit 2a19923

Browse files
committed
address some comments
1 parent 7e66e83 commit 2a19923

File tree

5 files changed

+93
-98
lines changed

5 files changed

+93
-98
lines changed

src/ethereum_test_forks/forks/forks.py

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -196,9 +196,10 @@ def fn(
196196
return_cost_deducted_prior_execution: bool = False,
197197
) -> int:
198198
assert access_list is None, f"Access list is not supported in {cls.name()}"
199-
assert authorization_list_or_count is None, (
200-
f"Authorizations are not supported in {cls.name()}"
201-
)
199+
assert (
200+
authorization_list_or_count is None
201+
), f"Authorizations are not supported in {cls.name()}"
202+
202203
intrinsic_cost: int = gas_costs.G_TRANSACTION
203204

204205
if contract_creation:
@@ -642,9 +643,12 @@ def valid_opcodes(
642643
cls,
643644
) -> List[Opcodes]:
644645
"""Return list of Opcodes that are valid to work on this fork."""
645-
return [Opcodes.REVERT, Opcodes.RETURNDATASIZE, Opcodes.STATICCALL] + super(
646-
Byzantium, cls
647-
).valid_opcodes()
646+
return [
647+
Opcodes.REVERT,
648+
Opcodes.RETURNDATASIZE,
649+
Opcodes.RETURNDATACOPY,
650+
Opcodes.STATICCALL,
651+
] + super(Byzantium, cls).valid_opcodes()
648652

649653

650654
class Constantinople(Byzantium):

tests/frontier/scenarios/common.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -166,8 +166,9 @@ def translate_result(
166166
return exec_env.gaslimit
167167
if res.result == ScenarioExpectOpcode.SELFBALANCE:
168168
return int(env.selfbalance)
169-
170-
return int(res.result)
169+
else:
170+
return res.result
171+
return 0
171172

172173

173174
def replace_special_calls_in_operation(

tests/frontier/scenarios/programs/invalid_opcodes.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,14 @@ def make_all_invalid_opcode_calls() -> Bytecode:
2525

2626
code = Bytecode(
2727
sum(
28-
[
29-
Op.MSTORE(64, opcode)
30-
+ Op.MSTORE(32, Op.CALL(100000, invalid_opcode_caller, 0, 64, 32, 0, 0))
31-
+ Op.MSTORE(0, Op.ADD(Op.MLOAD(0), Op.MLOAD(32)))
32-
for opcode_range in invalid_opcode_ranges
33-
for opcode in opcode_range
34-
],
35-
start=Bytecode(),
28+
Op.MSTORE(64, opcode)
29+
+ Op.MSTORE(
30+
32,
31+
Op.CALL(gas=100000, address=invalid_opcode_caller, args_offset=64, args_size=32),
32+
)
33+
+ Op.MSTORE(0, Op.ADD(Op.MLOAD(0), Op.MLOAD(32)))
34+
for opcode_range in invalid_opcode_ranges
35+
for opcode in opcode_range
3636
)
3737
# If any of invalid instructions works, mstore[0] will be > 1
3838
+ Op.MSTORE(0, Op.ADD(Op.MLOAD(0), 1))

tests/frontier/scenarios/scenarios/call_combinations.py

Lines changed: 70 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -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
)

tests/frontier/scenarios/test_scenarios.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ def scenarios(fork: Fork, pre: Alloc, operation: Bytecode, debug: ScenarioDebug)
135135
# program=None select all programs
136136
# scenario_name="" select all scenarios
137137
"debug",
138-
[ScenarioDebug(None, scenario_name="")],
138+
[ScenarioDebug(test_param=None, scenario_name="")],
139139
ids=["debug"],
140140
)
141141
@pytest.mark.parametrize(
@@ -245,7 +245,7 @@ def make_result(scenario: Scenario) -> int:
245245
gas_limit=500_000_000,
246246
gas_price=tx_gasprice,
247247
to=runner_contract,
248-
data=b"0x11223344",
248+
data=bytes.fromhex("11223344"),
249249
value=0,
250250
protected=False,
251251
)

0 commit comments

Comments
 (0)