Commit 3af1faf1 authored by AgusDuha's avatar AgusDuha Committed by GitHub

fix: remove immutables from superchain erc20 beacon (#12207)

* fix: remove immutables from superchain erc20 beacon (#67)

* fix: remove immutables from superchain erc20 beacon

* test: add superchain erc20 beacon tests

* fix: superchain erc20 beacon interface (#99)
parent 94204e94
...@@ -21,7 +21,6 @@ import { Types } from "src/libraries/Types.sol"; ...@@ -21,7 +21,6 @@ import { Types } from "src/libraries/Types.sol";
import { ISequencerFeeVault } from "src/L2/interfaces/ISequencerFeeVault.sol"; import { ISequencerFeeVault } from "src/L2/interfaces/ISequencerFeeVault.sol";
import { IBaseFeeVault } from "src/L2/interfaces/IBaseFeeVault.sol"; import { IBaseFeeVault } from "src/L2/interfaces/IBaseFeeVault.sol";
import { IL1FeeVault } from "src/L2/interfaces/IL1FeeVault.sol"; import { IL1FeeVault } from "src/L2/interfaces/IL1FeeVault.sol";
import { IOptimismSuperchainERC20Beacon } from "src/L2/interfaces/IOptimismSuperchainERC20Beacon.sol";
import { IOptimismMintableERC721Factory } from "src/universal/interfaces/IOptimismMintableERC721Factory.sol"; import { IOptimismMintableERC721Factory } from "src/universal/interfaces/IOptimismMintableERC721Factory.sol";
import { IGovernanceToken } from "src/governance/interfaces/IGovernanceToken.sol"; import { IGovernanceToken } from "src/governance/interfaces/IGovernanceToken.sol";
import { IOptimismMintableERC20Factory } from "src/universal/interfaces/IOptimismMintableERC20Factory.sol"; import { IOptimismMintableERC20Factory } from "src/universal/interfaces/IOptimismMintableERC20Factory.sol";
...@@ -577,29 +576,14 @@ contract L2Genesis is Deployer { ...@@ -577,29 +576,14 @@ contract L2Genesis is Deployer {
_setImplementationCode(Predeploys.OPTIMISM_SUPERCHAIN_ERC20_FACTORY); _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 { function setOptimismSuperchainERC20Beacon() internal {
address superchainERC20Impl = Predeploys.OPTIMISM_SUPERCHAIN_ERC20; address superchainERC20Impl = Predeploys.OPTIMISM_SUPERCHAIN_ERC20;
console.log("Setting %s implementation at: %s", "OptimismSuperchainERC20", superchainERC20Impl); console.log("Setting %s implementation at: %s", "OptimismSuperchainERC20", superchainERC20Impl);
vm.etch(superchainERC20Impl, vm.getDeployedCode("OptimismSuperchainERC20.sol:OptimismSuperchainERC20")); vm.etch(superchainERC20Impl, vm.getDeployedCode("OptimismSuperchainERC20.sol:OptimismSuperchainERC20"));
IOptimismSuperchainERC20Beacon beacon = IOptimismSuperchainERC20Beacon( _setImplementationCode(Predeploys.OPTIMISM_SUPERCHAIN_ERC20_BEACON);
DeployUtils.create1(
"OptimismSuperchainERC20Beacon",
DeployUtils.encodeConstructor(
abi.encodeCall(IOptimismSuperchainERC20Beacon.__constructor__, (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));
} }
/// @notice This predeploy is following the safety invariant #1. /// @notice This predeploy is following the safety invariant #1.
......
...@@ -112,8 +112,8 @@ ...@@ -112,8 +112,8 @@
"sourceCodeHash": "0xf32130f0b46333daba062c50ff6dcfadce1f177ff753bed2374d499ea9c2d98a" "sourceCodeHash": "0xf32130f0b46333daba062c50ff6dcfadce1f177ff753bed2374d499ea9c2d98a"
}, },
"src/L2/OptimismSuperchainERC20Beacon.sol": { "src/L2/OptimismSuperchainERC20Beacon.sol": {
"initCodeHash": "0x99ce8095b23c124850d866cbc144fee6cee05dbc6bb5d83acadfe00b90cf42c7", "initCodeHash": "0x23dba3ceb9e58646695c306996c9e15251ac79acc6339c1a93d10a4c79da6dab",
"sourceCodeHash": "0x5e58b7c867fafa49fe39d68d83875425e9cf94f05f2835bdcdaa08fc8bc6b68e" "sourceCodeHash": "0xf4379e49665823c877f5732f35068435ce06e2394fce6910a5e113d16cdc9f95"
}, },
"src/L2/OptimismSuperchainERC20Factory.sol": { "src/L2/OptimismSuperchainERC20Factory.sol": {
"initCodeHash": "0x18a362c57f08b611db98dfde96121385e938f995c84e3547c1c03fd49f9db2fd", "initCodeHash": "0x18a362c57f08b611db98dfde96121385e938f995c84e3547c1c03fd49f9db2fd",
......
[ [
{
"inputs": [
{
"internalType": "address",
"name": "_implementation",
"type": "address"
}
],
"stateMutability": "nonpayable",
"type": "constructor"
},
{ {
"inputs": [], "inputs": [],
"name": "implementation", "name": "implementation",
...@@ -20,7 +9,7 @@ ...@@ -20,7 +9,7 @@
"type": "address" "type": "address"
} }
], ],
"stateMutability": "view", "stateMutability": "pure",
"type": "function" "type": "function"
}, },
{ {
......
...@@ -3,25 +3,19 @@ pragma solidity 0.8.15; ...@@ -3,25 +3,19 @@ pragma solidity 0.8.15;
import { IBeacon } from "@openzeppelin/contracts/proxy/beacon/IBeacon.sol"; import { IBeacon } from "@openzeppelin/contracts/proxy/beacon/IBeacon.sol";
import { ISemver } from "src/universal/interfaces/ISemver.sol"; import { ISemver } from "src/universal/interfaces/ISemver.sol";
import { Predeploys } from "src/libraries/Predeploys.sol";
/// @custom:proxied /// @custom:proxied true
/// @custom:predeployed 0x4200000000000000000000000000000000000027 /// @custom:predeployed 0x4200000000000000000000000000000000000027
/// @title OptimismSuperchainERC20Beacon /// @title OptimismSuperchainERC20Beacon
/// @notice OptimismSuperchainERC20Beacon is the beacon proxy for the OptimismSuperchainERC20 implementation. /// @notice OptimismSuperchainERC20Beacon is the beacon proxy for the OptimismSuperchainERC20 implementation.
contract OptimismSuperchainERC20Beacon is IBeacon, ISemver { contract OptimismSuperchainERC20Beacon is IBeacon, ISemver {
/// @notice Address of the OptimismSuperchainERC20 implementation.
address internal immutable IMPLEMENTATION;
/// @notice Semantic version. /// @notice Semantic version.
/// @custom:semver 1.0.0-beta.1 /// @custom:semver 1.0.0-beta.2
string public constant version = "1.0.0-beta.1"; string public constant version = "1.0.0-beta.2";
constructor(address _implementation) {
IMPLEMENTATION = _implementation;
}
/// @inheritdoc IBeacon /// @inheritdoc IBeacon
function implementation() external view override returns (address) { function implementation() external pure override returns (address) {
return IMPLEMENTATION; return Predeploys.OPTIMISM_SUPERCHAIN_ERC20;
} }
} }
// SPDX-License-Identifier: MIT // SPDX-License-Identifier: MIT
pragma solidity ^0.8.0; pragma solidity ^0.8.0;
import { IBeacon } from "@openzeppelin/contracts/proxy/beacon/IBeacon.sol";
import { ISemver } from "src/universal/interfaces/ISemver.sol"; import { ISemver } from "src/universal/interfaces/ISemver.sol";
/// @title IOptimismSuperchainERC20Beacon /// @title IOptimismSuperchainERC20Beacon
/// @notice Interface for the OptimismSuperchainERC20Beacon contract /// @notice Interface for the OptimismSuperchainERC20Beacon contract
interface IOptimismSuperchainERC20Beacon is IBeacon, ISemver { interface IOptimismSuperchainERC20Beacon is ISemver {
function version() external view returns (string memory); function implementation() external pure returns (address);
function implementation() external view override returns (address);
function __constructor__(address _implementation) external; function __constructor__() external;
} }
// 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);
}
}
...@@ -31,7 +31,7 @@ contract PredeploysBaseTest is CommonTest { ...@@ -31,7 +31,7 @@ contract PredeploysBaseTest is CommonTest {
function _usesImmutables(address _addr) internal pure returns (bool) { function _usesImmutables(address _addr) internal pure returns (bool) {
return _addr == Predeploys.OPTIMISM_MINTABLE_ERC721_FACTORY || _addr == Predeploys.SEQUENCER_FEE_WALLET 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.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 { function test_predeployToCodeNamespace() external pure {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment