Skip to content

Commit

Permalink
Merge pull request #599 from matter-labs/mp-admin-contract-scripts
Browse files Browse the repository at this point in the history
Chain admin contract scripts
  • Loading branch information
perekopskiy authored Jul 29, 2024
2 parents 26f6e04 + c863a65 commit 172e073
Show file tree
Hide file tree
Showing 8 changed files with 71 additions and 19 deletions.
24 changes: 13 additions & 11 deletions l1-contracts/deploy-scripts/AcceptAdmin.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@ import {Script} from "forge-std/Script.sol";

import {Ownable2Step} from "@openzeppelin/contracts/access/Ownable2Step.sol";
import {IZkSyncHyperchain} from "contracts/state-transition/chain-interfaces/IZkSyncHyperchain.sol";
import {ChainAdmin} from "contracts/governance/ChainAdmin.sol";
import {IChainAdmin} from "contracts/governance/IChainAdmin.sol";
import {Utils} from "./Utils.sol";

contract AcceptAdmin is Script {
// This function should be called by the owner to accept the admin role
// This function should be called by the owner to accept the owner role
function acceptOwner(address governor, address target) public {
Ownable2Step adminContract = Ownable2Step(target);
Utils.executeUpgrade({
Expand All @@ -22,15 +24,15 @@ contract AcceptAdmin is Script {
}

// This function should be called by the owner to accept the admin role
function acceptAdmin(address governor, address target) public {
IZkSyncHyperchain adminContract = IZkSyncHyperchain(target);
Utils.executeUpgrade({
_governor: governor,
_salt: bytes32(0),
_target: target,
_data: abi.encodeCall(adminContract.acceptAdmin, ()),
_value: 0,
_delay: 0
});
function acceptAdmin(address payable _admin, address _target) public {
IZkSyncHyperchain hyperchain = IZkSyncHyperchain(_target);
ChainAdmin chainAdmin = ChainAdmin(_admin);

IChainAdmin.Call[] memory calls = new IChainAdmin.Call[](1);
calls[0] = IChainAdmin.Call({target: _target, value: 0, data: abi.encodeCall(hyperchain.acceptAdmin, ())});

vm.startBroadcast();
chainAdmin.multicall(calls, true);
vm.stopBroadcast();
}
}
10 changes: 10 additions & 0 deletions l1-contracts/deploy-scripts/DeployL1.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import {TestnetVerifier} from "contracts/state-transition/TestnetVerifier.sol";
import {VerifierParams, IVerifier} from "contracts/state-transition/chain-interfaces/IVerifier.sol";
import {DefaultUpgrade} from "contracts/upgrades/DefaultUpgrade.sol";
import {Governance} from "contracts/governance/Governance.sol";
import {ChainAdmin} from "contracts/governance/ChainAdmin.sol";
import {GenesisUpgrade} from "contracts/upgrades/GenesisUpgrade.sol";
import {ValidatorTimelock} from "contracts/state-transition/ValidatorTimelock.sol";
import {Bridgehub} from "contracts/bridgehub/Bridgehub.sol";
Expand Down Expand Up @@ -45,6 +46,7 @@ contract DeployL1Script is Script {
BridgesDeployedAddresses bridges;
address transparentProxyAdmin;
address governance;
address chainAdmin;
address blobVersionedHashRetriever;
address validatorTimelock;
address create2Factory;
Expand Down Expand Up @@ -135,6 +137,7 @@ contract DeployL1Script is Script {
deployValidatorTimelock();

deployGovernance();
deployChainAdmin();
deployTransparentProxyAdmin();
deployBridgehubContract();
deployBlobVersionedHashRetriever();
Expand Down Expand Up @@ -291,6 +294,13 @@ contract DeployL1Script is Script {
addresses.governance = contractAddress;
}

function deployChainAdmin() internal {
bytes memory bytecode = abi.encodePacked(type(ChainAdmin).creationCode, abi.encode(config.ownerAddress));
address contractAddress = deployViaCreate2(bytecode);
console.log("ChainAdmin deployed at:", contractAddress);
addresses.chainAdmin = contractAddress;
}

function deployTransparentProxyAdmin() internal {
vm.startBroadcast();
ProxyAdmin proxyAdmin = new ProxyAdmin();
Expand Down
15 changes: 13 additions & 2 deletions l1-contracts/deploy-scripts/RegisterHyperchain.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {IBridgehub} from "contracts/bridgehub/IBridgehub.sol";
import {IZkSyncHyperchain} from "contracts/state-transition/chain-interfaces/IZkSyncHyperchain.sol";
import {ValidatorTimelock} from "contracts/state-transition/ValidatorTimelock.sol";
import {Governance} from "contracts/governance/Governance.sol";
import {ChainAdmin} from "contracts/governance/ChainAdmin.sol";
import {Utils} from "./Utils.sol";
import {PubdataPricingMode} from "contracts/state-transition/chain-deps/ZkSyncHyperchainStorage.sol";

Expand Down Expand Up @@ -40,6 +41,7 @@ contract RegisterHyperchainScript is Script {
uint256 governanceMinDelay;
address newDiamondProxy;
address governance;
address chainAdmin;
}

Config config;
Expand All @@ -50,6 +52,7 @@ contract RegisterHyperchainScript is Script {
initializeConfig();

deployGovernance();
deployChainAdmin();
checkTokenAddress();
registerTokenOnBridgehub();
registerHyperchain();
Expand Down Expand Up @@ -145,6 +148,13 @@ contract RegisterHyperchainScript is Script {
config.governance = address(governance);
}

function deployChainAdmin() internal {
vm.broadcast();
ChainAdmin chainAdmin = new ChainAdmin(config.ownerAddress);
console.log("ChainAdmin deployed at:", address(chainAdmin));
config.chainAdmin = address(chainAdmin);
}

function registerHyperchain() internal {
IBridgehub bridgehub = IBridgehub(config.bridgehub);
Ownable ownable = Ownable(config.bridgehub);
Expand Down Expand Up @@ -220,12 +230,13 @@ contract RegisterHyperchainScript is Script {
IZkSyncHyperchain hyperchain = IZkSyncHyperchain(config.newDiamondProxy);

vm.broadcast();
hyperchain.setPendingAdmin(config.governance);
console.log("Owner for ", config.newDiamondProxy, "set to", config.governance);
hyperchain.setPendingAdmin(config.chainAdmin);
console.log("Owner for ", config.newDiamondProxy, "set to", config.chainAdmin);
}

function saveOutput() internal {
vm.serializeAddress("root", "diamond_proxy_addr", config.newDiamondProxy);
vm.serializeAddress("root", "chain_admin_addr", config.chainAdmin);
string memory toml = vm.serializeAddress("root", "governance_addr", config.governance);
string memory root = vm.projectRoot();
string memory path = string.concat(root, "/script-out/output-register-hyperchain.toml");
Expand Down
2 changes: 1 addition & 1 deletion l1-contracts/scripts/register-hyperchain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ async function main() {
}

await deployer.registerHyperchain(baseTokenAddress, cmd.validiumMode, null, gasPrice, useGovernance);
await deployer.transferAdminFromDeployerToGovernance();
await deployer.transferAdminFromDeployerToChainAdmin();
});

await program.parseAsync(process.argv);
Expand Down
3 changes: 3 additions & 0 deletions l1-contracts/src.ts/deploy-process.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,9 @@ export async function initialBridgehubDeployment(
nonce++;

await deployer.deployGovernance(create2Salt, { gasPrice, nonce });
nonce++;

await deployer.deployChainAdmin(create2Salt, { gasPrice, nonce });
await deployer.deployTransparentProxyAdmin(create2Salt, { gasPrice });
await deployer.deployBridgehubContract(create2Salt, gasPrice);
await deployer.deployBlobVersionedHashRetriever(create2Salt, { gasPrice });
Expand Down
3 changes: 3 additions & 0 deletions l1-contracts/src.ts/deploy-test-process.ts
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,9 @@ export async function initialPreUpgradeContractsDeployment(
nonce++;

await deployer.deployGovernance(create2Salt, { gasPrice, nonce });
nonce++;

await deployer.deployChainAdmin(create2Salt, { gasPrice, nonce });
await deployer.deployTransparentProxyAdmin(create2Salt, { gasPrice });
await deployer.deployBlobVersionedHashRetriever(create2Salt, { gasPrice });

Expand Down
2 changes: 2 additions & 0 deletions l1-contracts/src.ts/deploy-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ export interface DeployedAddresses {
BaseToken: string;
TransparentProxyAdmin: string;
Governance: string;
ChainAdmin: string;
BlobVersionedHashRetriever: string;
ValidatorTimeLock: string;
Create2Factory: string;
Expand Down Expand Up @@ -152,5 +153,6 @@ export function deployedAddressesFromEnv(): DeployedAddresses {
BlobVersionedHashRetriever: getAddressFromEnv("CONTRACTS_BLOB_VERSIONED_HASH_RETRIEVER_ADDR"),
ValidatorTimeLock: getAddressFromEnv("CONTRACTS_VALIDATOR_TIMELOCK_ADDR"),
Governance: getAddressFromEnv("CONTRACTS_GOVERNANCE_ADDR"),
ChainAdmin: getAddressFromEnv("CONTRACTS_CHAIN_ADMIN_ADDR"),
};
}
31 changes: 26 additions & 5 deletions l1-contracts/src.ts/deploy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ import { ValidatorTimelockFactory } from "../typechain/ValidatorTimelockFactory"
import type { FacetCut } from "./diamondCut";
import { getCurrentFacetCutsForAdd } from "./diamondCut";

import { ERC20Factory } from "../typechain";
import { ChainAdminFactory, ERC20Factory } from "../typechain";
import type { Contract, Overrides } from "@ethersproject/contracts";

let L2_BOOTLOADER_BYTECODE_HASH: string;
Expand Down Expand Up @@ -190,6 +190,15 @@ export class Deployer {
this.addresses.Governance = contractAddress;
}

public async deployChainAdmin(create2Salt: string, ethTxOptions: ethers.providers.TransactionRequest) {
ethTxOptions.gasLimit ??= 10_000_000;
const contractAddress = await this.deployViaCreate2("ChainAdmin", [this.ownerAddress], create2Salt, ethTxOptions);
if (this.verbose) {
console.log(`CONTRACTS_CHAIN_ADMIN_ADDR=${contractAddress}`);
}
this.addresses.ChainAdmin = contractAddress;
}

public async deployBridgehubImplementation(create2Salt: string, ethTxOptions: ethers.providers.TransactionRequest) {
ethTxOptions.gasLimit ??= 10_000_000;
const contractAddress = await this.deployViaCreate2("Bridgehub", [], create2Salt, ethTxOptions);
Expand Down Expand Up @@ -798,17 +807,29 @@ export class Deployer {
}
}

public async transferAdminFromDeployerToGovernance() {
public async transferAdminFromDeployerToChainAdmin() {
const stm = this.stateTransitionManagerContract(this.deployWallet);
const diamondProxyAddress = await stm.getHyperchain(this.chainId);
const hyperchain = IZkSyncHyperchainFactory.connect(diamondProxyAddress, this.deployWallet);

const receipt = await (await hyperchain.setPendingAdmin(this.addresses.Governance)).wait();
const receipt = await (await hyperchain.setPendingAdmin(this.addresses.ChainAdmin)).wait();
if (this.verbose) {
console.log(`Governance set as pending admin, gas used: ${receipt.gasUsed.toString()}`);
console.log(`ChainAdmin set as pending admin, gas used: ${receipt.gasUsed.toString()}`);
}

await this.executeUpgrade(hyperchain.address, 0, hyperchain.interface.encodeFunctionData("acceptAdmin"), false);
const acceptAdminData = hyperchain.interface.encodeFunctionData("acceptAdmin");
const chainAdmin = ChainAdminFactory.connect(this.addresses.ChainAdmin, this.deployWallet);
const multicallTx = await chainAdmin.multicall(
[
{
target: hyperchain.address,
value: 0,
data: acceptAdminData,
},
],
true
);
await multicallTx.wait();

if (this.verbose) {
console.log("Pending admin successfully accepted");
Expand Down

0 comments on commit 172e073

Please sign in to comment.