From 525ba9f22e3ad8aad0242b27daed4c1f67b293c1 Mon Sep 17 00:00:00 2001 From: Vlad Bochok <41153528+vladbochok@users.noreply.github.com> Date: Wed, 16 Oct 2024 17:53:29 +0400 Subject: [PATCH] fix(protocol upgrade tool): Remove legacy from protocol upgrade tool (#3064) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ## What ❔ Remove the calldata generated for `Governance.sol`. We don't use `Governance.sol` anymore and so this calldata is not needed. ## Why ❔ ## Checklist - [ x PR title corresponds to the body of PR (we generate changelog entries from PRs). - [ ] Tests for the changes have been added / updated. - [x] Documentation comments have been added / updated. - [x] Code has been formatted via `zk_supervisor fmt` and `zk_supervisor lint`. --- infrastructure/protocol-upgrade/README.md | 18 +- .../protocol-upgrade/src/transaction.ts | 410 +----------------- 2 files changed, 16 insertions(+), 412 deletions(-) diff --git a/infrastructure/protocol-upgrade/README.md b/infrastructure/protocol-upgrade/README.md index da5ee313dab8..c7998b961233 100644 --- a/infrastructure/protocol-upgrade/README.md +++ b/infrastructure/protocol-upgrade/README.md @@ -25,13 +25,15 @@ If not provided as arguments, the tool can retrieve certain values from environm 2. `l2rpc` - `API_WEB3_JSON_RPC_HTTP_URL` 3. `create2-address` - `CONTRACTS_CREATE2_FACTORY_ADDR` 4. `zksync-address` - `CONTRACTS_DIAMOND_PROXY_ADDR` -5. `nonce` - Taken from the node via `l1rpc` -6. `gas-price` - Taken from the node via `l1rpc` -7. `environment` - By default, set to `localhost`. Always specify it explicitly. Possible values: `localhost`, +5. `upgrade-address` - `CONTRACTS_DEFAULT_UPGRADE_ADDR` +6. `l2-upgrader-address` - `CONTRACTS_L2_DEFAULT_UPGRADE_ADDR` +7. `nonce` - Taken from the node via `l1rpc` +8. `gas-price` - Taken from the node via `l1rpc` +9. `environment` - By default, set to `localhost`. Always specify it explicitly. Possible values: `localhost`, `testnet2`, `stage2`, `mainnet2`. Each upgrade on different environments is performed separately since the contract addresses differ between environments. -8. `private-key` - If not specified, the default key from the default mnemonic will be used. Always specify it - explicitly. +10. `private-key` - If not specified, the default key from the default mnemonic will be used. Always specify it + explicitly. ### Create a Protocol Upgrade Proposal @@ -215,8 +217,7 @@ $ zk f yarn start transactions build-default \ --l2-upgrader-address \ --diamond-upgrade-proposal-id \ --l1rpc \ ---zksync-address \ ---use-new-governance +--zksync-address ``` To execute the `proposeTransparentUpgrade` transaction on L1, use the following command: @@ -228,7 +229,6 @@ $ zk f yarn start transactions propose-upgrade \ --gas-price \ --nonce \ --zksync-address \ ---new-governance \ --environment ``` @@ -241,7 +241,6 @@ $ zk f yarn start transactions execute-upgrade \ --gas-price \ --nonce \ --zksync-address \ ---new-governance \ --environment ``` @@ -254,6 +253,5 @@ $ zk f yarn start transactions cancel-upgrade \ --zksync-address \ --gas-price \ --nonce \ ---new-governance \ --environment ``` diff --git a/infrastructure/protocol-upgrade/src/transaction.ts b/infrastructure/protocol-upgrade/src/transaction.ts index dfea3a3bfc35..e7a3f32b3227 100644 --- a/infrastructure/protocol-upgrade/src/transaction.ts +++ b/infrastructure/protocol-upgrade/src/transaction.ts @@ -3,12 +3,10 @@ import { ForceDeployUpgraderFactory as ForceDeployUpgraderFactoryL2 } from 'l2-c import { DefaultUpgradeFactory as DefaultUpgradeFactoryL1, AdminFacetFactory, - GovernanceFactory, StateTransitionManagerFactory, ChainAdminFactory } from 'l1-contracts/typechain'; import { FacetCut } from 'l1-contracts/src.ts/diamondCut'; -import { IZkSyncFactory } from '../pre-boojum/IZkSyncFactory'; import { ComplexUpgraderFactory } from 'system-contracts/typechain'; import { getCommonDataFileName, @@ -89,7 +87,6 @@ export interface ProposedUpgrade { postUpgradeCalldata: BytesLike; upgradeTimestamp: ethers.BigNumber; newProtocolVersion: BigNumberish; - newAllowList: string; } function buildNoopL2UpgradeTx(): L2CanonicalTransaction { @@ -123,10 +120,8 @@ export function buildProposeUpgrade( bootloaderHash?: BytesLike, defaultAccountHash?: BytesLike, verifier?: string, - newAllowList?: string, l2ProtocolUpgradeTx?: L2CanonicalTransaction ): ProposedUpgrade { - newAllowList = newAllowList ?? ethers.constants.AddressZero; bootloaderHash = bootloaderHash ?? ethers.constants.HashZero; defaultAccountHash = defaultAccountHash ?? ethers.constants.HashZero; l1ContractsUpgradeCalldata = l1ContractsUpgradeCalldata ?? '0x'; @@ -142,8 +137,7 @@ export function buildProposeUpgrade( postUpgradeCalldata, upgradeTimestamp, factoryDeps: [], - newProtocolVersion, - newAllowList + newProtocolVersion }; } @@ -171,43 +165,6 @@ export function prepareDefaultCalldataForL2upgrade(forcedDeployments: ForceDeplo return complexUpgraderCalldata; } -interface GovernanceTx { - scheduleCalldata: string; - executeCalldata: string; - operation: any; -} - -function prepareGovernanceTxs(target: string, data: BytesLike): GovernanceTx { - const govCall = { - target: target, - value: 0, - data: data - }; - - const operation = { - calls: [govCall], - predecessor: ethers.constants.HashZero, - salt: ethers.constants.HashZero - }; - - const governance = new GovernanceFactory(); - - // Get transaction data of the `scheduleTransparent` - const scheduleCalldata = governance.interface.encodeFunctionData('scheduleTransparent', [ - operation, - 0 // delay - ]); - - // Get transaction data of the `execute` - const executeCalldata = governance.interface.encodeFunctionData('execute', [operation]); - - return { - scheduleCalldata, - executeCalldata, - operation - }; -} - function prepareChainAdminCalldata(target: string, data: BytesLike): string { const call = { target: target, @@ -221,14 +178,13 @@ function prepareChainAdminCalldata(target: string, data: BytesLike): string { return calldata; } -export function prepareTransparentUpgradeCalldataForNewGovernance( +export function prepareUpgradeCalldata( oldProtocolVersion, oldProtocolVersionDeadline, newProtocolVersion, initCalldata, upgradeAddress: string, facetCuts: FacetCut[], - stmAddress: string, zksyncAddress: string, prepareDirectOperation?: boolean, chainId?: string @@ -247,9 +203,6 @@ export function prepareTransparentUpgradeCalldataForNewGovernance( newProtocolVersion ]); - const { scheduleCalldata: stmScheduleTransparentOperation, executeCalldata: stmExecuteOperation } = - prepareGovernanceTxs(stmAddress, stmUpgradeCalldata); - // Prepare calldata for upgrading diamond proxy let adminFacet = new AdminFacetFactory(); const diamondProxyUpgradeCalldata = adminFacet.interface.encodeFunctionData('upgradeChainFromVersion', [ @@ -257,30 +210,12 @@ export function prepareTransparentUpgradeCalldataForNewGovernance( diamondCut ]); - const { - scheduleCalldata: scheduleTransparentOperation, - executeCalldata: executeOperation, - operation: governanceOperation - } = prepareGovernanceTxs(zksyncAddress, diamondProxyUpgradeCalldata); - - const newExecuteChainUpgradeCalldata = prepareChainAdminCalldata(zksyncAddress, diamondProxyUpgradeCalldata); - - const legacyScheduleTransparentOperation = adminFacet.interface.encodeFunctionData('executeUpgrade', [diamondCut]); - const { scheduleCalldata: legacyScheduleOperation, executeCalldata: legacyExecuteOperation } = prepareGovernanceTxs( - zksyncAddress, - legacyScheduleTransparentOperation - ); + const chainAdminUpgradeCalldata = prepareChainAdminCalldata(zksyncAddress, diamondProxyUpgradeCalldata); let result: any = { - stmScheduleTransparentOperation, - stmExecuteOperation, - scheduleTransparentOperation, - executeOperation, - newExecuteChainUpgradeCalldata, - diamondCut, - governanceOperation, - legacyScheduleOperation, - legacyExecuteOperation + stmUpgradeCalldata, + chainAdminUpgradeCalldata, + diamondCut }; if (prepareDirectOperation) { @@ -290,13 +225,9 @@ export function prepareTransparentUpgradeCalldataForNewGovernance( const stmDirecUpgradeCalldata = stm.interface.encodeFunctionData('executeUpgrade', [chainId, diamondCut]); - const { scheduleCalldata: stmScheduleOperationDirect, executeCalldata: stmExecuteOperationDirect } = - prepareGovernanceTxs(stmAddress, stmDirecUpgradeCalldata); - result = { ...result, - stmScheduleOperationDirect, - stmExecuteOperationDirect + stmDirecUpgradeCalldata }; } @@ -305,14 +236,10 @@ export function prepareTransparentUpgradeCalldataForNewGovernance( export function buildDefaultUpgradeTx( environment, - diamondUpgradeProposalId, upgradeAddress, - l2UpgraderAddress, oldProtocolVersion, oldProtocolVersionDeadline, upgradeTimestamp, - newAllowList, - stmAddress, zksyncAddress, postUpgradeCalldataFlag, prepareDirectOperation?, @@ -389,20 +316,18 @@ export function buildDefaultUpgradeTx( bootloaderHash, defaultAAHash, cryptoVerifierAddress, - newAllowList, l2UpgradeTx ); let l1upgradeCalldata = prepareDefaultCalldataForL1upgrade(proposeUpgradeTx); - let upgradeData = prepareTransparentUpgradeCalldataForNewGovernance( + let upgradeData = prepareUpgradeCalldata( oldProtocolVersion, oldProtocolVersionDeadline, packedNewProtocolVersion, l1upgradeCalldata, upgradeAddress, facetCuts, - stmAddress, zksyncAddress, prepareDirectOperation, chainId @@ -414,7 +339,6 @@ export function buildDefaultUpgradeTx( upgradeAddress, protocolVersionSemVer: newProtocolVersionSemVer, packedProtocolVersion: packedNewProtocolVersion, - diamondUpgradeProposalId, upgradeTimestamp, ...upgradeData }; @@ -423,31 +347,6 @@ export function buildDefaultUpgradeTx( console.log('Default upgrade transactions are generated'); } -async function sendTransaction( - calldata: BytesLike, - privateKey: string, - l1rpc: string, - to: string, - environment: string, - gasPrice: ethers.BigNumber, - nonce: number -) { - const wallet = getWallet(l1rpc, privateKey); - gasPrice = gasPrice ?? (await wallet.provider.getGasPrice()); - nonce = nonce ?? (await wallet.getTransactionCount()); - const tx = await wallet.sendTransaction({ - to, - data: calldata, - value: 0, - gasLimit: 10_000_000, - gasPrice, - nonce - }); - console.log('Transaction hash: ', tx.hash); - await tx.wait(); - console.log('Transaction is executed'); -} - export function getWallet(l1rpc, privateKey) { if (!l1rpc) { l1rpc = web3Url(); @@ -462,99 +361,6 @@ export function getWallet(l1rpc, privateKey) { ).connect(provider); } -async function sendPreparedTx( - privateKey: string, - l1rpc: string, - environment: string, - gasPrice: ethers.BigNumber, - nonce: number, - governanceAddr: string, - transactionsJsonField: string, - logText: string -) { - const transactions = JSON.parse(fs.readFileSync(getL2TransactionsFileName(environment)).toString()); - const calldata = transactions[transactionsJsonField]; - - console.log(`${logText} for protocolVersion ${transactions.protocolVersion}`); - await sendTransaction(calldata, privateKey, l1rpc, governanceAddr, environment, gasPrice, nonce); -} - -async function cancelUpgrade( - privateKey: string, - l1rpc: string, - zksyncAddress: string, - environment: string, - gasPrice: ethers.BigNumber, - nonce: number, - execute: boolean, - newGovernanceAddress: string -) { - if (newGovernanceAddress != null) { - let wallet = getWallet(l1rpc, privateKey); - const transactions = JSON.parse(fs.readFileSync(getL2TransactionsFileName(environment)).toString()); - - let governance = GovernanceFactory.connect(newGovernanceAddress, wallet); - const operation = transactions.governanceOperation; - - const operationId = await governance.hashOperation(operation); - - console.log(`Cancel upgrade operation with id: ${operationId}`); - if (execute) { - const tx = await governance.cancel(operationId); - await tx.wait(); - console.log('Operation canceled'); - } else { - const calldata = governance.interface.encodeFunctionData('cancel', [operationId]); - console.log(`Cancel upgrade calldata: ${calldata}`); - } - } else { - zksyncAddress = zksyncAddress ?? process.env.CONTRACTS_DIAMOND_PROXY_ADDR; - let wallet = getWallet(l1rpc, privateKey); - let zkSync = IZkSyncFactory.connect(zksyncAddress, wallet); - const transactions = JSON.parse(fs.readFileSync(getL2TransactionsFileName(environment)).toString()); - - const transparentUpgrade = transactions.transparentUpgrade; - const diamondUpgradeProposalId = transactions.diamondUpgradeProposalId; - - const proposalHash = await zkSync.upgradeProposalHash( - transparentUpgrade, - diamondUpgradeProposalId, - ethers.constants.HashZero - ); - - console.log(`Cancel upgrade with hash: ${proposalHash}`); - let cancelUpgradeCalldata = zkSync.interface.encodeFunctionData('cancelUpgradeProposal', [proposalHash]); - if (execute) { - await sendTransaction( - cancelUpgradeCalldata, - privateKey, - l1rpc, - zksyncAddress, - environment, - gasPrice, - nonce - ); - } else { - console.log(`Cancel upgrade calldata: ${cancelUpgradeCalldata}`); - } - } -} - -async function getNewDiamondUpgradeProposalId(l1rpc: string, zksyncAddress: string) { - zksyncAddress = zksyncAddress ?? process.env.CONTRACTS_DIAMOND_PROXY_ADDR; - // We don't care about the wallet here, we just need to make a get call. - let wallet = getWallet(l1rpc, undefined); - let zkSync = IZkSyncFactory.connect(zksyncAddress, wallet); - let proposalId = await zkSync.getCurrentProposalId(); - proposalId = proposalId.add(1); - console.log( - `New proposal id: ${proposalId} for ${zksyncAddress} network: ${JSON.stringify( - await wallet.provider.getNetwork() - )}` - ); - return proposalId; -} - export const command = new Command('transactions').description( 'prepare the transactions and their calldata for the upgrade' ); @@ -564,223 +370,23 @@ command .requiredOption('--upgrade-timestamp ') .option('--upgrade-address ') .option('--environment ') - .option('--new-allow-list ') - .option('--l2-upgrader-address ') - .option('--diamond-upgrade-proposal-id ') .option('--old-protocol-version ') .option('--old-protocol-version-deadline ') .option('--l1rpc ') .option('--zksync-address ') - .option('--state-transition-manager-address ') .option('--chain-id ') .option('--prepare-direct-operation ') - .option('--use-new-governance') .option('--post-upgrade-calldata') .action(async (options) => { - if (!options.useNewGovernance) { - // TODO(X): remove old governance functionality from the protocol upgrade tool - throw new Error('Old governance is not supported anymore'); - } - - let diamondUpgradeProposalId = options.diamondUpgradeProposalId; - if (!diamondUpgradeProposalId && !options.useNewGovernance) { - diamondUpgradeProposalId = await getNewDiamondUpgradeProposalId(options.l1rpc, options.zksyncAddress); - } - buildDefaultUpgradeTx( options.environment, - diamondUpgradeProposalId, options.upgradeAddress, - options.l2UpgraderAddress, options.oldProtocolVersion, options.oldProtocolVersionDeadline, options.upgradeTimestamp, - options.newAllowList, - options.stateTransitionManagerAddress, options.zksyncAddress, options.postUpgradeCalldata, options.prepareDirectOperation, options.chainId ); }); - -command - .command('propose-upgrade-stm') - .option('--environment ') - .option('--private-key ') - .option('--gas-price ') - .option('--nonce ') - .option('--l1rpc ') - .option('--governance-addr ') - .action(async (options) => { - if (!options.governanceAddr) { - throw new Error('Governance address must be provided'); - } - - await sendPreparedTx( - options.privateKey, - options.l1rpc, - options.environment, - options.gasPrice, - options.nonce, - options.governanceAddr, - 'stmScheduleTransparentOperation', - 'Proposing upgrade for STM' - ); - }); - -command - .command('execute-upgrade-stm') - .option('--environment ') - .option('--private-key ') - .option('--gas-price ') - .option('--nonce ') - .option('--l1rpc ') - .option('--governance-addr ') - .action(async (options) => { - if (!options.governanceAddr) { - throw new Error('Governance address must be provided'); - } - - await sendPreparedTx( - options.privateKey, - options.l1rpc, - options.environment, - options.gasPrice, - options.nonce, - options.governanceAddr, - 'stmExecuteOperation', - 'Executing upgrade for STM' - ); - }); - -command - .command('propose-upgrade') - .option('--environment ') - .option('--private-key ') - .option('--zksync-address ') - .option('--gas-price ') - .option('--nonce ') - .option('--l1rpc ') - .option('--governance-addr ') - .action(async (options) => { - if (!options.governanceAddr) { - throw new Error('Governance address must be provided'); - } - - await sendPreparedTx( - options.privateKey, - options.l1rpc, - options.environment, - options.gasPrice, - options.nonce, - options.governanceAddr, - 'scheduleTransparentOperation', - 'Proposing "upgradeChainFromVersion" upgrade' - ); - }); - -command - .command('execute-upgrade') - .option('--environment ') - .option('--private-key ') - .option('--zksync-address ') - .option('--gas-price ') - .option('--nonce ') - .option('--l1rpc ') - .option('--governance-addr ') - .action(async (options) => { - if (!options.governanceAddr) { - throw new Error('Governance address must be provided'); - } - - await sendPreparedTx( - options.privateKey, - options.l1rpc, - options.environment, - options.gasPrice, - options.nonce, - options.governanceAddr, - 'executeOperation', - 'Executing "upgradeChainFromVersion" upgrade' - ); - }); - -command - .command('propose-upgrade-direct') - .option('--environment ') - .option('--private-key ') - .option('--zksync-address ') - .option('--gas-price ') - .option('--nonce ') - .option('--l1rpc ') - .option('--governance-addr ') - .action(async (options) => { - if (!options.governanceAddr) { - throw new Error('Governance address must be provided'); - } - - await sendPreparedTx( - options.privateKey, - options.l1rpc, - options.environment, - options.gasPrice, - options.nonce, - options.governanceAddr, - 'stmScheduleOperationDirect', - 'Executing direct upgrade via STM' - ); - }); - -command - .command('execute-upgrade-direct') - .option('--environment ') - .option('--private-key ') - .option('--zksync-address ') - .option('--gas-price ') - .option('--nonce ') - .option('--l1rpc ') - .option('--governance-addr ') - .action(async (options) => { - if (!options.governanceAddr) { - throw new Error('Governance address must be provided'); - } - - await sendPreparedTx( - options.privateKey, - options.l1rpc, - options.environment, - options.gasPrice, - options.nonce, - options.governanceAddr, - 'stmExecuteOperationDirect', - 'Executing direct upgrade via STM' - ); - }); - -command - .command('cancel-upgrade') - .option('--environment ') - .option('--private-key ') - .option('--zksync-address ') - .option('--gas-price ') - .option('--nonce ') - .option('--l1rpc ') - .option('--execute') - .option('--governance-addr ') - .action(async (options) => { - if (!options.governanceAddr) { - throw new Error('Governance address must be provided'); - } - - await cancelUpgrade( - options.privateKey, - options.l1rpc, - options.zksyncAddress, - options.environment, - options.gasPrice, - options.nonce, - options.execute, - options.newGovernance - ); - });