Skip to content

Commit

Permalink
set verifiers forkID & add README in updateRollup tool
Browse files Browse the repository at this point in the history
  • Loading branch information
krlosMata committed Sep 10, 2024
1 parent 3f5d847 commit 6da9eb3
Show file tree
Hide file tree
Showing 13 changed files with 8,096 additions and 523 deletions.
1,760 changes: 1,337 additions & 423 deletions contracts/verifiers/FflonkVerifier.sol

Large diffs are not rendered by default.

2,158 changes: 2,158 additions & 0 deletions contracts/verifiers/FflonkVerifier_12.sol

Large diffs are not rendered by default.

2,158 changes: 2,158 additions & 0 deletions contracts/verifiers/previousVerifiers/FflonkVerifier_10.sol

Large diffs are not rendered by default.

2,158 changes: 2,158 additions & 0 deletions contracts/verifiers/previousVerifiers/FflonkVerifier_11.sol

Large diffs are not rendered by default.

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": 11,
"forkID": 12,
"consensusContract": "PolygonZkEVMEtrog",
"gasTokenAddress":"",
"deployerPvtKey": "",
Expand Down
3 changes: 2 additions & 1 deletion tools/addRollupType/.gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
add_rollup_type_output.json
add_rollup_type_output-*.json
add_rollup_type.json
genesis.json
20 changes: 10 additions & 10 deletions tools/addRollupType/addRollupType.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ async function main() {
"polygonRollupManagerAddress",
"verifierAddress",
"rollupCompatibilityID",
"genesisRoot"
"genesisRoot",
];

for (const parameterName of mandatoryDeploymentParameters) {
Expand All @@ -47,7 +47,7 @@ async function main() {
consensusContract,
polygonRollupManagerAddress,
verifierAddress,
genesisRoot
genesisRoot,
} = addRollupParameters;

const supportedConensus = ["PolygonZkEVMEtrog", "PolygonValidiumEtrog"];
Expand Down Expand Up @@ -117,21 +117,19 @@ async function main() {

// 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'`
);
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;
let genesisBridgeAddress = ethers.ZeroAddress;
for (let i = 0; i < genesis.genesis.lenght; i++) {
if (genesis.genesis[i].contractName === 'PolygonZkEVMBridge proxy') {
if (genesis.genesis[i].contractName === "PolygonZkEVMBridge proxy") {
genesisBridgeAddress = genesis.genesis[i].address;
break;
}
}

if (polygonZkEVMBridgeAddress.toLowerCase() !== genesisBridgeAddress ) {
if (polygonZkEVMBridgeAddress.toLowerCase() !== genesisBridgeAddress.toLowerCase()) {
throw new Error(
`'PolygonZkEVMBridge proxy' root in the 'genesis.json' does not match 'bridgeAddress' in the 'PolygonRollupManager'`
);
Expand All @@ -155,7 +153,10 @@ async function main() {
// Create consensus implementation if needed
let polygonConsensusContractAddress;

if (typeof addRollupParameters.polygonconsensusContract !== 'undefined' && ethers.isAddress(addRollupParameters.polygonconsensusContract)) {
if (
typeof addRollupParameters.polygonconsensusContract !== "undefined" &&
ethers.isAddress(addRollupParameters.polygonconsensusContract)
) {
polygonConsensusContractAddress = addRollupParameters.polygonconsensusContract;
} else {
const PolygonconsensusFactory = (await ethers.getContractFactory(consensusContract, deployer)) as any;
Expand Down Expand Up @@ -210,7 +211,6 @@ async function main() {
outputJson.rollupTypeID = newRollupTypeID;

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

Expand Down
2 changes: 1 addition & 1 deletion tools/deployVerifier/deployVerifier.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ async function main() {
/*
* Deployment Verifier
*/
const verifierName = `FflonkVerifier`;
const verifierName = `FflonkVerifier_${deployParameters.forkID}`;
let verifierContract;
if (deployParameters.realVerifier === true) {
const VerifierRollup = await ethers.getContractFactory(verifierName, deployer);
Expand Down
1 change: 1 addition & 0 deletions tools/deployVerifier/deploy_verifier_parameters.example
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"realVerifier": true,
"forkID": 12,
"deployerPvtKey": "",
"maxFeePerGas":"",
"maxPriorityFeePerGas":"",
Expand Down
2 changes: 2 additions & 0 deletions tools/updateRollup/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
updateRollupOutput-*.json
updateRollup.json
61 changes: 61 additions & 0 deletions tools/updateRollup/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
# Update rollup
Script to deploy call `updateRollup` function in the `PolygonRollupManager.sol` smart contract

## Install
```
npm i
```

## Setup
- Config file
- `rollupAddress`: rollup address of the rollup that is going to be updated
- `newRollupTypeID`: select which is the `rollupTypeID` to upgrade
- `upgradeData`: data necessary to perform the upgrade (default to `0x`)
- `polygonRollupManagerAddress`: `PolygonRollupManager.sol` SC address
- `timelockDelay (optional)`: at least it should be the minimum delay of the timelock smart contract
- `deployerPvtKey`: private key deployer
- First option will load `deployerPvtKey`. Otherwise, `process.env.MNEMONIC` will be loaded from the `.env` file
- `maxFeePerGas`: set custom gas
- `maxPriorityFeePerGas`: set custom gas
- `multiplierGas`: set custom gas
- 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 file:
```
cp ./tools/updateRollup/updateRollup.json.example ./tools/updateRollup/updateRollup.json
```

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

### Generate 'updateRollup' data to the Timelock SC

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

- Set your parameters
- Run tool:
```
npx hardhat run ./tools/updateRollup/updateRollupTimelock.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
110 changes: 23 additions & 87 deletions tools/updateRollup/updateRollup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,13 @@ import fs = require("fs");

import * as dotenv from "dotenv";
dotenv.config({path: path.resolve(__dirname, "../../.env")});
import {ethers} from "hardhat";
import {ethers, network} from "hardhat";

const addRollupParameters = require("./updateRollup.json");

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

async function main() {
Expand All @@ -25,7 +27,6 @@ async function main() {
"newRollupTypeID",
"upgradeData",
"polygonRollupManagerAddress",
"timelockDelay",
];

for (const parameterName of mandatoryDeploymentParameters) {
Expand All @@ -34,10 +35,7 @@ async function main() {
}
}

const {rollupAddress, newRollupTypeID, upgradeData, polygonRollupManagerAddress, timelockDelay} =
addRollupParameters;

const salt = addRollupParameters.timelockSalt || ethers.ZeroHash;
const {rollupAddress, newRollupTypeID, upgradeData, polygonRollupManagerAddress} = addRollupParameters;

// Load provider
let currentProvider = ethers.provider;
Expand Down Expand Up @@ -87,96 +85,34 @@ async function main() {

console.log("Using with: ", deployer.address);

// load timelock
const timelockContractFactory = await ethers.getContractFactory("PolygonZkEVMTimelock", deployer);

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

const operation = genOperation(
polygonRollupManagerAddress,
0, // value
PolgonRollupManagerFactory.interface.encodeFunctionData("updateRollup", [
rollupAddress,
newRollupTypeID,
upgradeData,
]),
ethers.ZeroHash, // predecesoor
salt // salt
);

// Schedule operation
const scheduleData = timelockContractFactory.interface.encodeFunctionData("schedule", [
operation.target,
operation.value,
operation.data,
operation.predecessor,
operation.salt,
timelockDelay,
]);
// Execute operation
const executeData = timelockContractFactory.interface.encodeFunctionData("execute", [
operation.target,
operation.value,
operation.data,
operation.predecessor,
operation.salt,
]);

console.log({scheduleData});
console.log({executeData});

outputJson.scheduleData = scheduleData;
outputJson.executeData = executeData;

// Decode the scheduleData for better readibility
const timelockTx = timelockContractFactory.interface.parseTransaction({data: scheduleData});
const paramsArray = timelockTx?.fragment.inputs;
const objectDecoded = {};

for (let i = 0; i < paramsArray?.length; i++) {
const currentParam = paramsArray[i];

objectDecoded[currentParam.name] = timelockTx?.args[i];

if (currentParam.name == "data") {
const decodedRollupManagerData = PolgonRollupManagerFactory.interface.parseTransaction({
data: timelockTx?.args[i],
});
const objectDecodedData = {};
const paramsArrayData = decodedRollupManagerData?.fragment.inputs;

for (let j = 0; j < paramsArrayData?.length; j++) {
const currentParam = paramsArrayData[j];
objectDecodedData[currentParam.name] = decodedRollupManagerData?.args[j];
}
objectDecoded["decodedData"] = objectDecodedData;
}
// Check role
const UPDATE_ROLLUP_ROLE = ethers.id("UPDATE_ROLLUP_ROLE");

if ((await rollupManagerContract.hasRole(UPDATE_ROLLUP_ROLE, deployer.address)) == false) {
// log that address ha sno role
throw new Error(`Address ${deployer.address} does not have the UPDATE_ROLLUP_ROLE role`);
}

outputJson.decodedScheduleData = objectDecoded;
// Add a new rollup type with timelock
console.log(await (await rollupManagerContract.updateRollup(rollupAddress, newRollupTypeID, upgradeData)).wait());

outputJson.networkName = network.name;
outputJson.polygonRollupManagerAddress = polygonRollupManagerAddress;
outputJson.rollupAddress = rollupAddress;
outputJson.newRollupTypeID = newRollupTypeID;
outputJson.upgradeData = upgradeData;

// add time to output path
fs.writeFileSync(pathOutputJson, JSON.stringify(outputJson, null, 1));
}

main().catch((e) => {
console.error(e);
process.exit(1);
});

// OZ test functions
function genOperation(target: any, value: any, data: any, predecessor: any, salt: any) {
const abiEncoded = ethers.AbiCoder.defaultAbiCoder().encode(
["address", "uint256", "bytes", "uint256", "bytes32"],
[target, value, data, predecessor, salt]
);
const id = ethers.keccak256(abiEncoded);
return {
id,
target,
value,
data,
predecessor,
salt,
};
}
Loading

0 comments on commit 6da9eb3

Please sign in to comment.