Skip to content

Commit

Permalink
More review remediations
Browse files Browse the repository at this point in the history
  • Loading branch information
ignasirv committed Dec 2, 2024
1 parent 497d739 commit 6d4fc97
Show file tree
Hide file tree
Showing 5 changed files with 79 additions and 48 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
52 changes: 35 additions & 17 deletions tools/addRollupType/addRollupType.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
? 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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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'`
);
}
}
Expand Down Expand Up @@ -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;
}

Expand Down
41 changes: 21 additions & 20 deletions tools/addRollupType/addRollupTypeTimelock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
? addRollupTypeParameters.outputPath
: path.join(__dirname, `./add_rollup_type_output-${dateStr}.json`);
import "../../deployment/helpers/utils";

async function main() {
Expand All @@ -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}`);
}
}
Expand All @@ -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",
Expand All @@ -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;
Expand All @@ -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),
Expand Down Expand Up @@ -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,
Expand Down
28 changes: 19 additions & 9 deletions tools/createNewRollup/createNewRollup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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`;
: `./outputs/create_new_rollup_output_${createRollupParameters.type}_${dateStr}.json`;

/*
* Check deploy parameters
Expand Down Expand Up @@ -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"
);
}
}

Expand Down
4 changes: 3 additions & 1 deletion tools/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'],
Expand Down Expand Up @@ -50,5 +51,6 @@ function convertBigIntsToNumbers(obj) {
module.exports = {
genOperation,
createNewRollupTypes,
convertBigIntsToNumbers
convertBigIntsToNumbers,
supportedBridgeContracts,
};

0 comments on commit 6d4fc97

Please sign in to comment.