Skip to content

Commit

Permalink
Merge pull request #1164 from matter-labs/sb-cleanup-scripts
Browse files Browse the repository at this point in the history
Cleanup scripts
  • Loading branch information
StanislavBreadless authored Dec 31, 2024
2 parents 49c688f + 0d9dd9e commit 3e2dad0
Show file tree
Hide file tree
Showing 8 changed files with 31 additions and 24 deletions.
2 changes: 1 addition & 1 deletion l1-contracts/contracts/governance/ChainAdmin.sol
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import {ReentrancyGuard} from "../common/ReentrancyGuard.sol";
/// so called "restrictions": contracts that implement the `IRestriction` interface and ensure that
/// particular restrictions are ensured for the contract, including access control, security invariants, etc.
/// @dev This is a new EXPERIMENTAL version of the `ChainAdmin` implementation. While chains may opt into using it,
/// using the old `ChainAdminSingleOwner` is recommended.
/// using the old `ChainAdminOwnable` is recommended.
contract ChainAdmin is IChainAdmin, ReentrancyGuard {
using EnumerableSet for EnumerableSet.AddressSet;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
pragma solidity 0.8.24;

import {Ownable2Step} from "@openzeppelin/contracts-v4/access/Ownable2Step.sol";
import {IChainAdminSingleOwner} from "./IChainAdminSingleOwner.sol";
import {IChainAdminOwnable} from "./IChainAdminOwnable.sol";
import {IAdmin} from "../state-transition/chain-interfaces/IAdmin.sol";
import {NoCallsProvided, Unauthorized, ZeroAddress} from "../common/L1ContractErrors.sol";

Expand All @@ -13,7 +13,7 @@ import {NoCallsProvided, Unauthorized, ZeroAddress} from "../common/L1ContractEr
/// The owner of the contract can perform any external calls and also save the information needed for
/// the blockchain node to accept the protocol upgrade. Another role - `tokenMultiplierSetter` can be used in the contract
/// to change the base token gas price in the Chain contract.
contract ChainAdminSingleOwner is IChainAdminSingleOwner, Ownable2Step {
contract ChainAdminOwnable is IChainAdminOwnable, Ownable2Step {
/// @notice Mapping of protocol versions to their expected upgrade timestamps.
/// @dev Needed for the offchain node administration to know when to start building batches with the new protocol version.
mapping(uint256 protocolVersion => uint256 upgradeTimestamp) public protocolVersionToUpgradeTimestamp;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {IAdmin} from "../state-transition/chain-interfaces/IAdmin.sol";
/// @title ChainAdmin contract interface
/// @author Matter Labs
/// @custom:security-contact [email protected]
interface IChainAdminSingleOwner {
interface IChainAdminOwnable {
/// @dev Represents a call to be made during multicall.
/// @param target The address to which the call will be made.
/// @param value The amount of Ether (in wei) to be sent along with the call.
Expand Down
8 changes: 4 additions & 4 deletions l1-contracts/deploy-scripts/AcceptAdmin.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {IAdmin} from "contracts/state-transition/chain-interfaces/IAdmin.sol";
import {ChainAdmin} from "contracts/governance/ChainAdmin.sol";
import {AccessControlRestriction} from "contracts/governance/AccessControlRestriction.sol";
import {IChainAdmin} from "contracts/governance/IChainAdmin.sol";
import {IChainAdminSingleOwner} from "contracts/governance/IChainAdminSingleOwner.sol";
import {IChainAdminOwnable} from "contracts/governance/IChainAdminOwnable.sol";
import {Call} from "contracts/governance/Common.sol";
import {Utils} from "./Utils.sol";
import {IGovernance} from "contracts/governance/IGovernance.sol";
Expand Down Expand Up @@ -83,14 +83,14 @@ contract AcceptAdmin is Script {
address setter
) public {
if (accessControlRestriction == address(0)) {
_chainSetTokenMultiplierSetterSingleOwner(chainAdmin, setter);
_chainSetTokenMultiplierSetterOwnable(chainAdmin, setter);
} else {
_chainSetTokenMultiplierSetterLatestChainAdmin(accessControlRestriction, diamondProxyAddress, setter);
}
}

function _chainSetTokenMultiplierSetterSingleOwner(address chainAdmin, address setter) internal {
IChainAdminSingleOwner admin = IChainAdminSingleOwner(chainAdmin);
function _chainSetTokenMultiplierSetterOwnable(address chainAdmin, address setter) internal {
IChainAdminOwnable admin = IChainAdminOwnable(chainAdmin);

vm.startBroadcast();
admin.setTokenMultiplierSetter(setter);
Expand Down
10 changes: 5 additions & 5 deletions l1-contracts/deploy-scripts/DeployUtils.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ import {IMessageRoot} from "contracts/bridgehub/IMessageRoot.sol";
import {IAssetRouterBase} from "contracts/bridge/asset-router/IAssetRouterBase.sol";
import {L2ContractsBytecodesLib} from "./L2ContractsBytecodesLib.sol";
import {BytecodesSupplier} from "contracts/upgrades/BytecodesSupplier.sol";
import {ChainAdminSingleOwner} from "contracts/governance/ChainAdminSingleOwner.sol";
import {ChainAdminOwnable} from "contracts/governance/ChainAdminOwnable.sol";

struct FixedForceDeploymentsData {
uint256 l1ChainId;
Expand Down Expand Up @@ -334,22 +334,22 @@ contract DeployUtils is Script {

function deployChainAdmin() internal {
// TODO(EVM-924): provide an option to deploy a non-single owner ChainAdmin.
(address chainAdmin, address accessControlRestriction) = deployChainAdminSingleOwner();
(address chainAdmin, address accessControlRestriction) = deployChainAdminOwnable();

addresses.accessControlRestrictionAddress = accessControlRestriction;
addresses.chainAdmin = chainAdmin;
}

function deployChainAdminSingleOwner() internal returns (address chainAdmin, address accessControlRestriction) {
function deployChainAdminOwnable() internal returns (address chainAdmin, address accessControlRestriction) {
chainAdmin = deployViaCreate2(
type(ChainAdminSingleOwner).creationCode,
type(ChainAdminOwnable).creationCode,
abi.encode(config.ownerAddress, address(0))
);
// The single owner chainAdmin does not have a separate control restriction contract.
// We set to it to zero explicitly so that it is clear to the reader.
accessControlRestriction = address(0);

console.log("ChainAdminSingleOwner deployed at:", accessControlRestriction);
console.log("ChainAdminOwnable deployed at:", accessControlRestriction);
}

// TODO(EVM-924): this function is unused
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ library L2LegacySharedBridgeTestHelper {
address l1Erc20BridgeProxy,
address l1NullifierProxy,
address ecosystemL1Governance
) internal view returns (address tokenBeaconAddress, bytes32 tokenBeaconBytecodeHash) {
) internal view returns (address tokenBeaconAddress, bytes32 tokenBeaconProxyBytecodeHash) {
address l2SharedBridgeAddress = calculateL2LegacySharedBridgeProxyAddr(
l1Erc20BridgeProxy,
l1NullifierProxy,
Expand All @@ -84,9 +84,12 @@ library L2LegacySharedBridgeTestHelper {
keccak256(hex"")
);

tokenBeaconBytecodeHash = L2ContractHelper.hashL2Bytecode(
bytes32 tokenBeaconBytecodeHash = L2ContractHelper.hashL2Bytecode(
L2ContractsBytecodesLib.readUpgradeableBeaconBytecode()
);
tokenBeaconProxyBytecodeHash = L2ContractHelper.hashL2Bytecode(
L2ContractsBytecodesLib.readBeaconProxyBytecode()
);
tokenBeaconAddress = L2ContractHelper.computeCreate2Address(
l2SharedBridgeAddress,
bytes32(0),
Expand Down
10 changes: 5 additions & 5 deletions l1-contracts/deploy-scripts/RegisterZKChain.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ import {Call} from "contracts/governance/Common.sol";

import {ETH_TOKEN_ADDRESS} from "contracts/common/Config.sol";
import {CreateAndTransfer} from "./CreateAndTransfer.sol";
import {ChainAdminSingleOwner} from "contracts/governance/ChainAdminSingleOwner.sol";
import {ChainAdminOwnable} from "contracts/governance/ChainAdminOwnable.sol";

// solhint-disable-next-line gas-struct-packing
struct Config {
Expand Down Expand Up @@ -335,23 +335,23 @@ contract RegisterZKChainScript is Script {

function deployChainAdmin() internal {
// TODO(EVM-924): provide an option to deploy a non-single owner ChainAdmin.
(address chainAdmin, address accessControlRestriction) = deployChainAdminSingleOwner();
(address chainAdmin, address accessControlRestriction) = deployChainAdminOwnable();

output.accessControlRestrictionAddress = accessControlRestriction;
output.chainAdmin = chainAdmin;
}

function deployChainAdminSingleOwner() internal returns (address chainAdmin, address accessControlRestriction) {
function deployChainAdminOwnable() internal returns (address chainAdmin, address accessControlRestriction) {
chainAdmin = Utils.deployViaCreate2(
abi.encodePacked(type(ChainAdminSingleOwner).creationCode, abi.encode(config.ownerAddress, address(0))),
abi.encodePacked(type(ChainAdminOwnable).creationCode, abi.encode(config.ownerAddress, address(0))),
config.create2Salt,
config.create2FactoryAddress
);
// The single owner chainAdmin does not have a separate control restriction contract.
// We set to it to zero explicitly so that it is clear to the reader.
accessControlRestriction = address(0);

console.log("ChainAdminSingleOwner deployed at:", accessControlRestriction);
console.log("ChainAdminOwnable deployed at:", accessControlRestriction);
}

// TODO(EVM-924): this function is unused
Expand Down
12 changes: 8 additions & 4 deletions l1-contracts/deploy-scripts/dev/SetupLegacyBridge.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ contract SetupLegacyBridge is Script {

struct Config {
uint256 chainId;
address l2SharedBridgeAddress;
bytes32 create2FactorySalt;
}

Expand Down Expand Up @@ -68,7 +67,6 @@ contract SetupLegacyBridge is Script {
addresses.tokenWethAddress = toml.readAddress("$.token_weth_address");
addresses.create2FactoryAddr = toml.readAddress("$.create2factory_addr");
config.chainId = toml.readUint("$.chain_id");
config.l2SharedBridgeAddress = toml.readAddress("$.l2shared_bridge_address");
config.create2FactorySalt = toml.readBytes32("$.create2factory_salt");
}

Expand Down Expand Up @@ -129,16 +127,22 @@ contract SetupLegacyBridge is Script {
}

function setParamsForDummyBridge() internal {
(address l2TokenBeacon, bytes32 l2TokenBeaconHash) = L2LegacySharedBridgeTestHelper
(address l2TokenBeacon, bytes32 l2TokenBeaconProxyHash) = L2LegacySharedBridgeTestHelper
.calculateTestL2TokenBeaconAddress(
addresses.erc20BridgeProxy,
addresses.l1Nullifier,
Ownable2StepUpgradeable(addresses.l1Nullifier).owner()
);

address l2LegacySharedBridgeAddress = L2LegacySharedBridgeTestHelper.calculateL2LegacySharedBridgeProxyAddr(
addresses.erc20BridgeProxy,
addresses.l1Nullifier,
Ownable2StepUpgradeable(addresses.l1Nullifier).owner()
);

DummyL1ERC20Bridge bridge = DummyL1ERC20Bridge(addresses.erc20BridgeProxy);
vm.broadcast();
bridge.setValues(config.l2SharedBridgeAddress, l2TokenBeacon, l2TokenBeaconHash);
bridge.setValues(l2LegacySharedBridgeAddress, l2TokenBeacon, l2TokenBeaconProxyHash);
}

function calculateL2Create2Address(
Expand Down

0 comments on commit 3e2dad0

Please sign in to comment.