diff --git a/l1-contracts/scripts/register-hyperchain.ts b/l1-contracts/scripts/register-hyperchain.ts index 755352f9b..3fea4b9f8 100644 --- a/l1-contracts/scripts/register-hyperchain.ts +++ b/l1-contracts/scripts/register-hyperchain.ts @@ -59,12 +59,9 @@ async function main() { program .option("--private-key ") - .option("--chain-id ") .option("--gas-price ") .option("--nonce ") .option("--governor-address ") - .option("--create2-salt ") - .option("--diamond-upgrade-init ") .option("--only-verifier") .option("--validium-mode") .option("--base-token-name ") @@ -106,7 +103,16 @@ async function main() { await deployer.registerToken(baseTokenAddress, useGovernance); } - await deployer.registerHyperchain(baseTokenAddress, cmd.validiumMode, null, gasPrice, useGovernance); + await deployer.registerHyperchain( + baseTokenAddress, + cmd.validiumMode, + null, + gasPrice, + true, + null, + null, + useGovernance + ); await deployer.transferAdminFromDeployerToGovernance(); }); diff --git a/l1-contracts/src.ts/deploy-process.ts b/l1-contracts/src.ts/deploy-process.ts index f495bb69a..94a403fb8 100644 --- a/l1-contracts/src.ts/deploy-process.ts +++ b/l1-contracts/src.ts/deploy-process.ts @@ -93,6 +93,7 @@ export async function registerHyperchain( validiumMode, extraFacets, gasPrice, + false, null, chainId, useGovernance diff --git a/l1-contracts/src.ts/deploy.ts b/l1-contracts/src.ts/deploy.ts index 4ff958560..6e3106127 100644 --- a/l1-contracts/src.ts/deploy.ts +++ b/l1-contracts/src.ts/deploy.ts @@ -34,10 +34,11 @@ import { L1SharedBridgeFactory } from "../typechain/L1SharedBridgeFactory"; import { SingletonFactoryFactory } from "../typechain/SingletonFactoryFactory"; import { ValidatorTimelockFactory } from "../typechain/ValidatorTimelockFactory"; + import type { FacetCut } from "./diamondCut"; import { getCurrentFacetCutsForAdd } from "./diamondCut"; -import { ERC20Factory } from "../typechain"; +import { ERC20Factory, StateTransitionManagerFactory } from "../typechain"; import type { Contract, Overrides } from "@ethersproject/contracts"; let L2_BOOTLOADER_BYTECODE_HASH: string; @@ -81,7 +82,7 @@ export class Deployer { this.chainId = parseInt(process.env.CHAIN_ETH_ZKSYNC_NETWORK_ID!); } - public async initialZkSyncHyperchainDiamondCut(extraFacets?: FacetCut[]) { + public async initialZkSyncHyperchainDiamondCut(extraFacets?: FacetCut[], compareDiamondCutHash: boolean = false) { let facetCuts: FacetCut[] = Object.values( await getCurrentFacetCutsForAdd( this.addresses.StateTransition.AdminFacet, @@ -99,7 +100,7 @@ export class Deployer { }; const priorityTxMaxGasLimit = getNumberFromEnv("CONTRACTS_PRIORITY_TX_MAX_GAS_LIMIT"); - return compileInitialCutHash( + const diamondCut = compileInitialCutHash( facetCuts, verifierParams, L2_BOOTLOADER_BYTECODE_HASH, @@ -110,6 +111,25 @@ export class Deployer { this.addresses.StateTransition.DiamondInit, false ); + + if (compareDiamondCutHash) { + const hash = ethers.utils.keccak256( + ethers.utils.defaultAbiCoder.encode([DIAMOND_CUT_DATA_ABI_STRING], [diamondCut]) + ); + + console.log(`Diamond cut hash: ${hash}`); + const stm = StateTransitionManagerFactory.connect( + this.addresses.StateTransition.StateTransitionProxy, + this.deployWallet + ); + + const hashFromSTM = await stm.initialCutHash(); + if (hash != hashFromSTM) { + throw new Error(`Has from STM ${hashFromSTM} does not match the computed hash ${hash}`); + } + } + + return diamondCut; } public async deployCreate2Factory(ethTxOptions?: ethers.providers.TransactionRequest) { @@ -685,6 +705,7 @@ export class Deployer { validiumMode: boolean, extraFacets?: FacetCut[], gasPrice?: BigNumberish, + compareDiamondCutHash: boolean = false, nonce?, predefinedChainId?: string, useGovernance: boolean = false @@ -698,7 +719,7 @@ export class Deployer { const inputChainId = predefinedChainId || getNumberFromEnv("CHAIN_ETH_ZKSYNC_NETWORK_ID"); const admin = process.env.CHAIN_ADMIN_ADDRESS || this.ownerAddress; - const diamondCutData = await this.initialZkSyncHyperchainDiamondCut(extraFacets); + const diamondCutData = await this.initialZkSyncHyperchainDiamondCut(extraFacets, compareDiamondCutHash); const initialDiamondCut = new ethers.utils.AbiCoder().encode([DIAMOND_CUT_DATA_ABI_STRING], [diamondCutData]); const receipt = await this.executeDirectOrGovernance( @@ -751,7 +772,8 @@ export class Deployer { console.log(`CONTRACTS_DIAMOND_PROXY_ADDR=${diamondProxyAddress}`); } } - this.chainId = parseInt(chainId, 16); + const intChainId = parseInt(chainId, 16); + this.chainId = intChainId; const validatorOneAddress = getAddressFromEnv("ETH_SENDER_SENDER_OPERATOR_COMMIT_ETH_ADDR"); const validatorTwoAddress = getAddressFromEnv("ETH_SENDER_SENDER_OPERATOR_BLOBS_ETH_ADDR"); @@ -783,18 +805,25 @@ export class Deployer { } const diamondProxy = this.stateTransitionContract(this.deployWallet); - const tx4 = await diamondProxy.setTokenMultiplier(1, 1); - const receipt4 = await tx4.wait(); - if (this.verbose) { - console.log(`BaseTokenMultiplier set, gas used: ${receipt4.gasUsed.toString()}`); - } - - if (validiumMode) { - const tx5 = await diamondProxy.setPubdataPricingMode(PubdataPricingMode.Validium); - const receipt5 = await tx5.wait(); + // if we are using governance, the deployer will not be the admin, so we can't call the diamond proxy directly + if (admin == this.deployWallet.address) { + const tx4 = await diamondProxy.setTokenMultiplier(1, 1); + const receipt4 = await tx4.wait(); if (this.verbose) { - console.log(`Validium mode set, gas used: ${receipt5.gasUsed.toString()}`); + console.log(`BaseTokenMultiplier set, gas used: ${receipt4.gasUsed.toString()}`); } + + if (validiumMode) { + const tx5 = await diamondProxy.setPubdataPricingMode(PubdataPricingMode.Validium); + const receipt5 = await tx5.wait(); + if (this.verbose) { + console.log(`Validium mode set, gas used: ${receipt5.gasUsed.toString()}`); + } + } + } else { + console.warn( + "BaseTokenMultiplier and Validium mode can't be set through the governance, please set it separately, using the admin account" + ); } }