Skip to content

Commit 1b254f7

Browse files
committed
feat(spec-specs): add EIP-7997 deterministic factory deployment
Install the factory runtime code on the fork activation block, detected by the parent header being a pre-amsterdam header, when the code is not already present. The nonce and code changes are recorded in the block access list at the pre-execution index. On chains where the factory already exists this is a no-op, and no other block ever touches the account.
1 parent 9e2bf60 commit 1b254f7

1 file changed

Lines changed: 40 additions & 0 deletions

File tree

  • src/ethereum/forks/amsterdam

src/ethereum/forks/amsterdam/fork.py

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@
8080
incorporate_tx_into_block,
8181
increment_nonce,
8282
set_account_balance,
83+
set_code,
8384
)
8485
from .transactions import (
8586
TX_MAX_GAS_LIMIT,
@@ -144,6 +145,17 @@
144145
HISTORY_STORAGE_ADDRESS = hex_to_address(
145146
"0x0000F90827F1C53a10cb7A02335B175320002935"
146147
)
148+
DETERMINISTIC_FACTORY_ADDRESS = hex_to_address(
149+
"0x4e59b44847b379578588920cA78FbF26c0B4956C"
150+
)
151+
DETERMINISTIC_FACTORY_CODE = Bytes(
152+
bytes.fromhex(
153+
"7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"
154+
"ffe03601600081602082378035828234f58015156039578182fd5b80825250"
155+
"50506014600cf3"
156+
)
157+
)
158+
DETERMINISTIC_FACTORY_CODE_HASH = keccak256(DETERMINISTIC_FACTORY_CODE)
147159
MAX_BLOCK_SIZE = 10_485_760
148160
SAFETY_MARGIN = 2_097_152
149161
MAX_RLP_BLOCK_SIZE = MAX_BLOCK_SIZE - SAFETY_MARGIN
@@ -842,6 +854,31 @@ def process_unchecked_system_transaction(
842854
return system_tx_output
843855

844856

857+
def deploy_deterministic_factory(block_env: vm.BlockEnvironment) -> None:
858+
"""
859+
Install the [EIP-7997] deterministic deployment factory on the fork
860+
activation block if its canonical runtime code is not already
861+
present, recording the changes in the block access list at the
862+
pre-execution index.
863+
864+
[EIP-7997]: https://eips.ethereum.org/EIPS/eip-7997
865+
"""
866+
tx_state = TransactionState(parent=block_env.state)
867+
account = get_account(tx_state, DETERMINISTIC_FACTORY_ADDRESS)
868+
if account.code_hash == DETERMINISTIC_FACTORY_CODE_HASH:
869+
return
870+
871+
set_code(
872+
tx_state,
873+
DETERMINISTIC_FACTORY_ADDRESS,
874+
DETERMINISTIC_FACTORY_CODE,
875+
)
876+
if account.nonce == Uint(0):
877+
increment_nonce(tx_state, DETERMINISTIC_FACTORY_ADDRESS)
878+
879+
incorporate_tx_into_block(tx_state, block_env.block_access_list_builder)
880+
881+
845882
def apply_body(
846883
block_env: vm.BlockEnvironment,
847884
transactions: Tuple[LegacyTransaction | Bytes, ...],
@@ -874,6 +911,9 @@ def apply_body(
874911
"""
875912
block_output = vm.BlockOutput()
876913

914+
if isinstance(block_env.parent_header, PreviousHeader):
915+
deploy_deterministic_factory(block_env)
916+
877917
process_unchecked_system_transaction(
878918
block_env=block_env,
879919
target_address=BEACON_ROOTS_ADDRESS,

0 commit comments

Comments
 (0)