Skip to content

Commit

Permalink
fix: deploy a proxy for the beacon on genesis (#45)
Browse files Browse the repository at this point in the history
---------

Co-authored-by: 0xng <[email protected]>
  • Loading branch information
0xDiscotech and 0xng committed Sep 12, 2024
1 parent 00451bc commit e6effed
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 11 deletions.
6 changes: 4 additions & 2 deletions packages/contracts-bedrock/scripts/L2Genesis.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -528,12 +528,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), "");
Expand Down
2 changes: 1 addition & 1 deletion packages/contracts-bedrock/semver-lock.json
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@
},
"src/L2/OptimismSuperchainERC20Beacon.sol": {
"initCodeHash": "0x99ce8095b23c124850d866cbc144fee6cee05dbc6bb5d83acadfe00b90cf42c7",
"sourceCodeHash": "0x00eb41c15cf548dfb6425f317d85262c1edd5f1ad2386a6a76695781d158cf16"
"sourceCodeHash": "0xec163226a89c2aa6c2add4e9de0513af9cd6525ce911a27774db4bca91381abb"
},
"src/L2/OptimismSuperchainERC20Factory.sol": {
"initCodeHash": "0x98011045722178751e4a1112892f7d9a11bc1f5e42ac18205b6d30a1f1476d24",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion packages/contracts-bedrock/src/libraries/Predeploys.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
14 changes: 7 additions & 7 deletions packages/contracts-bedrock/test/L2Genesis.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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
Expand Down

0 comments on commit e6effed

Please sign in to comment.