Skip to content

Commit c20c334

Browse files
ImTeispacesailor24
authored andcommitted
Use engine API that matches hardfork version (#9253)
* Use engine API that matches HF * Simplify engine client code by using EngineAPIVersion * Return full method string from engine api version methods * FCUVersion takes payload attributes * Use a proper method * Handle switch default case explicitly * Return fcuV3 if attrs is nil * Add test cases for engine api version methods
1 parent 1af01ea commit c20c334

File tree

1 file changed

+17
-16
lines changed

1 file changed

+17
-16
lines changed

packages/contracts-bedrock/scripts/L2Genesis.s.sol

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -23,23 +23,24 @@ interface IInitializable {
2323
}
2424

2525
/// @dev The general flow of adding a predeploy is:
26-
/// 1. _setProxies uses vm.etch to set the Proxy.sol deployed bytecode for proxy address `0x420...000` to `0x420...000 + PROXY_COUNT - 1`.
26+
/// 1. _setPredeployProxies uses vm.etch to set the Proxy.sol deployed bytecode for proxy address `0x420...000` to `0x420...000 + PROXY_COUNT - 1`.
2727
/// Additionally, the PROXY_ADMIN_ADDRESS and PROXY_IMPLEMENTATION_ADDRESS storage slots are set for the proxy
2828
/// address.
29-
/// 2. vm.etch sets the deployed bytecode for each predeploy at the implementation address (i.e. `0xc0d3` namespace).
30-
/// 3. The `initialize` method is called at the implementation address with zero/dummy vaules if it exists.
31-
/// 4. The `initialize` method is called at the proxy address with actual vaules if it exists.
29+
/// 2. `vm.etch` sets the deployed bytecode for each predeploy at the implementation address (i.e. `0xc0d3` namespace).
30+
/// 3. The `initialize` method is called at the implementation address with zero/dummy vaules if the method exists.
31+
/// 4. The `initialize` method is called at the proxy address with actual vaules if the method exists.
3232
/// 5. A `require` check to verify the expected implementation address is set for the proxy.
3333
/// @notice The following safety invariants are used when setting state:
3434
/// 1. `vm.getDeployedBytecode` can only be used with `vm.etch` when there are no side
3535
/// effects in the constructor and no immutables in the bytecode.
3636
/// 2. A contract must be deployed using the `new` syntax if there are immutables in the code.
3737
/// Any other side effects from the init code besides setting the immutables must be cleaned up afterwards.
38-
/// 3. A contract is deployed using the `new` syntax because it's not proxied, but still needs to be set
39-
/// at a specific address. Because just deploying a new instance doesn't give us the contract at our desired
40-
/// address,
41-
/// we must use `vm.etch` to set the deployed bytecode, and `vm.store` to set any storage slots. Lastly, we reset
42-
/// the account the contract was initially deployed by so it's not included in the `vm.dumpState`.
38+
/// 3. A contract is deployed using the `new` syntax, however it's not proxied and is still expected to exist at a
39+
/// specific implementation address (i.e. `0xc0d3` namespace). In this case we deploy an instance of the contract
40+
/// using `new` syntax, use `contract.code` to retrieve it's deployed bytecode, `vm.etch` the bytecode at the
41+
/// expected implementation address, and `vm.store` to set any storage slots that are
42+
/// expected to be set after a new deployment. Lastly, we reset the account code and storage slots the contract
43+
/// was initially deployed to so it's not included in the `vm.dumpState`.
4344
contract L2Genesis is Script, Artifacts {
4445
uint256 constant PROXY_COUNT = 2048;
4546
uint256 constant PRECOMPILE_COUNT = 256;
@@ -77,9 +78,9 @@ contract L2Genesis is Script, Artifacts {
7778
/// to generate a L2 genesis alloc.
7879
/// @notice The alloc object is sorted numerically by address.
7980
function run() public {
80-
_setPrecompiles();
81-
_setProxies();
82-
_setImplementations();
81+
_dealEthToPrecompiles();
82+
_setPredeployProxies();
83+
_setPredeployImplementations();
8384

8485
/// Reset so its not included state dump
8586
vm.etch(address(cfg), "");
@@ -90,7 +91,7 @@ contract L2Genesis is Script, Artifacts {
9091

9192
/// @notice Give all of the precompiles 1 wei so that they are
9293
/// not considered empty accounts.
93-
function _setPrecompiles() internal {
94+
function _dealEthToPrecompiles() internal {
9495
for (uint256 i; i < PRECOMPILE_COUNT; i++) {
9596
vm.deal(address(uint160(i)), 1);
9697
}
@@ -100,7 +101,7 @@ contract L2Genesis is Script, Artifacts {
100101
/// The Proxy bytecode should be set. All proxied predeploys should have
101102
/// the 1967 admin slot set to the ProxyAdmin predeploy. All defined predeploys
102103
/// should have their implementations set.
103-
function _setProxies() internal {
104+
function _setPredeployProxies() internal {
104105
bytes memory code = vm.getDeployedCode("Proxy.sol:Proxy");
105106
uint160 prefix = uint160(0x420) << 148;
106107

@@ -129,7 +130,7 @@ contract L2Genesis is Script, Artifacts {
129130
/// @notice LEGACY_ERC20_ETH is not being predeployed since it's been deprecated.
130131
/// @dev Sets all the implementations for the predeploy proxies. For contracts without proxies,
131132
/// sets the deployed bytecode at their expected predeploy address.
132-
function _setImplementations() internal {
133+
function _setPredeployImplementations() internal {
133134
_setLegacyMessagePasser();
134135
_setDeployerWhitelist();
135136
_setWETH9();
@@ -350,7 +351,7 @@ contract L2Genesis is Script, Artifacts {
350351
/// @notice There isn't a good way to know if the resulting revering is due to abi mismatch
351352
/// or because it's already been initialized
352353
function _verifyCantReinitialize(address _contract, address _arg) internal {
353-
vm.expectRevert();
354+
vm.expectRevert("Initializable: contract is already initialized");
354355
IInitializable(_contract).initialize(_arg);
355356
}
356357

0 commit comments

Comments
 (0)