Skip to content

Commit

Permalink
minor fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
krlosMata committed Jan 27, 2025
1 parent 96ccc3a commit 50fb2eb
Show file tree
Hide file tree
Showing 5 changed files with 102 additions and 41 deletions.
10 changes: 5 additions & 5 deletions deployment/v2/utils/updateVanillaGenesis.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ import {padTo32Bytes, padTo20Bytes} from "./deployment-utils";
// Those contracts names came from the genesis creation:
// - https://github.com/0xPolygonHermez/zkevm-contracts/blob/main/deployment/v2/1_createGenesis.ts#L294
// - https://github.com/0xPolygonHermez/zkevm-contracts/blob/main/deployment/v2/1_createGenesis.ts#L328
// Some genesis have been created time ago and they have ald naming as in the links above
// Genesis files have been created previoudly and so they have old naming, as it shown in the links above
// Those genesis are already imported on different tooling and added as a metedata on-chain. Therefore, this util aims
// to support them too
const bridgeContractName = "BridgeL2SovereignChain";
const supportedGERManagers = ["PolygonZkEVMGlobalExitRootL2 implementation", "PolygonZkEVMGlobalExitRootL2"];
const supportedBridgeContracts = ['PolygonZkEVMBridgeV2', 'PolygonZkEVMBridge implementation', 'PolygonZkEVMBridgeV2 implementation'];
const supportedGERManagers = ["PolygonZkEVMGlobalExitRootL2 implementation"];
const supportedBridgeContracts = ['PolygonZkEVMBridge implementation', 'PolygonZkEVMBridgeV2 implementation'];
const supportedBridgeContractsProxy = ['PolygonZkEVMBridgeV2 proxy', 'PolygonZkEVMBridge proxy'];

async function updateVanillaGenesis(genesis, chainID, initializeParams) {
Expand Down Expand Up @@ -103,13 +103,13 @@ async function updateVanillaGenesis(genesis, chainID, initializeParams) {
await zkEVMDB.consolidate(batch);

// replace old bridge and ger manager by sovereign contracts bytecode
oldBridge.contractName = bridgeContractName;
oldBridge.contractName = bridgeContractName + " implementation";
oldBridge.bytecode = `0x${await zkEVMDB.getBytecode(sovereignBridgeAddress)}`;

const oldGer = genesis.genesis.find(function (obj) {
return supportedGERManagers.includes(obj.contractName);
});
oldGer.contractName = gerContractName;
oldGer.contractName = gerContractName + " implementation";
oldGer.bytecode = `0x${await zkEVMDB.getBytecode(GERAddress)}`;

// Setup a second zkEVM to initialize both contracts
Expand Down
4 changes: 2 additions & 2 deletions tools/createSovereignGenesis/.gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
output-*.json
output-*.json
genesis-rollupID-*.json
output-rollupID-*.json
genesis-base.json
create-genesis-sovereign-params.json
53 changes: 53 additions & 0 deletions tools/createSovereignGenesis/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
# Create sovereign genesis
Script to generate the genesis file for a rollup with `SovereignContracts`. This genesis si aim to be used for chains that are run with vanilla clients.
This script should be run after the rollup is created, so its `rollupID` and the bridge initialization parameters are known.
The script does the following:
- read base genesis file
- deploy sovereign cobtracts
- initialize them

## Setup
- install packages
```
npm i
```

- Set env variables
````
cp .env.example .env
````

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

- Copy configuration files:
```
cp ./tools/createSovereignGenesis/create-genesis-sovereign-params.json.example ./tools/createSovereignGenesis/create-genesis-sovereign-params.json
```

- Copy genesis base file:
```
cp ./tools/createSovereignGenesis/genesis-base.json.example ./tools/createSovereignGenesis/genesis-base.json
```

- Set your parameters
- `rollupManagerAddress`: `polygonRollupManager` smart contract address
- `rollupID`: Rollup identifier. Assigned to a rollup when it is created in the contracts
- `chainID`: ChainID of the rollup
- `gasTokenAddress`: Address of the native gas token of the rollup, zero if ether
- `bridgeManager`: bridge manager address
- `sovereignWETHAddress`: sovereign WETH address
- `sovereignWETHAddressIsNotMintable`: Flag to indicate if the wrapped ETH is not mintable
- `globalExitRootUpdater`: Address of globalExitRootUpdater for sovereign chains
- `globalExitRootRemover`: Address of globalExitRootRemover for sovereign chains

- Run tool:
```
npx hardhat run ./tools/createSovereignGenesis/create-sovereign-genesis.ts --network sepolia
```

### More Info
- All commands are done from root repository
- The output files are:
- `genesis-rollupID-${rollupID}__${timestamp}`: genesis file
- `output-rollupID-${rollupID}__${timestamp}`: input parameters, gastokenAddress information and network used
- outputs are saved in the tool folder: `./tools/createSovereignGenesis`
32 changes: 20 additions & 12 deletions tools/createSovereignGenesis/create-sovereign-genesis.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import fs = require("fs");

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

// internal dependencies
import updateVanillaGenesis from "../../deployment/v2/utils/updateVanillaGenesis";
Expand Down Expand Up @@ -148,29 +148,37 @@ async function main() {
// Populate final output
outputJson.network = hardhatArguments.network;
outputJson.rollupID = createGenesisSovereignParams.rollupID;
outputJson.rollupManagerAddress;
outputJson.rollupID;
outputJson.chainID;
outputJson.bridgeManager;
outputJson.sovereignWETHAddress;
outputJson.sovereignWETHAddressIsNotMintable;
outputJson.globalExitRootUpdater;
outputJson.globalExitRootRemover;
outputJson.gasTokenAddress = gasTokenAddress;
outputJson.gasTokenNetwork = gasTokenNetwork;
outputJson.gasTokenMetadata = gasTokenMetadata;
outputJson.rollupManagerAddress = createGenesisSovereignParams.rollupManagerAddress;
outputJson.chainID = createGenesisSovereignParams.chainID;
outputJson.bridgeManager = createGenesisSovereignParams.bridgeManager;
outputJson.sovereignWETHAddress = createGenesisSovereignParams.sovereignWETHAddress;
outputJson.sovereignWETHAddressIsNotMintable = createGenesisSovereignParams.sovereignWETHAddressIsNotMintable;
outputJson.globalExitRootUpdater = createGenesisSovereignParams.globalExitRootUpdater;
outputJson.globalExitRootRemover = createGenesisSovereignParams.globalExitRootRemover;

if (typeof outWETHAddress !== 'undefined') {
outputJson.WETHAddress = outWETHAddress;
}
outputJson.genesisSovereign = finalGenesis;

// path output genesis
const pathOutputGenesisJson = createGenesisSovereignParams.outputGenesisPath
? path.join(__dirname, createGenesisSovereignParams.outputGenesisPath)
: path.join(__dirname, `./output-${createGenesisSovereignParams.rollupID}-${dateStr}.json`);
: path.join(__dirname, `./genesis-rollupID-${createGenesisSovereignParams.rollupID}__${dateStr}.json`);

const pathOutputJson = createGenesisSovereignParams.outputPath
? path.join(__dirname, createGenesisSovereignParams.outputPath)
: path.join(__dirname, `./output-rollupID-${createGenesisSovereignParams.rollupID}__${dateStr}.json`);

// write files
fs.writeFileSync(pathOutputGenesisJson, JSON.stringify(finalGenesis, null, 1));
fs.writeFileSync(pathOutputJson, JSON.stringify(outputJson, null, 1));

console.log("Output saved at:");
console.log(` output tool: ${pathOutputGenesisJson}`);
console.log(` output genesis: ${pathOutputGenesisJson}`);
console.log(` output info : ${pathOutputJson}`);
}

main().catch((e) => {
Expand Down
44 changes: 22 additions & 22 deletions tools/createSovereignGenesis/genesis-base.json.example

Large diffs are not rendered by default.

0 comments on commit 50fb2eb

Please sign in to comment.