Skip to content

Commit d12c5d4

Browse files
committed
python lint
1 parent ad9dd18 commit d12c5d4

File tree

5 files changed

+67
-48
lines changed

5 files changed

+67
-48
lines changed

src/ethereum/osaka/fork.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
"""
1414

1515
from dataclasses import dataclass
16-
from typing import List, Optional, Tuple
16+
from typing import Any, List, Optional, Tuple
1717

1818
from ethereum_rlp import rlp
1919
from ethereum_types.bytes import Bytes
@@ -179,7 +179,9 @@ def get_last_256_block_hashes(chain: BlockChain) -> List[Hash32]:
179179
return recent_block_hashes
180180

181181

182-
def state_transition(chain: BlockChain, block: Block, oracle=None) -> None:
182+
def state_transition(
183+
chain: BlockChain, block: Block, oracle: Optional[Any] = None
184+
) -> None:
183185
"""
184186
Attempts to apply a block to an existing block chain.
185187

src/ethereum/osaka/vm/instructions/storage.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,9 @@ def sstore(evm: Evm) -> None:
123123
charge_gas(evm, gas_cost)
124124
if evm.message.is_static:
125125
raise WriteInStaticContext
126-
oracle.set_storage_value(evm.message.current_target, key, new_value)
126+
oracle.set_storage_value(
127+
evm.message.current_target, key, new_value.to_be_bytes32()
128+
)
127129

128130
# PROGRAM COUNTER
129131
evm.pc += Uint(1)

src/ethereum/osaka/vm/interpreter.py

Lines changed: 11 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -32,16 +32,7 @@
3232

3333
from ..blocks import Log
3434
from ..fork_types import Address
35-
from ..state import (
36-
begin_transaction,
37-
commit_transaction,
38-
destroy_storage,
39-
increment_nonce,
40-
mark_account_created,
41-
move_ether,
42-
rollback_transaction,
43-
set_code,
44-
)
35+
from ..state import begin_transaction, commit_transaction, rollback_transaction
4536
from ..vm import Message
4637
from ..vm.eoa_delegation import get_delegated_code_address, set_delegation
4738
from ..vm.gas import GAS_CODE_DEPOSIT, charge_gas
@@ -169,7 +160,7 @@ def process_create_message(message: Message) -> Evm:
169160
evm: :py:class:`~ethereum.osaka.vm.Evm`
170161
Items containing execution specific objects.
171162
"""
172-
state = message.block_env.state
163+
state = message.block_env.oracle.state
173164
transient_storage = message.tx_env.transient_storage
174165
# take snapshot of state before processing the message
175166
begin_transaction(state, transient_storage)
@@ -181,15 +172,15 @@ def process_create_message(message: Message) -> Evm:
181172
# `CREATE` or `CREATE2` call.
182173
# * The first `CREATE` happened before Spurious Dragon and left empty
183174
# code.
184-
destroy_storage(state, message.current_target)
175+
message.block_env.oracle.destroy_storage(message.current_target)
185176

186177
# In the previously mentioned edge case the preexisting storage is ignored
187178
# for gas refund purposes. In order to do this we must track created
188179
# accounts. This tracking is also needed to respect the constraints
189180
# added to SELFDESTRUCT by EIP-6780.
190-
mark_account_created(state, message.current_target)
181+
message.block_env.oracle.add_created_account(message.current_target)
191182

192-
increment_nonce(state, message.current_target)
183+
message.block_env.oracle.increment_nonce(message.current_target)
193184
evm = process_message(message)
194185
if not evm.error:
195186
contract_code = evm.output
@@ -207,7 +198,9 @@ def process_create_message(message: Message) -> Evm:
207198
evm.output = b""
208199
evm.error = error
209200
else:
210-
set_code(state, message.current_target, contract_code)
201+
message.block_env.oracle.set_code(
202+
message.current_target, contract_code
203+
)
211204
commit_transaction(state, transient_storage)
212205
else:
213206
rollback_transaction(state, transient_storage)
@@ -228,7 +221,7 @@ def process_message(message: Message) -> Evm:
228221
evm: :py:class:`~ethereum.osaka.vm.Evm`
229222
Items containing execution specific objects
230223
"""
231-
state = message.block_env.state
224+
state = message.block_env.oracle.state
232225
transient_storage = message.tx_env.transient_storage
233226
if message.depth > STACK_DEPTH_LIMIT:
234227
raise StackDepthLimitError("Stack depth limit reached")
@@ -237,8 +230,8 @@ def process_message(message: Message) -> Evm:
237230
begin_transaction(state, transient_storage)
238231

239232
if message.should_transfer_value and message.value != 0:
240-
move_ether(
241-
state, message.caller, message.current_target, message.value
233+
message.block_env.oracle.move_ether(
234+
message.caller, message.current_target, message.value
242235
)
243236

244237
evm = execute_code(message)

src/ethereum/state_oracle/interface.py

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
from typing import Any, Callable, Optional, Protocol
66

77
from ethereum_types.bytes import Bytes20, Bytes32
8+
from ethereum_types.numeric import U256
89

910
# Use generic types for compatibility across forks
1011
Account = Any
@@ -76,7 +77,7 @@ def get_storage_original(
7677
"""
7778

7879
def set_storage_value(
79-
self, address: Address, key: Bytes32, value: Any # noqa: U100
80+
self, address: Address, key: Bytes32, value: Bytes32 # noqa: U100
8081
) -> None:
8182
"""
8283
Set individual storage value.
@@ -90,8 +91,8 @@ def set_storage_value(
9091
Contract address
9192
key : Bytes32
9293
Storage slot key
93-
value : Any
94-
Storage value (U256 or Bytes32)
94+
value : Bytes32
95+
Storage value as 32-byte value
9596
"""
9697

9798
def account_has_code_or_nonce(
@@ -137,7 +138,7 @@ def set_code(self, address: Address, code: Any) -> None: # noqa: U100
137138
"""
138139

139140
def set_account_balance(
140-
self, address: Address, balance: Any # noqa: U100
141+
self, address: Address, balance: U256 # noqa: U100
141142
) -> None: # noqa: U100
142143
"""
143144
Set account balance.
@@ -146,7 +147,7 @@ def set_account_balance(
146147
"""
147148

148149
def move_ether(
149-
self, sender: Bytes20, recipient: Bytes20, amount: Any # noqa: U100
150+
self, sender: Bytes20, recipient: Bytes20, amount: U256 # noqa: U100
150151
) -> None:
151152
"""
152153
Transfer ether between accounts.
@@ -186,6 +187,11 @@ def destroy_account(self, address: Address) -> None: # noqa: U100
186187
Used in SELFDESTRUCT and account cleanup.
187188
"""
188189

190+
def destroy_storage(self, address: Address) -> None: # noqa: U100
191+
"""
192+
Completely remove the storage at address.
193+
"""
194+
189195
def modify_state(
190196
self,
191197
address: Address, # noqa: U100
@@ -201,3 +207,7 @@ def modify_state(
201207
modifier_function : Callable[[Account], None]
202208
Function that takes an account and modifies it in place
203209
"""
210+
211+
@property
212+
def state(self) -> Any: # noqa: U100
213+
"""Access to underlying state for compatibility."""

src/ethereum/state_oracle/memory_oracle.py

Lines changed: 34 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -6,24 +6,26 @@
66
This is mainly done as a first pass to make the diff small.
77
"""
88

9-
from typing import Any, Optional
9+
from typing import Any, Callable, Optional
1010

1111
from ethereum_types.bytes import Bytes20, Bytes32
12+
from ethereum_types.numeric import U256
1213

1314
# TODO: This file is current Osaka specific -- we could move state.py
1415
# into here to mitigate this.
1516

1617
# Use generic types for compatibility across forks
1718
Account = Any
1819
Address = Bytes20
20+
State = Any
1921

2022

2123
class MemoryMerkleOracle:
2224
"""
2325
Merkle oracle implementation that wraps existing execution-specs state.
2426
"""
2527

26-
def __init__(self, state):
28+
def __init__(self, state: State) -> None:
2729
"""
2830
Initialize oracle with existing state.
2931
@@ -67,101 +69,111 @@ def state_root(self) -> Bytes32:
6769

6870
return state_root(self._state)
6971

70-
def get_storage_original(self, address, key):
72+
def get_storage_original(self, address: Address, key: Bytes32) -> Bytes32:
7173
"""Get original storage value (before transaction started)."""
7274
from ethereum.osaka.state import get_storage_original
7375

7476
storage_value = get_storage_original(self._state, address, key)
7577
return storage_value.to_be_bytes32()
7678

77-
def set_storage_value(self, address, key, value):
79+
def set_storage_value(
80+
self, address: Address, key: Bytes32, value: Bytes32
81+
) -> None:
7882
"""Set a single storage value."""
7983
from ethereum_types.numeric import U256
8084

8185
from ethereum.osaka.state import set_storage
8286

83-
if isinstance(value, bytes):
84-
storage_value = U256.from_be_bytes(value)
85-
else:
86-
storage_value = value
87+
# Convert Bytes32 to U256 for storage
88+
storage_value = U256.from_be_bytes(value)
8789
set_storage(self._state, address, key, storage_value)
8890

89-
def account_has_code_or_nonce(self, address):
91+
def account_has_code_or_nonce(self, address: Address) -> bool:
9092
"""Check if account has non-zero code or nonce."""
9193
from ethereum.osaka.state import account_has_code_or_nonce
9294

9395
return account_has_code_or_nonce(self._state, address)
9496

95-
def account_has_storage(self, address):
97+
def account_has_storage(self, address: Address) -> bool:
9698
"""Check if account has any storage slots."""
9799
from ethereum.osaka.state import account_has_storage
98100

99101
return account_has_storage(self._state, address)
100102

101-
def is_account_alive(self, address):
103+
def is_account_alive(self, address: Address) -> bool:
102104
"""Check if account is alive (exists and not marked for deletion)."""
103105
from ethereum.osaka.state import is_account_alive
104106

105107
return is_account_alive(self._state, address)
106108

107-
def account_exists(self, address):
109+
def account_exists(self, address: Address) -> bool:
108110
"""Check if account exists in the state."""
109111
from ethereum.osaka.state import account_exists
110112

111113
return account_exists(self._state, address)
112114

113-
def increment_nonce(self, address):
115+
def increment_nonce(self, address: Address) -> None:
114116
"""Increment account nonce."""
115117
from ethereum.osaka.state import increment_nonce
116118

117119
increment_nonce(self._state, address)
118120

119-
def set_code(self, address, code):
121+
def set_code(self, address: Address, code: Any) -> None:
120122
"""Set account code."""
121123
from ethereum.osaka.state import set_code
122124

123125
set_code(self._state, address, code)
124126

125-
def set_account_balance(self, address, balance):
127+
def set_account_balance(self, address: Address, balance: U256) -> None:
126128
"""Set account balance."""
127129
from ethereum.osaka.state import set_account_balance
128130

129131
set_account_balance(self._state, address, balance)
130132

131-
def move_ether(self, sender, recipient, amount):
133+
def move_ether(
134+
self, sender: Address, recipient: Address, amount: U256
135+
) -> None:
132136
"""Transfer ether between accounts."""
133137
from ethereum.osaka.state import move_ether
134138

135139
move_ether(self._state, sender, recipient, amount)
136140

137-
def add_created_account(self, address):
141+
def add_created_account(self, address: Address) -> None:
138142
"""Mark account as created in current transaction."""
139143
# Add to the created_accounts set in state
140144
self._state.created_accounts.add(address)
141145

142-
def is_created_account(self, address):
146+
def is_created_account(self, address: Address) -> bool:
143147
"""Check if account was created in current transaction."""
144148
return address in self._state.created_accounts
145149

146-
def account_exists_and_is_empty(self, address):
150+
def account_exists_and_is_empty(self, address: Address) -> bool:
147151
"""Check if account exists and is empty."""
148152
from ethereum.osaka.state import account_exists_and_is_empty
149153

150154
return account_exists_and_is_empty(self._state, address)
151155

152-
def destroy_account(self, address):
156+
def destroy_account(self, address: Address) -> None:
153157
"""Mark account for destruction."""
154158
from ethereum.osaka.state import destroy_account
155159

156160
destroy_account(self._state, address)
157161

158-
def modify_state(self, address, modifier_function):
162+
def destroy_storage(self, address: Address) -> None:
163+
"""Completely remove the storage at address."""
164+
from ethereum.osaka.state import destroy_storage
165+
166+
destroy_storage(self._state, address)
167+
168+
def modify_state(
169+
self, address: Address, modifier_function: Callable[[Account], None]
170+
) -> None:
159171
"""Modify an account using a modifier function."""
160172
from ethereum.osaka.state import modify_state
161173

162174
modify_state(self._state, address, modifier_function)
163175

164176
@property
165-
def state(self):
177+
def state(self) -> State:
166178
"""Access to underlying state for compatibility."""
167179
return self._state

0 commit comments

Comments
 (0)