diff --git a/contracts/v2/consensus/pessimistic/PolygonPessimisticConsensus.sol b/contracts/v2/consensus/pessimistic/PolygonPessimisticConsensus.sol index f847d3c05..cc2d59525 100644 --- a/contracts/v2/consensus/pessimistic/PolygonPessimisticConsensus.sol +++ b/contracts/v2/consensus/pessimistic/PolygonPessimisticConsensus.sol @@ -14,7 +14,7 @@ contract PolygonPessimisticConsensus is * @param _globalExitRootManager Global exit root manager address * @param _pol POL token address * @param _bridgeAddress Bridge address - * @param _rollupManager Global exit root manager address + * @param _rollupManager Rollup manager address */ constructor( IPolygonZkEVMGlobalExitRootV2 _globalExitRootManager, diff --git a/tools/addRollupType/addRollupType.ts b/tools/addRollupType/addRollupType.ts index 25584a6e0..e60eae20a 100644 --- a/tools/addRollupType/addRollupType.ts +++ b/tools/addRollupType/addRollupType.ts @@ -6,16 +6,19 @@ import fs = require("fs"); import * as dotenv from "dotenv"; dotenv.config({path: path.resolve(__dirname, "../../.env")}); -import {ethers, upgrades} from "hardhat"; +import {ethers, run} from "hardhat"; const addRollupTypeParameters = require("./add_rollup_type.json"); const genesis = require("./genesis.json"); const dateStr = new Date().toISOString(); -const pathOutputJson = path.join(__dirname, `./add_rollup_type_output-${dateStr}.json`); +const pathOutputJson = addRollupTypeParameters.outputPath + ? path.join(__dirname, addRollupTypeParameters.outputPath) + : path.join(__dirname, `./add_rollup_type_output-${dateStr}.json`);; import {PolygonRollupManager} from "../../typechain-types"; import "../../deployment/helpers/utils"; +import {supportedBridgeContracts} from "../utils"; async function main() { const outputJson = {} as any; @@ -82,7 +85,8 @@ async function main() { return new ethers.FeeData( null, ((feedata.maxFeePerGas as bigint) * BigInt(addRollupTypeParameters.multiplierGas)) / 1000n, - ((feedata.maxPriorityFeePerGas as bigint) * BigInt(addRollupTypeParameters.multiplierGas)) / 1000n + ((feedata.maxPriorityFeePerGas as bigint) * BigInt(addRollupTypeParameters.multiplierGas)) / + 1000n ); } currentProvider.getFeeData = overrideFeeData; @@ -125,16 +129,18 @@ async function main() { // get bridge address in genesis file let genesisBridgeAddress = ethers.ZeroAddress; + let bridgeContractName = ""; for (let i = 0; i < genesis.genesis.length; i++) { - if (genesis.genesis[i].contractName === "PolygonZkEVMBridgeV2 proxy") { + if (supportedBridgeContracts.includes(genesis.genesis[i].contractName)) { genesisBridgeAddress = genesis.genesis[i].address; + bridgeContractName = genesis.genesis[i].contractName; break; } } if (polygonZkEVMBridgeAddress.toLowerCase() !== genesisBridgeAddress.toLowerCase()) { throw new Error( - `'PolygonZkEVMBridgeV2 proxy' root in the 'genesis.json' does not match 'bridgeAddress' in the 'PolygonRollupManager'` + `'${bridgeContractName}' root in the 'genesis.json' does not match 'bridgeAddress' in the 'PolygonRollupManager'` ); } } @@ -173,22 +179,34 @@ async function main() { polygonRollupManagerAddress ); await PolygonConsensusContract.waitForDeployment(); - console.log("#######################\n"); console.log(`new consensus name: ${consensusContract}`); console.log(`new PolygonConsensusContract impl: ${PolygonConsensusContract.target}`); - console.log("you can verify the new impl address with:"); - console.log( - `npx hardhat verify --constructor-args upgrade/arguments.js ${PolygonConsensusContract.target} --network ${process.env.HARDHAT_NETWORK}\n` - ); - console.log("Copy the following constructor arguments on: upgrade/arguments.js \n", [ - polygonZkEVMGlobalExitRootAddress, - polTokenAddress, - polygonZkEVMBridgeAddress, - polygonRollupManagerAddress, - ]); - + try { + console.log("Verifying contract..."); + await run("verify:verify", { + address: PolygonConsensusContract.target, + constructorArguments: [ + polygonZkEVMGlobalExitRootAddress, + polTokenAddress, + polygonZkEVMBridgeAddress, + polygonRollupManagerAddress, + ], + }); + } catch (e) { + console.log("Automatic verification failed. Please verify the contract manually."); + console.log("you can verify the new impl address with:"); + console.log( + `npx hardhat verify --constructor-args upgrade/arguments.js ${PolygonConsensusContract.target} --network ${process.env.HARDHAT_NETWORK}\n` + ); + console.log("Copy the following constructor arguments on: upgrade/arguments.js \n", [ + polygonZkEVMGlobalExitRootAddress, + polTokenAddress, + polygonZkEVMBridgeAddress, + polygonRollupManagerAddress, + ]); + } consensusContractAddress = PolygonConsensusContract.target; } diff --git a/tools/addRollupType/addRollupTypeTimelock.ts b/tools/addRollupType/addRollupTypeTimelock.ts index 073afba3c..bfc9a27da 100644 --- a/tools/addRollupType/addRollupTypeTimelock.ts +++ b/tools/addRollupType/addRollupTypeTimelock.ts @@ -8,12 +8,13 @@ import * as dotenv from "dotenv"; dotenv.config({path: path.resolve(__dirname, "../../.env")}); import {ethers, upgrades} from "hardhat"; -const addRollupParameters = require("./add_rollup_type.json"); +const addRollupTypeParameters = require("./add_rollup_type.json"); const genesis = require("./genesis.json"); const dateStr = new Date().toISOString(); -const pathOutputJson = path.join(__dirname, `./add_rollup_type_output-${dateStr}.json`); -import {PolygonRollupManager} from "../../typechain-types"; +const pathOutputJson = addRollupTypeParameters.outputPath + ? path.join(__dirname, addRollupTypeParameters.outputPath) + : path.join(__dirname, `./add_rollup_type_output-${dateStr}.json`); import "../../deployment/helpers/utils"; async function main() { @@ -34,7 +35,7 @@ async function main() { ]; for (const parameterName of mandatoryDeploymentParameters) { - if (addRollupParameters[parameterName] === undefined || addRollupParameters[parameterName] === "") { + if (addRollupTypeParameters[parameterName] === undefined || addRollupTypeParameters[parameterName] === "") { throw new Error(`Missing parameter: ${parameterName}`); } } @@ -48,10 +49,10 @@ async function main() { timelockDelay, genesisRoot, programVKey, - } = addRollupParameters; + } = addRollupTypeParameters; - const salt = addRollupParameters.timelockSalt || ethers.ZeroHash; - const predecessor = addRollupParameters.predecessor || ethers.ZeroHash; + const salt = addRollupTypeParameters.timelockSalt || ethers.ZeroHash; + const predecessor = addRollupTypeParameters.predecessor || ethers.ZeroHash; const supportedConsensus = [ "PolygonZkEVMEtrog", @@ -67,30 +68,30 @@ async function main() { // Load provider let currentProvider = ethers.provider; - if (addRollupParameters.multiplierGas || addRollupParameters.maxFeePerGas) { + if (addRollupTypeParameters.multiplierGas || addRollupTypeParameters.maxFeePerGas) { if (process.env.HARDHAT_NETWORK !== "hardhat") { currentProvider = ethers.getDefaultProvider( `https://${process.env.HARDHAT_NETWORK}.infura.io/v3/${process.env.INFURA_PROJECT_ID}` ) as any; - if (addRollupParameters.maxPriorityFeePerGas && addRollupParameters.maxFeePerGas) { + if (addRollupTypeParameters.maxPriorityFeePerGas && addRollupTypeParameters.maxFeePerGas) { console.log( - `Hardcoded gas used: MaxPriority${addRollupParameters.maxPriorityFeePerGas} gwei, MaxFee${addRollupParameters.maxFeePerGas} gwei` + `Hardcoded gas used: MaxPriority${addRollupTypeParameters.maxPriorityFeePerGas} gwei, MaxFee${addRollupTypeParameters.maxFeePerGas} gwei` ); const FEE_DATA = new ethers.FeeData( null, - ethers.parseUnits(addRollupParameters.maxFeePerGas, "gwei"), - ethers.parseUnits(addRollupParameters.maxPriorityFeePerGas, "gwei") + ethers.parseUnits(addRollupTypeParameters.maxFeePerGas, "gwei"), + ethers.parseUnits(addRollupTypeParameters.maxPriorityFeePerGas, "gwei") ); currentProvider.getFeeData = async () => FEE_DATA; } else { - console.log("Multiplier gas used: ", addRollupParameters.multiplierGas); + console.log("Multiplier gas used: ", addRollupTypeParameters.multiplierGas); async function overrideFeeData() { const feeData = await ethers.provider.getFeeData(); return new ethers.FeeData( null, - ((feeData.maxFeePerGas as bigint) * BigInt(addRollupParameters.multiplierGas)) / 1000n, - ((feeData.maxPriorityFeePerGas as bigint) * BigInt(addRollupParameters.multiplierGas)) / 1000n + ((feeData.maxFeePerGas as bigint) * BigInt(addRollupTypeParameters.multiplierGas)) / 1000n, + ((feeData.maxPriorityFeePerGas as bigint) * BigInt(addRollupTypeParameters.multiplierGas)) / 1000n ); } currentProvider.getFeeData = overrideFeeData; @@ -100,8 +101,8 @@ async function main() { // Load deployer let deployer; - if (addRollupParameters.deployerPvtKey) { - deployer = new ethers.Wallet(addRollupParameters.deployerPvtKey, currentProvider); + if (addRollupTypeParameters.deployerPvtKey) { + deployer = new ethers.Wallet(addRollupTypeParameters.deployerPvtKey, currentProvider); } else if (process.env.MNEMONIC) { deployer = ethers.HDNodeWallet.fromMnemonic( ethers.Mnemonic.fromPhrase(process.env.MNEMONIC), @@ -153,10 +154,10 @@ async function main() { let PolygonConsensusContractAddress; if ( - typeof addRollupParameters.consensusContractAddress !== "undefined" && - ethers.isAddress(addRollupParameters.consensusContractAddress) + typeof addRollupTypeParameters.consensusContractAddress !== "undefined" && + ethers.isAddress(addRollupTypeParameters.consensusContractAddress) ) { - PolygonConsensusContractAddress = addRollupParameters.consensusContractAddress; + PolygonConsensusContractAddress = addRollupTypeParameters.consensusContractAddress; } else { PolygonConsensusContract = await PolygonConsensusFactory.deploy( polygonZkEVMGlobalExitRootAddress, diff --git a/tools/createNewRollup/createNewRollup.ts b/tools/createNewRollup/createNewRollup.ts index e07fb4ab2..82d73e45c 100644 --- a/tools/createNewRollup/createNewRollup.ts +++ b/tools/createNewRollup/createNewRollup.ts @@ -23,11 +23,10 @@ import { async function main() { console.log(`Starting script to create new rollup from ${createRollupParameters.type}...`); const outputJson = {} as any; + const dateStr = new Date().toISOString(); const destPath = createRollupParameters.outputPath - ? createRollupParameters.outputPath - : `./outputs/create_new_rollup_output_${createRollupParameters.type}_${Math.floor( - new Date().getTime() / 1000 - )}.json`; + ? path.join(__dirname, createRollupParameters.outputPath) + : `./outputs/create_new_rollup_output_${createRollupParameters.type}_${dateStr}.json`; /* * Check deploy parameters @@ -105,14 +104,25 @@ async function main() { } } // Vanilla checks like in bridge contract - if(ethers.isAddress(createRollupParameters.gasTokenAddress) && - createRollupParameters.gasTokenAddress !== ethers.ZeroAddress && - sovereignParams.sovereignWETHAddress === ethers.ZeroAddress && sovereignParams.sovereignWETHAddressIsNotMintable === true) { - throw new Error("InvalidSovereignWETHAddressParams: if gasTokenAddress is not 0x0, and sovereignWETHAddress is 0x0, sovereignWETHAddressIsNotMintable must be false"); + if ( + ethers.isAddress(createRollupParameters.gasTokenAddress) && + createRollupParameters.gasTokenAddress !== ethers.ZeroAddress && + sovereignParams.sovereignWETHAddress === ethers.ZeroAddress && + sovereignParams.sovereignWETHAddressIsNotMintable === true + ) { + throw new Error( + "InvalidSovereignWETHAddressParams: if gasTokenAddress is not 0x0, and sovereignWETHAddress is 0x0, sovereignWETHAddressIsNotMintable must be false" + ); } - if(createRollupParameters.gasTokenAddress === ethers.ZeroAddress && (sovereignParams.sovereignWETHAddress !== ethers.ZeroAddress || sovereignParams.sovereignWETHAddressIsNotMintable === true)) { - throw new Error("InvalidSovereignWETHAddressParams: If gasTokenAddress is 0x0, sovereignWETHAddress must be 0x0 and sovereignWETHAddressIsNotMintable must be false"); + if ( + createRollupParameters.gasTokenAddress === ethers.ZeroAddress && + (sovereignParams.sovereignWETHAddress !== ethers.ZeroAddress || + sovereignParams.sovereignWETHAddressIsNotMintable === true) + ) { + throw new Error( + "InvalidSovereignWETHAddressParams: If gasTokenAddress is 0x0, sovereignWETHAddress must be 0x0 and sovereignWETHAddressIsNotMintable must be false" + ); } } @@ -542,7 +552,7 @@ async function main() { outputJson.firstBatchData = batchData; outputJson.rollupID = Number(rollupID); - fs.writeFileSync(path.join(__dirname, destPath), JSON.stringify(outputJson, null, 1)); + fs.writeFileSync(destPath, JSON.stringify(outputJson, null, 1)); console.log("Finished script, output saved at: ", destPath); } diff --git a/tools/utils.js b/tools/utils.js index 6d03168f2..69766503b 100644 --- a/tools/utils.js +++ b/tools/utils.js @@ -2,6 +2,7 @@ /* eslint-disable no-restricted-syntax */ const ethers = require('ethers'); +const supportedBridgeContracts = ['PolygonZkEVMBridgeV2 proxy', 'PolygonZkEVMBridge proxy', 'BridgeL2SovereignChain proxy']; function genOperation(target, value, data, predecessor, salt) { const abiEncoded = ethers.AbiCoder.defaultAbiCoder().encode( ['address', 'uint256', 'bytes', 'uint256', 'bytes32'], @@ -50,5 +51,6 @@ function convertBigIntsToNumbers(obj) { module.exports = { genOperation, createNewRollupTypes, - convertBigIntsToNumbers + convertBigIntsToNumbers, + supportedBridgeContracts, };