From debc93d827e4033560d05853f97b2ccabef13330 Mon Sep 17 00:00:00 2001 From: Disco <131301107+0xDiscotech@users.noreply.github.com> Date: Mon, 9 Sep 2024 13:46:12 -0300 Subject: [PATCH] fix: deploy a proxy for the beacon on genesis (#45) --------- Co-authored-by: 0xng --- packages/contracts-bedrock/scripts/L2Genesis.s.sol | 6 ++++-- packages/contracts-bedrock/semver-lock.json | 2 +- .../src/L2/OptimismSuperchainERC20Beacon.sol | 1 + .../contracts-bedrock/src/libraries/Predeploys.sol | 2 +- packages/contracts-bedrock/test/L2Genesis.t.sol | 14 +++++++------- 5 files changed, 14 insertions(+), 11 deletions(-) diff --git a/packages/contracts-bedrock/scripts/L2Genesis.s.sol b/packages/contracts-bedrock/scripts/L2Genesis.s.sol index fc745aa793a7..d4aedde8aea2 100644 --- a/packages/contracts-bedrock/scripts/L2Genesis.s.sol +++ b/packages/contracts-bedrock/scripts/L2Genesis.s.sol @@ -521,12 +521,14 @@ contract L2Genesis is Deployer { vm.etch(superchainERC20Impl, vm.getDeployedCode("OptimismSuperchainERC20.sol:OptimismSuperchainERC20")); OptimismSuperchainERC20Beacon beacon = new OptimismSuperchainERC20Beacon(superchainERC20Impl); + address beaconImpl = Predeploys.predeployToCodeNamespace(Predeploys.OPTIMISM_SUPERCHAIN_ERC20_BEACON); + console.log( "Setting %s implementation at: %s", "OptimismSuperchainERC20Beacon", - Predeploys.OPTIMISM_SUPERCHAIN_ERC20_BEACON + beaconImpl ); - vm.etch(Predeploys.OPTIMISM_SUPERCHAIN_ERC20_BEACON, address(beacon).code); + vm.etch(beaconImpl, address(beacon).code); /// Reset so its not included state dump vm.etch(address(beacon), ""); diff --git a/packages/contracts-bedrock/semver-lock.json b/packages/contracts-bedrock/semver-lock.json index c7c0bd86bf3f..d21f188bb915 100644 --- a/packages/contracts-bedrock/semver-lock.json +++ b/packages/contracts-bedrock/semver-lock.json @@ -121,7 +121,7 @@ }, "src/L2/OptimismSuperchainERC20Beacon.sol": { "initCodeHash": "0x99ce8095b23c124850d866cbc144fee6cee05dbc6bb5d83acadfe00b90cf42c7", - "sourceCodeHash": "0x00eb41c15cf548dfb6425f317d85262c1edd5f1ad2386a6a76695781d158cf16" + "sourceCodeHash": "0xec163226a89c2aa6c2add4e9de0513af9cd6525ce911a27774db4bca91381abb" }, "src/L2/OptimismSuperchainERC20Factory.sol": { "initCodeHash": "0x98011045722178751e4a1112892f7d9a11bc1f5e42ac18205b6d30a1f1476d24", diff --git a/packages/contracts-bedrock/src/L2/OptimismSuperchainERC20Beacon.sol b/packages/contracts-bedrock/src/L2/OptimismSuperchainERC20Beacon.sol index 2c00410c29eb..0aaac53dbc53 100644 --- a/packages/contracts-bedrock/src/L2/OptimismSuperchainERC20Beacon.sol +++ b/packages/contracts-bedrock/src/L2/OptimismSuperchainERC20Beacon.sol @@ -4,6 +4,7 @@ pragma solidity 0.8.15; import { IBeacon } from "@openzeppelin/contracts/proxy/beacon/IBeacon.sol"; import { ISemver } from "src/universal/ISemver.sol"; +/// @custom:proxied /// @custom:predeployed 0x4200000000000000000000000000000000000027 /// @title OptimismSuperchainERC20Beacon /// @notice OptimismSuperchainERC20Beacon is the beacon proxy for the OptimismSuperchainERC20 implementation. diff --git a/packages/contracts-bedrock/src/libraries/Predeploys.sol b/packages/contracts-bedrock/src/libraries/Predeploys.sol index 5b7e5f410fa9..c8fca4376bde 100644 --- a/packages/contracts-bedrock/src/libraries/Predeploys.sol +++ b/packages/contracts-bedrock/src/libraries/Predeploys.sol @@ -140,7 +140,7 @@ library Predeploys { /// @notice Returns true if the predeploy is not proxied. function notProxied(address _addr) internal pure returns (bool) { - return _addr == GOVERNANCE_TOKEN || _addr == WETH || _addr == OPTIMISM_SUPERCHAIN_ERC20_BEACON; + return _addr == GOVERNANCE_TOKEN || _addr == WETH; } /// @notice Returns true if the address is a defined predeploy that is embedded into new OP-Stack chains. diff --git a/packages/contracts-bedrock/test/L2Genesis.t.sol b/packages/contracts-bedrock/test/L2Genesis.t.sol index a1a464a5082e..ee993fe1110c 100644 --- a/packages/contracts-bedrock/test/L2Genesis.t.sol +++ b/packages/contracts-bedrock/test/L2Genesis.t.sol @@ -147,18 +147,18 @@ contract L2GenesisTest is Test { genesis.setPredeployProxies(); genesis.writeGenesisAllocs(_path); - // 3 predeploys do not have proxies - assertEq(getCodeCount(_path, "Proxy.sol:Proxy"), Predeploys.PREDEPLOY_COUNT - 3); + // 2 predeploys do not have proxies + assertEq(getCodeCount(_path, "Proxy.sol:Proxy"), Predeploys.PREDEPLOY_COUNT - 2); - // 22 proxies have the implementation set if useInterop is true and 17 if useInterop is false - assertEq(getPredeployCountWithSlotSet(_path, Constants.PROXY_IMPLEMENTATION_ADDRESS), _useInterop ? 22 : 17); + // 23 proxies have the implementation set if useInterop is true and 17 if useInterop is false + assertEq(getPredeployCountWithSlotSet(_path, Constants.PROXY_IMPLEMENTATION_ADDRESS), _useInterop ? 23 : 17); - // All proxies except 3 have the proxy 1967 admin slot set to the proxy admin + // All proxies except 2 have the proxy 1967 admin slot set to the proxy admin assertEq( getPredeployCountWithSlotSetToValue( _path, Constants.PROXY_OWNER_ADDRESS, bytes32(uint256(uint160(Predeploys.PROXY_ADMIN))) ), - Predeploys.PREDEPLOY_COUNT - 3 + Predeploys.PREDEPLOY_COUNT - 2 ); // Also see Predeploys.t.test_predeploysSet_succeeds which uses L1Genesis for the CommonTest prestate. @@ -185,7 +185,7 @@ contract L2GenesisTest is Test { genesis.writeGenesisAllocs(_path); uint256 expected = 0; - expected += 2048 - 3; // predeploy proxies + expected += 2048 - 2; // predeploy proxies expected += 21; // predeploy implementations (excl. legacy erc20-style eth and legacy message sender) expected += 256; // precompiles expected += 13; // preinstalls