From 40e206965e8d345ad2d38e4ddf69d3e9f4b493eb Mon Sep 17 00:00:00 2001 From: AgusDuha <81362284+agusduha@users.noreply.github.com> Date: Mon, 30 Sep 2024 14:28:46 -0300 Subject: [PATCH] fix: remove immutables from superchain erc20 beacon (#67) * fix: remove immutables from superchain erc20 beacon * test: add superchain erc20 beacon tests --- .../contracts-bedrock/scripts/L2Genesis.s.sol | 13 +++------- packages/contracts-bedrock/semver-lock.json | 4 +-- .../abi/OptimismSuperchainERC20Beacon.json | 13 +--------- .../src/L2/OptimismSuperchainERC20Beacon.sol | 18 +++++-------- .../L2/OptimismSuperchainERC20Beacon.t.sol | 25 +++++++++++++++++++ .../contracts-bedrock/test/Predeploys.t.sol | 2 +- 6 files changed, 38 insertions(+), 37 deletions(-) create mode 100644 packages/contracts-bedrock/test/L2/OptimismSuperchainERC20Beacon.t.sol diff --git a/packages/contracts-bedrock/scripts/L2Genesis.s.sol b/packages/contracts-bedrock/scripts/L2Genesis.s.sol index ceae376ee5c2..1d1f0c3d6b64 100644 --- a/packages/contracts-bedrock/scripts/L2Genesis.s.sol +++ b/packages/contracts-bedrock/scripts/L2Genesis.s.sol @@ -538,21 +538,14 @@ contract L2Genesis is Deployer { _setImplementationCode(Predeploys.OPTIMISM_SUPERCHAIN_ERC20_FACTORY); } - /// @notice This predeploy is following the safety invariant #2. + /// @notice This predeploy is following the safety invariant #1. + /// This contract has no initializer. function setOptimismSuperchainERC20Beacon() internal { address superchainERC20Impl = Predeploys.OPTIMISM_SUPERCHAIN_ERC20; console.log("Setting %s implementation at: %s", "OptimismSuperchainERC20", superchainERC20Impl); 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", beaconImpl); - vm.etch(beaconImpl, address(beacon).code); - - /// Reset so its not included state dump - vm.etch(address(beacon), ""); - vm.resetNonce(address(beacon)); + _setImplementationCode(Predeploys.OPTIMISM_SUPERCHAIN_ERC20_BEACON); } /// @notice Sets all the preinstalls. diff --git a/packages/contracts-bedrock/semver-lock.json b/packages/contracts-bedrock/semver-lock.json index 91c7ad09789d..a82cb0471094 100644 --- a/packages/contracts-bedrock/semver-lock.json +++ b/packages/contracts-bedrock/semver-lock.json @@ -120,8 +120,8 @@ "sourceCodeHash": "0xe853817da47d32b4ec5bb5392405278c82a1e9620aef377491dcb371fbbe682f" }, "src/L2/OptimismSuperchainERC20Beacon.sol": { - "initCodeHash": "0x99ce8095b23c124850d866cbc144fee6cee05dbc6bb5d83acadfe00b90cf42c7", - "sourceCodeHash": "0x5e58b7c867fafa49fe39d68d83875425e9cf94f05f2835bdcdaa08fc8bc6b68e" + "initCodeHash": "0x23dba3ceb9e58646695c306996c9e15251ac79acc6339c1a93d10a4c79da6dab", + "sourceCodeHash": "0xf4379e49665823c877f5732f35068435ce06e2394fce6910a5e113d16cdc9f95" }, "src/L2/OptimismSuperchainERC20Factory.sol": { "initCodeHash": "0x524bc58927ca60ba2fbc4b036ad00c5055758d5c5b2ebb3d75cb9b996175f2cb", diff --git a/packages/contracts-bedrock/snapshots/abi/OptimismSuperchainERC20Beacon.json b/packages/contracts-bedrock/snapshots/abi/OptimismSuperchainERC20Beacon.json index 0bdfc64ed2fe..a06b5b5d140e 100644 --- a/packages/contracts-bedrock/snapshots/abi/OptimismSuperchainERC20Beacon.json +++ b/packages/contracts-bedrock/snapshots/abi/OptimismSuperchainERC20Beacon.json @@ -1,15 +1,4 @@ [ - { - "inputs": [ - { - "internalType": "address", - "name": "_implementation", - "type": "address" - } - ], - "stateMutability": "nonpayable", - "type": "constructor" - }, { "inputs": [], "name": "implementation", @@ -20,7 +9,7 @@ "type": "address" } ], - "stateMutability": "view", + "stateMutability": "pure", "type": "function" }, { diff --git a/packages/contracts-bedrock/src/L2/OptimismSuperchainERC20Beacon.sol b/packages/contracts-bedrock/src/L2/OptimismSuperchainERC20Beacon.sol index d1160819a2ec..e2b3dc437b0f 100644 --- a/packages/contracts-bedrock/src/L2/OptimismSuperchainERC20Beacon.sol +++ b/packages/contracts-bedrock/src/L2/OptimismSuperchainERC20Beacon.sol @@ -3,25 +3,19 @@ pragma solidity 0.8.15; import { IBeacon } from "@openzeppelin/contracts/proxy/beacon/IBeacon.sol"; import { ISemver } from "src/universal/interfaces/ISemver.sol"; +import { Predeploys } from "src/libraries/Predeploys.sol"; -/// @custom:proxied +/// @custom:proxied true /// @custom:predeployed 0x4200000000000000000000000000000000000027 /// @title OptimismSuperchainERC20Beacon /// @notice OptimismSuperchainERC20Beacon is the beacon proxy for the OptimismSuperchainERC20 implementation. contract OptimismSuperchainERC20Beacon is IBeacon, ISemver { - /// @notice Address of the OptimismSuperchainERC20 implementation. - address internal immutable IMPLEMENTATION; - /// @notice Semantic version. - /// @custom:semver 1.0.0-beta.1 - string public constant version = "1.0.0-beta.1"; - - constructor(address _implementation) { - IMPLEMENTATION = _implementation; - } + /// @custom:semver 1.0.0-beta.2 + string public constant version = "1.0.0-beta.2"; /// @inheritdoc IBeacon - function implementation() external view override returns (address) { - return IMPLEMENTATION; + function implementation() external pure override returns (address) { + return Predeploys.OPTIMISM_SUPERCHAIN_ERC20; } } diff --git a/packages/contracts-bedrock/test/L2/OptimismSuperchainERC20Beacon.t.sol b/packages/contracts-bedrock/test/L2/OptimismSuperchainERC20Beacon.t.sol new file mode 100644 index 000000000000..68217127e0cb --- /dev/null +++ b/packages/contracts-bedrock/test/L2/OptimismSuperchainERC20Beacon.t.sol @@ -0,0 +1,25 @@ +// SPDX-License-Identifier: MIT +pragma solidity 0.8.15; + +// Testing utilities +import { Bridge_Initializer } from "test/setup/Bridge_Initializer.sol"; + +// Libraries +import { Predeploys } from "src/libraries/Predeploys.sol"; +import { IBeacon } from "@openzeppelin/contracts/proxy/beacon/IBeacon.sol"; + +/// @title OptimismSuperchainERC20BeaconTest +/// @notice Contract for testing the OptimismSuperchainERC20Beacon contract. +contract OptimismSuperchainERC20BeaconTest is Bridge_Initializer { + /// @notice Sets up the test suite. + function setUp() public override { + super.enableInterop(); + super.setUp(); + } + + /// @notice Test that calling the implementation function returns the correct implementation address. + function test_implementation_is_correct() public view { + IBeacon beacon = IBeacon(Predeploys.OPTIMISM_SUPERCHAIN_ERC20_BEACON); + assertEq(beacon.implementation(), Predeploys.OPTIMISM_SUPERCHAIN_ERC20); + } +} diff --git a/packages/contracts-bedrock/test/Predeploys.t.sol b/packages/contracts-bedrock/test/Predeploys.t.sol index 6c9ac3750a03..dd27284447bf 100644 --- a/packages/contracts-bedrock/test/Predeploys.t.sol +++ b/packages/contracts-bedrock/test/Predeploys.t.sol @@ -32,7 +32,7 @@ contract PredeploysBaseTest is CommonTest { function _usesImmutables(address _addr) internal pure returns (bool) { return _addr == Predeploys.OPTIMISM_MINTABLE_ERC721_FACTORY || _addr == Predeploys.SEQUENCER_FEE_WALLET || _addr == Predeploys.BASE_FEE_VAULT || _addr == Predeploys.L1_FEE_VAULT || _addr == Predeploys.EAS - || _addr == Predeploys.GOVERNANCE_TOKEN || _addr == Predeploys.OPTIMISM_SUPERCHAIN_ERC20_BEACON; + || _addr == Predeploys.GOVERNANCE_TOKEN; } function test_predeployToCodeNamespace() external pure {