|
80 | 80 | incorporate_tx_into_block, |
81 | 81 | increment_nonce, |
82 | 82 | set_account_balance, |
| 83 | + set_code, |
83 | 84 | ) |
84 | 85 | from .transactions import ( |
85 | 86 | TX_MAX_GAS_LIMIT, |
|
144 | 145 | HISTORY_STORAGE_ADDRESS = hex_to_address( |
145 | 146 | "0x0000F90827F1C53a10cb7A02335B175320002935" |
146 | 147 | ) |
| 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) |
147 | 159 | MAX_BLOCK_SIZE = 10_485_760 |
148 | 160 | SAFETY_MARGIN = 2_097_152 |
149 | 161 | MAX_RLP_BLOCK_SIZE = MAX_BLOCK_SIZE - SAFETY_MARGIN |
@@ -842,6 +854,31 @@ def process_unchecked_system_transaction( |
842 | 854 | return system_tx_output |
843 | 855 |
|
844 | 856 |
|
| 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 | + |
845 | 882 | def apply_body( |
846 | 883 | block_env: vm.BlockEnvironment, |
847 | 884 | transactions: Tuple[LegacyTransaction | Bytes, ...], |
@@ -874,6 +911,9 @@ def apply_body( |
874 | 911 | """ |
875 | 912 | block_output = vm.BlockOutput() |
876 | 913 |
|
| 914 | + if isinstance(block_env.parent_header, PreviousHeader): |
| 915 | + deploy_deterministic_factory(block_env) |
| 916 | + |
877 | 917 | process_unchecked_system_transaction( |
878 | 918 | block_env=block_env, |
879 | 919 | target_address=BEACON_ROOTS_ADDRESS, |
|
0 commit comments