Skip to content

Commit

Permalink
fix: remove immutables from superchain erc20 beacon (#67)
Browse files Browse the repository at this point in the history
* fix: remove immutables from superchain erc20 beacon

* test: add superchain erc20 beacon tests
  • Loading branch information
agusduha authored Sep 30, 2024
1 parent e1fe38e commit 40e2069
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 37 deletions.
13 changes: 3 additions & 10 deletions packages/contracts-bedrock/scripts/L2Genesis.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
4 changes: 2 additions & 2 deletions packages/contracts-bedrock/semver-lock.json
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,8 @@
"sourceCodeHash": "0xe853817da47d32b4ec5bb5392405278c82a1e9620aef377491dcb371fbbe682f"
},
"src/L2/OptimismSuperchainERC20Beacon.sol": {
"initCodeHash": "0x99ce8095b23c124850d866cbc144fee6cee05dbc6bb5d83acadfe00b90cf42c7",
"sourceCodeHash": "0x5e58b7c867fafa49fe39d68d83875425e9cf94f05f2835bdcdaa08fc8bc6b68e"
"initCodeHash": "0x23dba3ceb9e58646695c306996c9e15251ac79acc6339c1a93d10a4c79da6dab",
"sourceCodeHash": "0xf4379e49665823c877f5732f35068435ce06e2394fce6910a5e113d16cdc9f95"
},
"src/L2/OptimismSuperchainERC20Factory.sol": {
"initCodeHash": "0x524bc58927ca60ba2fbc4b036ad00c5055758d5c5b2ebb3d75cb9b996175f2cb",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,4 @@
[
{
"inputs": [
{
"internalType": "address",
"name": "_implementation",
"type": "address"
}
],
"stateMutability": "nonpayable",
"type": "constructor"
},
{
"inputs": [],
"name": "implementation",
Expand All @@ -20,7 +9,7 @@
"type": "address"
}
],
"stateMutability": "view",
"stateMutability": "pure",
"type": "function"
},
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Original file line number Diff line number Diff line change
@@ -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);
}
}
2 changes: 1 addition & 1 deletion packages/contracts-bedrock/test/Predeploys.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 40e2069

Please sign in to comment.