Skip to content

Commit 3c0bf69

Browse files
committed
chore(specs): refactor code deployment functions
1 parent 7df3b8b commit 3c0bf69

72 files changed

Lines changed: 360 additions & 768 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

src/ethereum/forks/amsterdam/state_tracker.py

Lines changed: 9 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -278,28 +278,18 @@ def account_exists(tx_state: TransactionState, address: Address) -> bool:
278278
return get_account_optional(tx_state, address) is not None
279279

280280

281-
def account_has_code_or_nonce(
282-
tx_state: TransactionState, address: Address
283-
) -> bool:
281+
def account_deployable(tx_state: TransactionState, address: Address) -> bool:
284282
"""
285-
Check if an account has non-zero nonce or non-empty code.
286-
287-
Parameters
288-
----------
289-
tx_state :
290-
The transaction state.
291-
address :
292-
Address of the account that needs to be checked.
293-
294-
Returns
295-
-------
296-
has_code_or_nonce : ``bool``
297-
True if the account has non-zero nonce or non-empty code,
298-
False otherwise.
299-
283+
Check if an account's code can be written to.
300284
"""
301285
account = get_account(tx_state, address)
302-
return account.nonce != Uint(0) or account.code_hash != EMPTY_CODE_HASH
286+
if account.nonce != Uint(0) or account.code_hash != EMPTY_CODE_HASH:
287+
return False
288+
289+
if account_has_storage(tx_state, address):
290+
return False
291+
292+
return True
303293

304294

305295
def account_has_storage(tx_state: TransactionState, address: Address) -> bool:

src/ethereum/forks/amsterdam/vm/instructions/system.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,7 @@
1818
from ethereum.utils.numeric import ceil32
1919

2020
from ...state_tracker import (
21-
account_has_code_or_nonce,
22-
account_has_storage,
21+
account_deployable,
2322
get_account,
2423
get_code,
2524
increment_nonce,
@@ -108,9 +107,7 @@ def generic_create(
108107

109108
evm.accessed_addresses.add(contract_address)
110109

111-
if account_has_code_or_nonce(
112-
tx_state, contract_address
113-
) or account_has_storage(tx_state, contract_address):
110+
if not account_deployable(tx_state, contract_address):
114111
increment_nonce(tx_state, evm.message.current_target)
115112
push(evm.stack, U256(0))
116113
return

src/ethereum/forks/amsterdam/vm/interpreter.py

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,7 @@
3232

3333
from ..blocks import Log
3434
from ..state_tracker import (
35-
account_has_code_or_nonce,
36-
account_has_storage,
35+
account_deployable,
3736
copy_tx_state,
3837
destroy_storage,
3938
get_account,
@@ -108,10 +107,9 @@ def process_message_call(message: Message) -> MessageCallOutput:
108107
tx_state = message.tx_env.state
109108
refund_counter = U256(0)
110109
if message.target == Bytes0(b""):
111-
is_collision = account_has_code_or_nonce(
112-
tx_state, message.current_target
113-
) or account_has_storage(tx_state, message.current_target)
114-
if is_collision:
110+
if account_deployable(tx_state, message.current_target):
111+
evm = process_create_message(message)
112+
else:
115113
return MessageCallOutput(
116114
Uint(0),
117115
U256(0),
@@ -120,8 +118,6 @@ def process_message_call(message: Message) -> MessageCallOutput:
120118
AddressCollision(),
121119
Bytes(b""),
122120
)
123-
else:
124-
evm = process_create_message(message)
125121
else:
126122
if message.tx_env.authorizations != ():
127123
refund_counter += set_delegation(message)

src/ethereum/forks/arrow_glacier/state_tracker.py

Lines changed: 9 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -274,28 +274,18 @@ def account_exists(tx_state: TransactionState, address: Address) -> bool:
274274
return get_account_optional(tx_state, address) is not None
275275

276276

277-
def account_has_code_or_nonce(
278-
tx_state: TransactionState, address: Address
279-
) -> bool:
277+
def account_deployable(tx_state: TransactionState, address: Address) -> bool:
280278
"""
281-
Check if an account has non-zero nonce or non-empty code.
282-
283-
Parameters
284-
----------
285-
tx_state :
286-
The transaction state.
287-
address :
288-
Address of the account that needs to be checked.
289-
290-
Returns
291-
-------
292-
has_code_or_nonce : ``bool``
293-
True if the account has non-zero nonce or non-empty code,
294-
False otherwise.
295-
279+
Check if an account's code can be written to.
296280
"""
297281
account = get_account(tx_state, address)
298-
return account.nonce != Uint(0) or account.code_hash != EMPTY_CODE_HASH
282+
if account.nonce != Uint(0) or account.code_hash != EMPTY_CODE_HASH:
283+
return False
284+
285+
if account_has_storage(tx_state, address):
286+
return False
287+
288+
return True
299289

300290

301291
def account_has_storage(tx_state: TransactionState, address: Address) -> bool:

src/ethereum/forks/arrow_glacier/vm/instructions/system.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,8 @@
1818
from ethereum.utils.numeric import ceil32
1919

2020
from ...state_tracker import (
21+
account_deployable,
2122
account_exists_and_is_empty,
22-
account_has_code_or_nonce,
23-
account_has_storage,
2423
get_account,
2524
get_code,
2625
increment_nonce,
@@ -88,9 +87,7 @@ def generic_create(
8887

8988
evm.accessed_addresses.add(contract_address)
9089

91-
if account_has_code_or_nonce(
92-
evm.message.tx_env.state, contract_address
93-
) or account_has_storage(evm.message.tx_env.state, contract_address):
90+
if not account_deployable(evm.message.tx_env.state, contract_address):
9491
increment_nonce(evm.message.tx_env.state, evm.message.current_target)
9592
push(evm.stack, U256(0))
9693
return

src/ethereum/forks/arrow_glacier/vm/interpreter.py

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,8 @@
3232

3333
from ..blocks import Log
3434
from ..state_tracker import (
35+
account_deployable,
3536
account_exists_and_is_empty,
36-
account_has_code_or_nonce,
37-
account_has_storage,
3837
copy_tx_state,
3938
destroy_storage,
4039
increment_nonce,
@@ -106,10 +105,9 @@ def process_message_call(message: Message) -> MessageCallOutput:
106105
tx_state = message.tx_env.state
107106
refund_counter = U256(0)
108107
if message.target == Bytes0(b""):
109-
is_collision = account_has_code_or_nonce(
110-
tx_state, message.current_target
111-
) or account_has_storage(tx_state, message.current_target)
112-
if is_collision:
108+
if account_deployable(tx_state, message.current_target):
109+
evm = process_create_message(message)
110+
else:
113111
return MessageCallOutput(
114112
gas_left=Uint(0),
115113
refund_counter=U256(0),
@@ -118,8 +116,6 @@ def process_message_call(message: Message) -> MessageCallOutput:
118116
touched_accounts=set(),
119117
error=AddressCollision(),
120118
)
121-
else:
122-
evm = process_create_message(message)
123119
else:
124120
evm = process_message(message)
125121
if account_exists_and_is_empty(tx_state, Address(message.target)):

src/ethereum/forks/berlin/state_tracker.py

Lines changed: 9 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -274,28 +274,18 @@ def account_exists(tx_state: TransactionState, address: Address) -> bool:
274274
return get_account_optional(tx_state, address) is not None
275275

276276

277-
def account_has_code_or_nonce(
278-
tx_state: TransactionState, address: Address
279-
) -> bool:
277+
def account_deployable(tx_state: TransactionState, address: Address) -> bool:
280278
"""
281-
Check if an account has non-zero nonce or non-empty code.
282-
283-
Parameters
284-
----------
285-
tx_state :
286-
The transaction state.
287-
address :
288-
Address of the account that needs to be checked.
289-
290-
Returns
291-
-------
292-
has_code_or_nonce : ``bool``
293-
True if the account has non-zero nonce or non-empty code,
294-
False otherwise.
295-
279+
Check if an account's code can be written to.
296280
"""
297281
account = get_account(tx_state, address)
298-
return account.nonce != Uint(0) or account.code_hash != EMPTY_CODE_HASH
282+
if account.nonce != Uint(0) or account.code_hash != EMPTY_CODE_HASH:
283+
return False
284+
285+
if account_has_storage(tx_state, address):
286+
return False
287+
288+
return True
299289

300290

301291
def account_has_storage(tx_state: TransactionState, address: Address) -> bool:

src/ethereum/forks/berlin/vm/instructions/system.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,8 @@
1818
from ethereum.utils.numeric import ceil32
1919

2020
from ...state_tracker import (
21+
account_deployable,
2122
account_exists_and_is_empty,
22-
account_has_code_or_nonce,
23-
account_has_storage,
2423
get_account,
2524
get_code,
2625
increment_nonce,
@@ -88,9 +87,7 @@ def generic_create(
8887

8988
evm.accessed_addresses.add(contract_address)
9089

91-
if account_has_code_or_nonce(
92-
evm.message.tx_env.state, contract_address
93-
) or account_has_storage(evm.message.tx_env.state, contract_address):
90+
if not account_deployable(evm.message.tx_env.state, contract_address):
9491
increment_nonce(evm.message.tx_env.state, evm.message.current_target)
9592
push(evm.stack, U256(0))
9693
return

src/ethereum/forks/berlin/vm/interpreter.py

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,8 @@
3232

3333
from ..blocks import Log
3434
from ..state_tracker import (
35+
account_deployable,
3536
account_exists_and_is_empty,
36-
account_has_code_or_nonce,
37-
account_has_storage,
3837
copy_tx_state,
3938
destroy_storage,
4039
increment_nonce,
@@ -105,10 +104,9 @@ def process_message_call(message: Message) -> MessageCallOutput:
105104
tx_state = message.tx_env.state
106105
refund_counter = U256(0)
107106
if message.target == Bytes0(b""):
108-
is_collision = account_has_code_or_nonce(
109-
tx_state, message.current_target
110-
) or account_has_storage(tx_state, message.current_target)
111-
if is_collision:
107+
if account_deployable(tx_state, message.current_target):
108+
evm = process_create_message(message)
109+
else:
112110
return MessageCallOutput(
113111
gas_left=Uint(0),
114112
refund_counter=U256(0),
@@ -117,8 +115,6 @@ def process_message_call(message: Message) -> MessageCallOutput:
117115
touched_accounts=set(),
118116
error=AddressCollision(),
119117
)
120-
else:
121-
evm = process_create_message(message)
122118
else:
123119
evm = process_message(message)
124120
if account_exists_and_is_empty(tx_state, Address(message.target)):

src/ethereum/forks/bpo1/state_tracker.py

Lines changed: 9 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -262,28 +262,18 @@ def account_exists(tx_state: TransactionState, address: Address) -> bool:
262262
return get_account_optional(tx_state, address) is not None
263263

264264

265-
def account_has_code_or_nonce(
266-
tx_state: TransactionState, address: Address
267-
) -> bool:
265+
def account_deployable(tx_state: TransactionState, address: Address) -> bool:
268266
"""
269-
Check if an account has non-zero nonce or non-empty code.
270-
271-
Parameters
272-
----------
273-
tx_state :
274-
The transaction state.
275-
address :
276-
Address of the account that needs to be checked.
277-
278-
Returns
279-
-------
280-
has_code_or_nonce : ``bool``
281-
True if the account has non-zero nonce or non-empty code,
282-
False otherwise.
283-
267+
Check if an account's code can be written to.
284268
"""
285269
account = get_account(tx_state, address)
286-
return account.nonce != Uint(0) or account.code_hash != EMPTY_CODE_HASH
270+
if account.nonce != Uint(0) or account.code_hash != EMPTY_CODE_HASH:
271+
return False
272+
273+
if account_has_storage(tx_state, address):
274+
return False
275+
276+
return True
287277

288278

289279
def account_has_storage(tx_state: TransactionState, address: Address) -> bool:

0 commit comments

Comments
 (0)