Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/update upgrade script #79

Merged
merged 4 commits into from
Jan 9, 2023
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,5 @@ docs/mocks
.vscode/launch.json
deploy_output.json
deploy_parameters.json
deployments
deployments
upgrade_parameters.json
10 changes: 7 additions & 3 deletions deployment/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ Fill created `deploy_parameters.json` with appropiate parameters.

To deploy contracts run `npm run deploy:ZkEVM:${network}`, for example:

> set `runs` parameter from the compiler settings in `hardhat.config.js` (i.e. `runs: 200`)
> set `runs` parameter from the compiler settings in `hardhat.config.js` (i.e. `runs: 100`)

```
npm run deploy:ZkEVM:goerli
Expand All @@ -35,6 +35,8 @@ To verify contracts run `npm run verify:ZkEVM:${network}`, for example:
npm run verify:ZkEVM:goerli
```

A new folder will be created witth the following name `deployments/${network}_$(date +%s)` with all the output information and the OZ proxy information.

## deploy-parameters.json

- `trustedSequencerURL`: string, trustedSequencer URL
Expand All @@ -46,15 +48,17 @@ npm run verify:ZkEVM:goerli

### Optional Parameters

- `privateKey`: string, privateKey of the deployment
- `deployerPvtKey`: string, deployerPvtKey of the deployer
- `maxFeePerGas`:string, maxFeePerGas of all txs
- `maxPriorityFeePerGas`:string, maxPriorityFeePerGas of all txs
- `multiplierGas`: number, Gas multiplier. If maxFeePerGas and maxPriorityFeePerGas are set, will not take effect
- `trustedSequencerPvtKey`: string, Trusted sequencer pvtKey in order to approve the matic tokens
- `PolygonZkEVMBridgeMock`:Boolean, Wheather the PolygonZkEVMBridge will be mock or not ( the mock version has a ether limitation on deposits)
- `admin`:address, Admin address
- `trustedAggregator`:address, Trusted aggregator address
- `minDelayTimelock`: number, minimum timelock delay,
- `timelockAddress`: address, Timelock owner address

## Notes

- `gensis.json` has been generated using the tool: `https://github.com/0xPolygonHermez/zkevm-commonjs/blob/main/tools/fill-genesis/create-genesis.js` using as generator file: `genesis-gen.json`
- `genesis.json` has been generated using the tool: `src/create-genesis.js` using as generator file: `genesis-gen.json`
4 changes: 2 additions & 2 deletions deployment/deployContracts.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@ async function main() {

// Load deployer
let deployer;
if (deployParameters.privateKey) {
deployer = new ethers.Wallet(deployParameters.privateKey, currentProvider);
if (deployParameters.deployerPvtKey) {
deployer = new ethers.Wallet(deployParameters.deployerPvtKey, currentProvider);
} else if (process.env.MNEMONIC) {
deployer = ethers.Wallet.fromMnemonic(process.env.MNEMONIC, 'm/44\'/60\'/0\'/0/0').connect(currentProvider);
} else {
Expand Down
2 changes: 1 addition & 1 deletion deployment/deploy_parameters.json.example
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"realVerifier": false,
"chainID": 1001,
"networkName": "zkevm",
"privateKey": "",
"deployerPvtKey": "",
"maxFeePerGas":0,
"maxPriorityFeePerGas":0,
"multiplierGas": 0,
Expand Down
54 changes: 0 additions & 54 deletions deployment/simpleUpgradeScript.js

This file was deleted.

108 changes: 0 additions & 108 deletions deployment/timeLockUpgrade.js

This file was deleted.

4 changes: 2 additions & 2 deletions deployment/verifyContracts.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ async function main() {

// verify timeLock
let deployer;
if (deployParameters.privateKey) {
deployer = new ethers.Wallet(deployParameters.privateKey);
if (deployParameters.deployerPvtKey) {
deployer = new ethers.Wallet(deployParameters.deployerPvtKey);
} else if (process.env.MNEMONIC) {
deployer = ethers.Wallet.fromMnemonic(process.env.MNEMONIC, 'm/44\'/60\'/0\'/0/0');
} else {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@
"docgen": "npx solidity-docgen --solc-module solc-0.8 -t ./docs/templates -e ./contracts/verifiers,./contracts/mocks",
"deploy:ZkEVM:hardhat": "npx hardhat run deployment/deployContracts.js --network hardhat",
"deploy:ZkEVM:goerli": "npx hardhat run deployment/deployContracts.js --network goerli && npm run saveDeployment:goerli",
"upgrade:timelock:goerli": "npx hardhat run deployment/timeLockUpgrade.js --network goerli",
"upgrade:timelock:goerli": "npx hardhat run upgrade/timeLockUpgrade.js --network goerli",
"verify:ZkEVM:goerli": "npx hardhat run deployment/verifyContracts.js --network goerli",
"lint": "npx eslint ./test && npx eslint ./docker/scripts && npx eslint ./deployment && npx eslint ./src",
"lint:fix": "npx eslint ./test --fix && npx eslint ./docker/scripts --fix && npx eslint ./deployment --fix && npx eslint ./src --fix",
Expand Down
53 changes: 53 additions & 0 deletions upgrade/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
## Requirements

- node version: 14.x
- npm version: 7.x

## Upgrade

```
npm i
cp .env.example .env
```

Fill `.env` with your `MNEMONIC` and `INFURA_PROJECT_ID`

In order to upgrade the contracts we will need the information on `deployments/${network}_$(date +%s)`

In project root, copy the `${network}.json` of the deployment that you want to upgrade and copy it on the `./.openzeppelin`
e.g. `cp deployments/${network}_$(date +%s)/${network}.json ./.openzeppelin`

Then fill the upgrade parameters:

```
cd deployment
cp upgrade_parameters.json.example upgrade_parameters.json
```

Fill created `upgrade_parameters.json` with appropiate parameters.
You should fullfill the upgrades array, with all the updates that you intend to do ( more information in `upgrade-parameters.json` section)

if the deployment was deployed without a timelock you can use the `simpleUpgradeScript.js`:

- Run the script

Otherwise, in case of timelock use `timeLockUpgrade.js`

- Run the script
- Now the necessary transactions to interact with the timelock are printed in the screen `schedule` and `execute`, also will be saved in
`./upgrade_output_${new Date().getTime() / 1000}.json` file
- With the owner of the timelock (multisig or account), send the data printed by `schedule` to the `Timelock` contract.
- Once the necessary `timelockMinDelay` has expired, with the same account you can now send the data printed by `execute` to the `Timelock` contract and the contracts will be upgraded.

## upgrade-parameters.json

- `timelockMinDelay`: number, timelock delay between the schedule and execution, must be bigger than current min delay
- `upgrades`: Object, Indicates which address and to which implementation must upgrade
- address: address of the current proxy
- contractName: string, contract name that the proxy will be updated to.s

### Optional Parameters

- `multiplierGas`: number, Gas multiplier. If maxFeePerGas and maxPriorityFeePerGas are set, will not take effect
- `deployerPvtKey`: string, deployerPvtKey of the deployer
- `timelockSalt`: string, Optional salt for the timelock
53 changes: 53 additions & 0 deletions upgrade/simpleUpgrade.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/* eslint-disable no-console, no-unused-vars */
const hre = require('hardhat');
const { ethers, upgrades } = require('hardhat');
const path = require('path');
require('dotenv').config({ path: path.resolve(__dirname, '../.env') });
const upgradeParameters = require('./upgrade_parameters.json');

async function main() {
// Set multiplier Gas
let currentProvider = ethers.provider;
if (upgradeParameters.multiplierGas) {
if (process.env.HARDHAT_NETWORK !== 'hardhat') {
const multiplierGas = upgradeParameters.multiplierGas;
currentProvider = new ethers.providers.JsonRpcProvider(`https://${process.env.HARDHAT_NETWORK}.infura.io/v3/${process.env.INFURA_PROJECT_ID}`);
async function overrideFeeData() {
const feedata = await ethers.provider.getFeeData();
return {
maxFeePerGas: feedata.maxFeePerGas.mul(multiplierGas),
maxPriorityFeePerGas: feedata.maxPriorityFeePerGas.mul(multiplierGas),
};
}
currentProvider.getFeeData = overrideFeeData;
}
}
let deployer;
if (upgradeParameters.deployerPvtKey) {
deployer = new ethers.Wallet(upgradeParameters.deployerPvtKey, currentProvider);
} else if (process.env.MNEMONIC) {
deployer = ethers.Wallet.fromMnemonic(process.env.MNEMONIC, 'm/44\'/60\'/0\'/0/0').connect(currentProvider);
} else {
[deployer] = (await ethers.getSigners());
}

// compìle contracts
await hre.run('compile');

for (const upgrade of upgradeParameters.upgrades) {
const proxyPolygonAddress = upgrade.address;
const polygonZkEVMFactory = await ethers.getContractFactory(upgrade.contractName, deployer);

const txZKEVM = await upgrades.upgradeProxy(proxyPolygonAddress, polygonZkEVMFactory);

console.log(txZKEVM.deployTransaction);
console.log(await txZKEVM.deployTransaction.wait());
console.log('upgrade succesfull', upgrade.contractName);
}
}
main()
.then(() => process.exit(0))
.catch((error) => {
console.error(error);
process.exit(1);
});
Loading