Skip to content

Commit

Permalink
Merge pull request #183 from 0xPolygonHermez/feature/updateV2Scripts
Browse files Browse the repository at this point in the history
Feature/update v2 scripts
  • Loading branch information
invocamanman authored Jan 30, 2024
2 parents e175a91 + 6466806 commit fb78b43
Show file tree
Hide file tree
Showing 22 changed files with 118 additions and 211 deletions.
6 changes: 3 additions & 3 deletions contracts/testnet/PolygonZkEVMTestnetClearStorage.sol
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import "../PolygonZkEVM.sol";

/**
* Contract responsible for managing the state and the updates of the L2 network
* This contract will NOT BE USED IN PRODUCTION, will be used only in testnet enviroment
* This contract will NOT BE USED IN PRODUCTION, will be used only in testnet environment
*/
contract PolygonZkEVMTestnetClearStorage is PolygonZkEVM {
// Indicates the current version
Expand Down Expand Up @@ -49,8 +49,8 @@ contract PolygonZkEVMTestnetClearStorage is PolygonZkEVM {
isForcedBatchDisallowed = true;
assembly {
sstore(version.slot, 0)
sstore(add(version.slot,1), 0)
sstore(add(version.slot,2), 0)
sstore(add(version.slot, 1), 0)
sstore(add(version.slot, 2), 0)
}
}
}
2 changes: 1 addition & 1 deletion contracts/testnet/PolygonZkEVMTestnetV2.sol
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import "../PolygonZkEVM.sol";

/**
* Contract responsible for managing the state and the updates of the L2 network
* This contract will NOT BE USED IN PRODUCTION, will be used only in testnet enviroment
* This contract will NOT BE USED IN PRODUCTION, will be used only in testnet environment
*/
contract PolygonZkEVMTestnetV2 is PolygonZkEVM {
// Indicates the current version
Expand Down
72 changes: 72 additions & 0 deletions contracts/v2/newDeployments/PolygonRollupManagerNotUpgraded.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
// SPDX-License-Identifier: AGPL-3.0
pragma solidity 0.8.20;
import "../PolygonRollupManager.sol";

/**
* PolygonRollupManager Test
*/
contract PolygonRollupManagerNotUpgraded is PolygonRollupManager {
/**
* @param _globalExitRootManager Global exit root manager address
* @param _pol MATIC token address
* @param _bridgeAddress Bridge address
*/
constructor(
IPolygonZkEVMGlobalExitRootV2 _globalExitRootManager,
IERC20Upgradeable _pol,
IPolygonZkEVMBridge _bridgeAddress
) PolygonRollupManager(_globalExitRootManager, _pol, _bridgeAddress) {}

function initialize(
address trustedAggregator,
uint64 _pendingStateTimeout,
uint64 _trustedAggregatorTimeout,
address admin,
address timelock,
address emergencyCouncil,
PolygonZkEVMExistentEtrog /*polygonZkEVM*/,
IVerifierRollup /*zkEVMVerifier*/,
uint64 /*zkEVMForkID*/,
uint64 /*zkEVMChainID*/
) external override reinitializer(2) {
pendingStateTimeout = _pendingStateTimeout;
trustedAggregatorTimeout = _trustedAggregatorTimeout;

// Constant deployment variables
_batchFee = 0.1 ether; // 0.1 Matic
verifyBatchTimeTarget = 30 minutes;
multiplierBatchFee = 1002;

// Initialize OZ contracts
__AccessControl_init();

// setup roles

// trusted aggregator role
_setupRole(_TRUSTED_AGGREGATOR_ROLE, trustedAggregator);

// Timelock roles
_setupRole(DEFAULT_ADMIN_ROLE, timelock);
_setupRole(_ADD_ROLLUP_TYPE_ROLE, timelock);
_setupRole(_ADD_EXISTING_ROLLUP_ROLE, timelock);

// Even this role can only update to an already added verifier/consensus
// Could break the compatibility of them, changing the virtual state
_setupRole(_UPDATE_ROLLUP_ROLE, timelock);

// Admin roles
_setupRole(_OBSOLETE_ROLLUP_TYPE_ROLE, admin);
_setupRole(_CREATE_ROLLUP_ROLE, admin);
_setupRole(_STOP_EMERGENCY_ROLE, admin);
_setupRole(_TWEAK_PARAMETERS_ROLE, admin);
_setRoleAdmin(_TRUSTED_AGGREGATOR_ROLE, _TRUSTED_AGGREGATOR_ROLE_ADMIN);
_setupRole(_TRUSTED_AGGREGATOR_ROLE_ADMIN, admin);

_setupRole(_SET_FEE_ROLE, admin);

// Emergency council roles
_setRoleAdmin(_EMERGENCY_COUNCIL_ROLE, _EMERGENCY_COUNCIL_ADMIN);
_setupRole(_EMERGENCY_COUNCIL_ROLE, emergencyCouncil);
_setupRole(_EMERGENCY_COUNCIL_ADMIN, emergencyCouncil);
}
}
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion deployment/v2/1_createGenesis.ts
Original file line number Diff line number Diff line change
Expand Up @@ -422,7 +422,7 @@ async function main() {
address: finalDeployer,
});

if (argv.test) {
if (deployParameters.test) {
// Add tester account with ether
genesis[genesis.length - 1].balance = "100000000000000000000000";
}
Expand Down
25 changes: 15 additions & 10 deletions deployment/v2/3_deployContracts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -390,6 +390,8 @@ async function main() {
expect(precalculateRollupManager).to.be.equal(await polygonZkEVMGlobalExitRoot.rollupManager());
}

const timelockAddressRollupManager = deployParameters.test ? deployer.address : timelockContract.target;

// deploy Rollup Manager
console.log("\n#######################");
console.log("##### Deployment Rollup Manager #####");
Expand All @@ -403,13 +405,10 @@ async function main() {
console.log("pendingStateTimeout:", pendingStateTimeout);
console.log("trustedAggregatorTimeout:", trustedAggregatorTimeout);
console.log("admin:", admin);
console.log("timelockContract:", timelockContract.target);
console.log("timelockContract:", timelockAddressRollupManager);
console.log("emergencyCouncilAddress:", emergencyCouncilAddress);

const PolygonRollupManagerFactory = await ethers.getContractFactory(
"PolygonRollupManagerMockInternalTest",
deployer
);
const PolygonRollupManagerFactory = await ethers.getContractFactory("PolygonRollupManagerNotUpgraded", deployer);

let polygonRollupManagerContract: any;
let deploymentBlockNumber;
Expand All @@ -423,7 +422,7 @@ async function main() {
pendingStateTimeout,
trustedAggregatorTimeout,
admin,
timelockContract.target,
timelockAddressRollupManager,
emergencyCouncilAddress,
ethers.ZeroAddress, // unused parameter
ethers.ZeroAddress, // unused parameter
Expand Down Expand Up @@ -496,12 +495,18 @@ async function main() {
console.log("trustedAggregatorTimeout:", await polygonRollupManagerContract.trustedAggregatorTimeout());

// Check roles
expect(await polygonRollupManagerContract.hasRole(DEFAULT_ADMIN_ROLE, timelockContract.target)).to.be.equal(true);
expect(await polygonRollupManagerContract.hasRole(ADD_ROLLUP_TYPE_ROLE, timelockContract.target)).to.be.equal(true);
expect(await polygonRollupManagerContract.hasRole(UPDATE_ROLLUP_ROLE, timelockContract.target)).to.be.equal(true);
expect(await polygonRollupManagerContract.hasRole(ADD_EXISTING_ROLLUP_ROLE, timelockContract.target)).to.be.equal(
expect(await polygonRollupManagerContract.hasRole(DEFAULT_ADMIN_ROLE, timelockAddressRollupManager)).to.be.equal(
true
);
expect(await polygonRollupManagerContract.hasRole(ADD_ROLLUP_TYPE_ROLE, timelockAddressRollupManager)).to.be.equal(
true
);
expect(await polygonRollupManagerContract.hasRole(UPDATE_ROLLUP_ROLE, timelockAddressRollupManager)).to.be.equal(
true
);
expect(
await polygonRollupManagerContract.hasRole(ADD_EXISTING_ROLLUP_ROLE, timelockAddressRollupManager)
).to.be.equal(true);
expect(await polygonRollupManagerContract.hasRole(TRUSTED_AGGREGATOR_ROLE, trustedAggregator)).to.be.equal(true);

expect(await polygonRollupManagerContract.hasRole(OBSOLETE_ROLLUP_TYPE_ROLE, admin)).to.be.equal(true);
Expand Down
8 changes: 8 additions & 0 deletions deployment/v2/4_createRollup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,13 @@ async function main() {
deployOutput.polygonRollupManager
) as PolygonRollupManager;

const DEFAULT_ADMIN_ROLE = ethers.ZeroHash;
if ((await rollupManagerContract.hasRole(DEFAULT_ADMIN_ROLE, deployer.address)) == false) {
throw new Error(
`Deployer does not have admin role. Use the test flag on deploy_parameters if this is a test deployment`
);
}

let verifierContract;
if (realVerifier === true) {
const VerifierRollup = await ethers.getContractFactory("FflonkVerifier", deployer);
Expand All @@ -155,6 +162,7 @@ async function main() {
const CREATE_ROLLUP_ROLE = ethers.id("CREATE_ROLLUP_ROLE");

// Check role:

if ((await rollupManagerContract.hasRole(ADD_ROLLUP_TYPE_ROLE, deployer.address)) == false)
await rollupManagerContract.grantRole(ADD_ROLLUP_TYPE_ROLE, deployer.address);

Expand Down
1 change: 1 addition & 0 deletions deployment/v2/deploy_parameters.json.example
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"test": true,
"timelockAdminAddress": "0x617b3a3528F9cDd6630fd3301B9c8911F7Bf063D",
"minDelayTimelock": 3600,
"salt": "0x0000000000000000000000000000000000000000000000000000000000000000",
Expand Down
98 changes: 0 additions & 98 deletions deployment/v2/genesis.json

This file was deleted.

8 changes: 4 additions & 4 deletions docker/scripts/v1ToV2/deploy-docker.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ sudo rm -rf docker/gethData/geth_data
DEV_PERIOD=1 docker-compose -f docker/docker-compose.geth.yml up -d geth
sleep 5
node docker/scripts/fund-accounts.js
cp docker/scripts/v1ToV2/deploy_parameters_docker.json deployment/v1ToV2/deploy_parameters.json
npm run deploy:testnet:v1ToV2:localhost
cp docker/scripts/testV1ToV2/deploy_parameters_docker.json deployment/testV1ToV2/deploy_parameters.json
npm run deploy:testnet:testV1ToV2:localhost
mkdir docker/deploymentOutput
mv deployment/v1ToV2/deploy_output.json docker/deploymentOutput
mv deployment/v1ToV2/genesis.json docker/deploymentOutput
mv deployment/testV1ToV2/deploy_output.json docker/deploymentOutput
mv deployment/testV1ToV2/genesis.json docker/deploymentOutput
DEV_PERIOD=1 docker-compose -f docker/docker-compose.geth.yml down
sudo docker build -t hermeznetwork/geth-zkevm-contracts -f docker/Dockerfile.geth .
# Let it readable for the multiplatform build coming later!
Expand Down
8 changes: 4 additions & 4 deletions docker/scripts/v1ToV2/deploy-dockerv2.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ sudo rm -rf docker/gethData/geth_data
DEV_PERIOD=1 docker compose -f docker/docker-compose.geth.yml up -d geth
sleep 5
node docker/scripts/fund-accounts.js
cp docker/scripts/v1ToV2/deploy_parameters_docker.json deployment/v1ToV2/deploy_parameters.json
npm run deploy:testnet:v1ToV2:localhost
cp docker/scripts/testV1ToV2/deploy_parameters_docker.json deployment/testV1ToV2/deploy_parameters.json
npm run deploy:testnet:testV1ToV2:localhost
mkdir docker/deploymentOutput
mv deployment/v1ToV2/deploy_output.json docker/deploymentOutput
mv deployment/v1ToV2/genesis.json docker/deploymentOutput
mv deployment/testV1ToV2/deploy_output.json docker/deploymentOutput
mv deployment/testV1ToV2/genesis.json docker/deploymentOutput
DEV_PERIOD=1 docker compose -f docker/docker-compose.geth.yml down
sudo docker build -t hermeznetwork/geth-zkevm-contracts -f docker/Dockerfile.geth .
# Let it readable for the multiplatform build coming later!
Expand Down
2 changes: 1 addition & 1 deletion docker/scripts/v1ToV2/hardhat.example.paris
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ const config: HardhatUserConfig = {
evmVersion: "paris",
}, // try yul optimizer
},
"contracts/v2/mocks/PolygonRollupManagerMockInternalTest.sol": {
"contracts/v2/newDeployments/PolygonRollupManagerNotUpgraded.sol": {
version: "0.8.20",
settings: {
optimizer: {
Expand Down
1 change: 1 addition & 0 deletions docker/scripts/v2/deploy_parameters_docker.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"test": true,
"timelockAdminAddress": "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266",
"minDelayTimelock": 3600,
"salt": "0x0000000000000000000000000000000000000000000000000000000000000000",
Expand Down
2 changes: 1 addition & 1 deletion docker/scripts/v2/hardhat.example.paris
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ const config: HardhatUserConfig = {
evmVersion: "paris",
}, // try yul optimizer
},
"contracts/v2/mocks/PolygonRollupManagerMockInternalTest.sol": {
"contracts/v2/newDeployments/PolygonRollupManagerNotUpgraded.sol": {
version: "0.8.20",
settings: {
optimizer: {
Expand Down
82 changes: 0 additions & 82 deletions docs/testnet/PolygonZkEVMTestnet.md

This file was deleted.

2 changes: 1 addition & 1 deletion hardhat.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ const config: HardhatUserConfig = {
evmVersion: "shanghai",
},
},
"contracts/v2/mocks/PolygonRollupManagerMockInternalTest.sol": {
"contracts/v2/newDeployments/PolygonRollupManagerNotUpgraded.sol": {
version: "0.8.20",
settings: {
optimizer: {
Expand Down
10 changes: 5 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -90,11 +90,11 @@
"deploy:v2:sepolia": "npx hardhat compile && npx ts-node deployment/v2/1_createGenesis.ts && npx hardhat run deployment/v2/2_deployPolygonZKEVMDeployer.ts --network sepolia && npx hardhat run deployment/v2/3_deployContracts.ts --network sepolia && npx hardhat run deployment/v2/4_createRollup.ts --network sepolia && npm run saveDeployment:sepolia",
"deploy:testnet:v2:sepolia": "npx hardhat compile && rm -f deployment/v2/deploy_ongoing.json && npm run prepare:testnet:ZkEVM:sepolia && npm run deploy:v2:sepolia",
"verify:v2:sepolia": "npx hardhat run deployment/v2/verifyContracts.js --network sepolia",
"prepare:v1ToV2:ZkEVM:localhost": "npx hardhat run deployment/v1ToV2/prepareTestnet.ts --network localhost",
"deploy:v1ToV2:localhost": "npx hardhat compile && rm -f .openzeppelin/unknown-*.json && npx ts-node deployment/v1ToV2/1_createGenesis.ts --test && npx hardhat run deployment/v1ToV2/2_deployPolygonZKEVMDeployer.ts --network localhost && npx hardhat run deployment/v1ToV2/3_deployContracts.ts --network localhost",
"deploy:testnet:v1ToV2:localhost": "npx hardhat compile && rm -f deployment/v1ToV2/deploy_ongoing.json && npm run prepare:v1ToV2:ZkEVM:localhost && npm run deploy:v1ToV2:localhost",
"docker:v1ToV2:contracts": "./docker/scripts/v1ToV2/deploy-docker.sh",
"dockerv2:v1ToV2:contracts": "sudo ./docker/scripts/v1ToV2/deploy-dockerv2.sh",
"prepare:testV1ToV2:ZkEVM:localhost": "npx hardhat run deployment/testV1ToV2/prepareTestnet.ts --network localhost",
"deploy:testV1ToV2:localhost": "npx hardhat compile && rm -f .openzeppelin/unknown-*.json && npx ts-node deployment/testV1ToV2/1_createGenesis.ts --test && npx hardhat run deployment/testV1ToV2/2_deployPolygonZKEVMDeployer.ts --network localhost && npx hardhat run deployment/testV1ToV2/3_deployContracts.ts --network localhost",
"deploy:testnet:testV1ToV2:localhost": "npx hardhat compile && rm -f deployment/testV1ToV2/deploy_ongoing.json && npm run prepare:testV1ToV2:ZkEVM:localhost && npm run deploy:testV1ToV2:localhost",
"docker:testV1ToV2:contracts": "./docker/scripts/testV1ToV2/deploy-docker.sh",
"dockerv2:testV1ToV2:contracts": "sudo ./docker/scripts/testV1ToV2/deploy-dockerv2.sh",
"saveDeployment:sepolia": "mkdir -p deployments/sepolia_$(date +%s) && cp -r deployment/v2/deploy_*.json deployments/sepolia_$(date +%s) && cp .openzeppelin/sepolia.json deployments/sepolia_$(date +%s) && cp deployment/v2/genesis.json deployments/sepolia_$(date +%s) && cp deployment/v2/create_rollup_output.json deployments/sepolia_$(date +%s)",
"testnetPol:upgradeV2:sepolia": "npx hardhat run upgrade/upgradeToV2/testnet/deployTestnetPol.ts --network sepolia",
"testnetPol:upgradeV2:goerli": "npx hardhat run upgrade/upgradeToV2/testnet/deployTestnetPol.ts --network goerli",
Expand Down

0 comments on commit fb78b43

Please sign in to comment.