Skip to content

Commit

Permalink
Merge pull request #121 from 0xPolygonHermez/feature/updateReadme
Browse files Browse the repository at this point in the history
update deploy readme
  • Loading branch information
invocamanman authored Apr 14, 2023
2 parents b1cefea + 8b24afc commit c773842
Show file tree
Hide file tree
Showing 7 changed files with 71 additions and 31 deletions.
4 changes: 2 additions & 2 deletions deployment/2_deployPolygonZKEVMDeployer.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ async function main() {
async function overrideFeeData() {
const feedata = await ethers.provider.getFeeData();
return {
maxFeePerGas: feedata.maxFeePerGas.mul(deployParameters.multiplierGas), // add 3 decimals
maxPriorityFeePerGas: feedata.maxPriorityFeePerGas.mul(deployParameters.multiplierGas), // add 3 decimals
maxFeePerGas: feedata.maxFeePerGas.mul(deployParameters.multiplierGas).div(1000),
maxPriorityFeePerGas: feedata.maxPriorityFeePerGas.mul(deployParameters.multiplierGas).div(1000),
};
}
currentProvider.getFeeData = overrideFeeData;
Expand Down
8 changes: 4 additions & 4 deletions deployment/3_deployContracts.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,8 @@ async function main() {
async function overrideFeeData() {
const feedata = await ethers.provider.getFeeData();
return {
maxFeePerGas: feedata.maxFeePerGas.mul(deployParameters.multiplierGas).div(1000), // add 3 decimals
maxPriorityFeePerGas: feedata.maxPriorityFeePerGas.mul(deployParameters.multiplierGas).div(1000), // add 3 decimals
maxFeePerGas: feedata.maxFeePerGas.mul(deployParameters.multiplierGas).div(1000),
maxPriorityFeePerGas: feedata.maxPriorityFeePerGas.mul(deployParameters.multiplierGas).div(1000),
};
}
currentProvider.getFeeData = overrideFeeData;
Expand Down Expand Up @@ -347,7 +347,7 @@ async function main() {
console.log('genesisRoot:', genesisRootHex);
console.log('trustedSequencerURL:', trustedSequencerURL);
console.log('networkName:', networkName);
console.log('networkName:', forkID);
console.log('forkID:', forkID);

const PolygonZkEVMFactory = await ethers.getContractFactory('PolygonZkEVM', deployer);

Expand Down Expand Up @@ -434,7 +434,7 @@ async function main() {
}

console.log('\n#######################');
console.log('##### Checks PolygonZkEVMMock #####');
console.log('##### Checks PolygonZkEVM #####');
console.log('#######################');
console.log('PolygonZkEVMGlobalExitRootAddress:', await polygonZkEVMContract.globalExitRootManager());
console.log('maticTokenAddress:', await polygonZkEVMContract.matic());
Expand Down
52 changes: 35 additions & 17 deletions deployment/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,23 +13,32 @@ cp .env.example .env
```

Fill `.env` with your `MNEMONIC` and `INFURA_PROJECT_ID`
If you want to verify the contracts also fill the `ETHERSCAN_API_KEY`

```
cd deployment
cp deploy_parameters.json.example deploy_parameters.json
```

Fill created `deploy_parameters.json` with appropiate parameters.
See below for more information about the `deploy_parameters.json`

To deploy contracts first deploy and verify the `PolygonZkEVMDeployer`
The first step is deploying and verifying the `PolygonZkEVMDeployer`, this will be the factory for deterministic contracts, the address of the contracts will depend on the `salt` and the `initialZkEVMDeployerOwner`

This contrat is deployed using a keyless deployment, therefore the gasPrice is hardcoded.
The value is on `100 gweis`, if it's necessary to update it go to `helpers/deployment-helpers.js` and update the `gasPriceKeylessDeployment` constant.
Note that this operation will change all the deterministic address deployed.

```
npm run deploy:deployer:ZkEVM:goerli
npm run verify:deployer:ZkEVM:goerli
```

Then deploy the contracts, if we are on testnet use `deploy:testnet:ZkEVM:${network}`, in other cases use `deploy:ZkEVM:${network}` and
set in deploy_parameters the `maticTokenAddress`:
To deploy on testnet is necessary a token MATIC contract, therefore, there's another script that previously to the actual deployment, deploys a matic contracts and adds it automatically to the `deploy_parameters.json`

To deploy on testnet use:`deploy:testnet:ZkEVM:${network}`

In other cases use fullfill `maticTokenAddress` in the `deploy_parameters.json` and run `deploy:ZkEVM:${network}`

```
npm run deploy:testnet:ZkEVM:goerli
Expand All @@ -46,25 +55,34 @@ A new folder will be created witth the following name `deployments/${network}_$(

## deploy-parameters.json

- `realVerifier`: bool, Indicates whether deploy a real verifier or not
- `trustedSequencerURL`: string, trustedSequencer URL
- `trustedSequencerAddress`: address, trusted sequencer addresss
- `realVerifier`: boolean, deploy or not a real verifier
- `chainID`: uint64, chainID
- `networkName`: string, networkName
- `version`:string, will just be emitted at initialization of the contract, usefull just for synchronizer
- `trustedSequencer`: address, trusted sequencer addresss
- `chainID`: uint64, chainID of the zkEVM
- `trustedAggregator`:address, Trusted aggregator address
- `trustedAggregatorTimeout`: uint64, If a sequence is not verified in this timeout everyone can verify it
- `pendingStateTimeout`: uint64, Once a pending state exceeds this timeout it can be consolidated
- `forkID`: uint64, Fork ID of the zkEVM, indicates the prover (zkROM/executor) version
- `admin`:address, Admin address, can adjust PolygonZkEVM parameters or stop the emergency state
- `zkEVMOwner`: address, Able to put the PolygonZkEVM into emergency state (kill switch)
- `timelockAddress`: address, Timelock owner address, able to send start an upgradability process via timelock
- `minDelayTimelock`: number, Minimum timelock delay,
- `salt`: bytes32, Salt used in `PolygonZkEVMDeployer` to deploy deterministic contracts, such as the PolygonZkEVMBridge
- `initialZkEVMDeployerOwner`: address, Initial owner of the `PolygonZkEVMDeployer`
- `maticTokenAddress`: address, Matic token address, only if deploy on testnet can be left blank and will fullfilled by the scripts.
- `zkEVMDeployerAddress`: address, Address of the `PolygonZkEVMDeployer`. Can be left blank, will be fullfilled automatically with the `deploy:deployer:ZkEVM:goerli` script.

### Optional Parameters

- `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
- `deployerPvtKey`: string, pvtKey of the deployer, overrides the address in `MNEMONIC` of `.env` if exist
- `maxFeePerGas`:string, Set `maxFeePerGas`, must define aswell `maxPriorityFeePerGas` to use it
- `maxPriorityFeePerGas`:string, Set `maxPriorityFeePerGas`, must define aswell `maxFeePerGas` to use it
- `multiplierGas`: number, Gas multiplier with 3 decimals. If `maxFeePerGas` and `maxPriorityFeePerGas` are set, this will not take effect

## Notes

- `genesis.json` has been generated using the tool: `src/create-genesis.js` using as generator file: `genesis-gen.json`
- Since there are deterministic address you cannot deploy twice on the same network using the same `salt` and `initialZkEVMDeployerOwner`. Changing one of them is enough to make a new deployment.
- It's mandatory to delete the `.openzeppelin` upgradebility information in order to make a new deployment
- `genesis.json` has been generated using the tool: `1_createGenesis`, this script depends on the `deploy_parameters` aswell.
6 changes: 3 additions & 3 deletions deployment/deploy_parameters.json.example
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@
"timelockAddress": "0x617b3a3528F9cDd6630fd3301B9c8911F7Bf063D",
"minDelayTimelock": 3600,
"salt": "0x0000000000000000000000000000000000000000000000000000000000000000",
"zkEVMDeployerAddress":"",
"initialZkEVMDeployerOwner" :"0xaddress"
"initialZkEVMDeployerOwner" :"0xaddress",
"maticTokenAddress":"0x617b3a3528F9cDd6630fd3301B9c8911F7Bf063D",
"zkEVMDeployerAddress":"",
"deployerPvtKey": "",
"maxFeePerGas":"",
"maxPriorityFeePerGas":"",
"multiplierGas": "",
"multiplierGas": ""
}
4 changes: 3 additions & 1 deletion deployment/helpers/deployment-helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
const { expect } = require('chai');
const { ethers } = require('hardhat');

const gasPriceKeylessDeployment = '100'; // 100 gweis

async function deployPolygonZkEVMDeployer(deployerAddress, signer) {
const PolgonZKEVMDeployerFactory = await ethers.getContractFactory('PolygonZkEVMDeployer', signer);

Expand All @@ -11,7 +13,7 @@ async function deployPolygonZkEVMDeployer(deployerAddress, signer) {
)).data;

const gasLimit = ethers.BigNumber.from(1000000); // Put 1 Million, aprox 650k are necessary
const gasPrice = ethers.BigNumber.from(ethers.utils.parseUnits('100', 'gwei')); // just in case, seems pretty standard
const gasPrice = ethers.BigNumber.from(ethers.utils.parseUnits(gasPriceKeylessDeployment, 'gwei'));
const to = '0x'; // bc deployment transaction, "to" is "0x"
const tx = {
to,
Expand Down
18 changes: 18 additions & 0 deletions hardhat.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,15 @@ module.exports = {
count: 20,
},
},
polygonZKEVMMainnet: {
url: "https://zkevm-rpc.com",
accounts: {
mnemonic: process.env.MNEMONIC || DEFAULT_MNEMONIC,
path: "m/44'/60'/0'/0",
initialIndex: 0,
count: 20,
},
},
},
gasReporter: {
enabled: !!process.env.REPORT_GAS,
Expand All @@ -139,10 +148,19 @@ module.exports = {
etherscan: {
apiKey: {
polygonZKEVMTestnet: `${process.env.ETHERSCAN_ZKEVM_API_KEY}`,
polygonZKEVMMainnet: `${process.env.ETHERSCAN_ZKEVM_API_KEY}`,
goerli: `${process.env.ETHERSCAN_API_KEY}`,
mainnet: `${process.env.ETHERSCAN_API_KEY}`
},
customChains: [
{
network: "polygonZKEVMMainnet",
chainId: 1101,
urls: {
apiURL: "https://api-zkevm.polygonscan.com/api",
browserURL: "https://zkevm.polygonscan.com/"
}
},
{
network: "polygonZKEVMTestnet",
chainId: 1442,
Expand Down
10 changes: 6 additions & 4 deletions test/contracts/polygonZkEVMTestnetV2.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -120,15 +120,17 @@ describe('Polygon ZK-EVM TestnetV2', () => {
});

it('should check updateVersion', async () => {
const lastVerifiedBatch = 0;
const newVersionString = '0.0.2';

await expect(polygonZkEVMContract.updateVersion(newVersionString))
.to.emit(polygonZkEVMContract, 'UpdateZkEVMVersion').withArgs(lastVerifiedBatch, forkID, newVersionString);
/*
* const lastVerifiedBatch = 0;
* await expect(polygonZkEVMContract.updateVersion(newVersionString))
* .to.emit(polygonZkEVMContract, 'UpdateZkEVMVersion').withArgs(lastVerifiedBatch, forkID, newVersionString);
*/

await expect(polygonZkEVMContract.updateVersion(newVersionString))
.to.be.revertedWith('VersionAlreadyUpdated');

expect(await polygonZkEVMContract.version()).to.be.equal(1);
// expect(await polygonZkEVMContract.version()).to.be.equal(1);
});
});

0 comments on commit c773842

Please sign in to comment.