Skip to content

Commit

Permalink
add support for forkID in the tool 'deployVerifier'
Browse files Browse the repository at this point in the history
addRollupType tool improvement

PR review 1

genesis

update verifier deployment
  • Loading branch information
krlosMata authored and invocamanman committed Jul 22, 2024
1 parent 9094f21 commit e307104
Show file tree
Hide file tree
Showing 23 changed files with 13,592 additions and 10,977 deletions.
3,920 changes: 1,960 additions & 1,960 deletions compiled-contracts/PolygonRollupManager.json

Large diffs are not rendered by default.

4,022 changes: 2,011 additions & 2,011 deletions compiled-contracts/PolygonRollupManagerMock.json

Large diffs are not rendered by default.

4,036 changes: 2,018 additions & 2,018 deletions compiled-contracts/PolygonRollupManagerMockInternalTest.json

Large diffs are not rendered by default.

2,642 changes: 1,321 additions & 1,321 deletions compiled-contracts/PolygonValidiumEtrog.json

Large diffs are not rendered by default.

2,358 changes: 1,179 additions & 1,179 deletions compiled-contracts/PolygonZkEVMEtrog.json

Large diffs are not rendered by default.

2,280 changes: 1,140 additions & 1,140 deletions compiled-contracts/PolygonZkEVMEtrogPrevious.json

Large diffs are not rendered by default.

2,480 changes: 1,240 additions & 1,240 deletions compiled-contracts/PolygonZkEVMExistentEtrog.json

Large diffs are not rendered by default.

1,244 changes: 1,244 additions & 0 deletions contracts/verifiers/FflonkVerifier_10.sol

Large diffs are not rendered by default.

1,244 changes: 1,244 additions & 0 deletions contracts/verifiers/FflonkVerifier_11.sol

Large diffs are not rendered by default.

9 changes: 8 additions & 1 deletion deployment/v2/4_createRollup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,14 @@ async function main() {

let verifierContract;
if (realVerifier === true) {
const VerifierRollup = await ethers.getContractFactory("FflonkVerifier", deployer);
let verifierName;
if (forkID > 9) {
verifierName = `FflonkVerifier_${forkID}`;
} else {
verifierName = "FflonkVerifier";
}

const VerifierRollup = await ethers.getContractFactory(verifierName, deployer);
verifierContract = await VerifierRollup.deploy();
await verifierContract.waitForDeployment();
} else {
Expand Down
2 changes: 1 addition & 1 deletion deployment/v2/create_rollup_parameters.json.example
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"trustedSequencer":"0x617b3a3528F9cDd6630fd3301B9c8911F7Bf063D",
"chainID": 1001,
"adminZkEVM":"0x617b3a3528F9cDd6630fd3301B9c8911F7Bf063D",
"forkID": 8,
"forkID": 11,
"consensusContract": "PolygonZkEVMEtrog",
"gasTokenAddress":"",
"deployerPvtKey": "",
Expand Down
2 changes: 2 additions & 0 deletions tools/addRollupType/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
add_rollup_type_output.json
genesis.json
69 changes: 69 additions & 0 deletions tools/addRollupType/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
# Add Rollup Type
Script to call `addNewRollupType` function with no timelock involved

## Install
```
npm i
```

## Setup
- Config file
- `consensusContract`: select between consensus contract. Supprted: `["PolygonZkEVMEtrog", "PolygonValidiumEtrog"]`
- `polygonRollupManagerAddress`: polygonRollupManager smart contract address
- `verifierAddress`: verifier to be used
- `description`: string to describe rollup type added. Example: "Type: Validium, Version: etrog, genesis: /ipfs/QmUXnRoPbUmZuEZCGyiHjEsoNcFVu3hLtSvhpnfBS2mAYU"
- `forkID`: forkID to be used
- `rollupCompatibilityID`: rollup compatibility ID
- `timelockDelay`: timelock delay
- `timelockSalt(optional)`: timelock salt
- `predecessor(optional)`: timelock predecessor
- `deployerPvtKey(optional)`: private key deployer
- First option will load `deployerPvtKey`. Otherwise, `process.env.MNEMONIC` will be loaded from the `.env` file
- `maxFeePerGas(optional)`: string, Set `maxFeePerGas`, must define aswell `maxPriorityFeePerGas` to use it
- `maxPriorityFeePerGas(optional)`: string, Set `maxPriorityFeePerGas`, must define aswell `maxFeePerGas` to use it
- `multiplierGas(optional)`: number, Gas multiplier with 3 decimals. If `maxFeePerGas` and `maxPriorityFeePerGas` are set, this will not take effect
- A network should be selected when running the script
- examples: `-- sepolia` or `--mainnet`
- This uses variables set in `hardhat.config.ts`
- Which uses some environment variables that should be set in `.env`
> All paths are from root repository
## Usage
> All commands are done from root repository.
### Call 'addNewRollupType' from an EOA

- Copy configuration files:
```
cp ./tools/addRollupType/add_rollup_type.json.example ./tools/addRollupType/add_rollup_type.json
```

```
cp ./tools/addRollupType/genesis.json.example ./tools/addRollupType/genesis.json
```

- Set your parameters
- Run tool:
```
npx hardhat run ./tools/addRollupType/addRollupType.ts --network sepolia
```

### Generate 'addNewRollupType' to the Timelock SC

- Copy configuration file:
```
cp ./tools/addRollupType/add_rollup_type.json.example ./tools/addRollupType/add_rollup_type.json
```

- Set your parameters
- Run tool:
```
npx hardhat run ./tools/addRollupType/addRollupType.ts --network sepolia
```
- Output:
- scheduleData
- executeData
> send data to the timelock contract address:
> - use your favourite browser extension
> - send tx to timelock address with hex data as `scheduleData`
> - wait timelockDelay and then send `executeData` to timelock address
95 changes: 65 additions & 30 deletions tools/addRollupType/addRollupType.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ import {ethers, upgrades} from "hardhat";
const addRollupParameters = require("./add_rollup_type.json");
const genesis = require("./genesis.json");

const pathOutputJson = path.join(__dirname, "./add_rollup_type_output.json");
const dateStr = new Date().toISOString();
const pathOutputJson = path.join(__dirname, `./add_rollup_type_output-${dateStr}.json`);

import {PolygonRollupManager} from "../../typechain-types";
import "../../deployment/helpers/utils";
Expand All @@ -28,11 +29,9 @@ async function main() {
"forkID",
"consensusContract",
"polygonRollupManagerAddress",
"polygonZkEVMBridgeAddress",
"polygonZkEVMGlobalExitRootAddress",
"polTokenAddress",
"verifierAddress",
"rollupCompatibilityID",
"genesisRoot"
];

for (const parameterName of mandatoryDeploymentParameters) {
Expand All @@ -47,10 +46,8 @@ async function main() {
forkID,
consensusContract,
polygonRollupManagerAddress,
polygonZkEVMBridgeAddress,
polygonZkEVMGlobalExitRootAddress,
polTokenAddress,
verifierAddress,
genesisRoot
} = addRollupParameters;

const supportedConensus = ["PolygonZkEVMEtrog", "PolygonValidiumEtrog"];
Expand Down Expand Up @@ -113,6 +110,34 @@ async function main() {
polygonRollupManagerAddress
) as PolygonRollupManager;

// get data from rollupManagerContract
const polygonZkEVMBridgeAddress = await rollupManagerContract.bridgeAddress();
const polygonZkEVMGlobalExitRootAddress = await rollupManagerContract.globalExitRootManager();
const polTokenAddress = await rollupManagerContract.pol();

// Sanity checks genesisRoot
if (genesisRoot !== genesis.root) {
throw new Error(
`Genesis root in the 'add_rollup_type.json' does not match the root in the 'genesis.json'`
);
}

// get bridge address in genesis file
let genesisBridgeAddress = ethers.constants.AddresZero;
for (let i = 0; i < genesis.genesis.lenght; i++) {
if (genesis.genesis[i].contractName === 'PolygonZkEVMBridge proxy') {
genesisBridgeAddress = genesis.genesis[i].address;
break;
}
}

if (polygonZkEVMBridgeAddress.toLowerCase() !== genesisBridgeAddress ) {
throw new Error(
`'PolygonZkEVMBridge proxy' root in the 'genesis.json' does not match 'bridgeAddress' in the 'PolygonRollupManager'`
);
}

// Check roles
const DEFAULT_ADMIN_ROLE = ethers.ZeroHash;
if ((await rollupManagerContract.hasRole(DEFAULT_ADMIN_ROLE, deployer.address)) == false) {
throw new Error(
Expand All @@ -127,37 +152,45 @@ async function main() {
if ((await rollupManagerContract.hasRole(ADD_ROLLUP_TYPE_ROLE, deployer.address)) == false)
await rollupManagerContract.grantRole(ADD_ROLLUP_TYPE_ROLE, deployer.address);

// Create consensus implementation
const PolygonconsensusFactory = (await ethers.getContractFactory(consensusContract, deployer)) as any;
let PolygonconsensusContract;
// Create consensus implementation if needed
let polygonConsensusContractAddress;

PolygonconsensusContract = await PolygonconsensusFactory.deploy(
polygonZkEVMGlobalExitRootAddress,
polTokenAddress,
polygonZkEVMBridgeAddress,
polygonRollupManagerAddress
);
await PolygonconsensusContract.waitForDeployment();
if (typeof addRollupParameters.polygonconsensusContract !== 'undefined' && ethers.isAddress(addRollupParameters.polygonconsensusContract)) {
polygonConsensusContractAddress = addRollupParameters.polygonconsensusContract;
} else {
const PolygonconsensusFactory = (await ethers.getContractFactory(consensusContract, deployer)) as any;
let PolygonconsensusContract;

PolygonconsensusContract = await PolygonconsensusFactory.deploy(
polygonZkEVMGlobalExitRootAddress,
polTokenAddress,
polygonZkEVMBridgeAddress,
polygonRollupManagerAddress
);
await PolygonconsensusContract.waitForDeployment();

console.log("#######################\n");
console.log(`new PolygonconsensusContract impl: ${PolygonconsensusContract.target}`);
console.log("#######################\n");
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,
]);
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,
]);

polygonConsensusContractAddress = PolygonconsensusContract.target;
}

// Add a new rollup type with timelock
console.log(
await (
await rollupManagerContract.addNewRollupType(
PolygonconsensusContract.target,
polygonConsensusContractAddress,
verifierAddress,
forkID,
rollupCompatibilityID,
Expand All @@ -176,6 +209,8 @@ async function main() {
outputJson.consensusContract = consensusContract;
outputJson.rollupTypeID = newRollupTypeID;

// add time to output path
const dateStr = new Date().toISOString();
fs.writeFileSync(pathOutputJson, JSON.stringify(outputJson, null, 1));
}

Expand Down
42 changes: 35 additions & 7 deletions tools/addRollupType/addRollupTypeTimelock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ import {ethers, upgrades} from "hardhat";
const addRollupParameters = require("./add_rollup_type.json");
const genesis = require("./genesis.json");

const pathOutputJson = path.join(__dirname, "./add_rollup_type_output.json");
const dateStr = new Date().toISOString();
const pathOutputJson = path.join(__dirname, `./add_rollup_type_output-${dateStr}.json`);
import {PolygonRollupManager} from "../../typechain-types";
import "../../deployment/helpers/utils";

async function main() {
Expand All @@ -25,13 +27,11 @@ async function main() {
"description",
"forkID",
"consensusContract",
"polygonRollupManagerAddress",
"polygonZkEVMBridgeAddress",
"polygonZkEVMGlobalExitRootAddress",
"polTokenAddress",
"verifierAddress",
"rollupCompatibilityID",
"timelockDelay",
"genesisRoot"
];

for (const parameterName of mandatoryDeploymentParameters) {
Expand All @@ -46,11 +46,9 @@ async function main() {
forkID,
consensusContract,
polygonRollupManagerAddress,
polygonZkEVMBridgeAddress,
polygonZkEVMGlobalExitRootAddress,
polTokenAddress,
verifierAddress,
timelockDelay,
genesisRoot
} = addRollupParameters;

const salt = addRollupParameters.timelockSalt || ethers.ZeroHash;
Expand Down Expand Up @@ -112,6 +110,36 @@ async function main() {

// Load Rollup manager
const PolgonRollupManagerFactory = await ethers.getContractFactory("PolygonRollupManager", deployer);
const rollupManagerContract = PolgonRollupManagerFactory.attach(
polygonRollupManagerAddress
) as PolygonRollupManager;

// get data from rollupManagerContract
const polygonZkEVMBridgeAddress = await rollupManagerContract.bridgeAddress();
const polygonZkEVMGlobalExitRootAddress = await rollupManagerContract.globalExitRootManager();
const polTokenAddress = await rollupManagerContract.pol();

// Sanity checks genesisRoot
if (genesisRoot !== genesis.root) {
throw new Error(
`Genesis root in the 'add_rollup_type.json' does not match the root in the 'genesis.json'`
);
}

// get bridge address in genesis file
let genesisBridgeAddress = ethers.constants.AddresZero;
for (let i = 0; i < genesis.genesis.lenght; i++) {
if (genesis.genesis[i].contractName === 'PolygonZkEVMBridge proxy') {
genesisBridgeAddress = genesis.genesis[i].address;
break;
}
}

if (polygonZkEVMBridgeAddress.toLowerCase() !== genesisBridgeAddress ) {
throw new Error(
`'PolygonZkEVMBridge proxy' root in the 'genesis.json' does not match 'bridgeAddress' in the 'PolygonRollupManager'`
);
}

// Create consensus implementation
const PolygonconsensusFactory = (await ethers.getContractFactory(consensusContract, deployer)) as any;
Expand Down
6 changes: 2 additions & 4 deletions tools/addRollupType/add_rollup_type.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
{
"consensusContract": "PolygonZkEVMEtrog",
"polygonRollupManagerAddress": "0x5132A183E9F3CB7C848b0AAC5Ae0c4f0491B7aB2",
"polygonZkEVMBridgeAddress": "0x2a3DD3EB832aF982ec71669E178424b10Dca2EDe",
"polygonZkEVMGlobalExitRootAddress": "0x580bda1e7A0CFAe92Fa7F6c20A3794F169CE3CFb",
"polTokenAddress": "0x455e53CBB86018Ac2B8092FdCd39d8444aFFC3F6",
"verifierAddress": "0x0775e11309d75aA6b0967917fB0213C5673eDf81",
"description": "Type: zkEVM, Version: eldelberry2, genesis: /ipfs/QmUXnRoPbUmZuEZCGyiHjEsoNcFVu3hLtSvhpnfBS2mAYU",
"forkID": 9,
Expand All @@ -15,5 +12,6 @@
"deployerPvtKey": "",
"maxFeePerGas": "",
"maxPriorityFeePerGas": "",
"multiplierGas": ""
"multiplierGas": "",
"genesisRoot": "0xe3a7d8bae497945ba8ddc51c69564f60ad4c1a990b9c7bdbd27f7929bfa8f272"
}
6 changes: 2 additions & 4 deletions tools/addRollupType/add_rollup_type.json.example
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
{
"consensusContract": "PolygonValidiumEtrog",
"polygonRollupManagerAddress": "0x5132A183E9F3CB7C848b0AAC5Ae0c4f0491B7aB2",
"polygonZkEVMBridgeAddress": "0x2a3DD3EB832aF982ec71669E178424b10Dca2EDe",
"polygonZkEVMGlobalExitRootAddress": "0x580bda1e7A0CFAe92Fa7F6c20A3794F169CE3CFb",
"polTokenAddress": "0x455e53CBB86018Ac2B8092FdCd39d8444aFFC3F6",
"verifierAddress": "0x1C3A3da552b8662CD69538356b1E7c2E9CC1EBD8",
"description": "Type: Validium, Version: etrog, genesis: /ipfs/QmUXnRoPbUmZuEZCGyiHjEsoNcFVu3hLtSvhpnfBS2mAYU",
"forkID": 7,
Expand All @@ -13,5 +10,6 @@
"deployerPvtKey": "",
"maxFeePerGas":"",
"maxPriorityFeePerGas":"",
"multiplierGas": ""
"multiplierGas": "",
"genesisRoot": "0xe3a7d8bae497945ba8ddc51c69564f60ad4c1a990b9c7bdbd27f7929bfa8f272"
}
File renamed without changes.
Loading

0 comments on commit e307104

Please sign in to comment.