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

update commmnets #182

Merged
merged 3 commits into from
Jan 27, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
25 changes: 14 additions & 11 deletions contracts/v2/PolygonRollupManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,11 @@ import "./lib/LegacyZKEVMStateVariables.sol";
import "./consensus/zkEVM/PolygonZkEVMExistentEtrog.sol";
import "./lib/PolygonConstantsBase.sol";

// review Possible renaming to PolygonL2Manager
/**
* Contract responsible for managing the exit roots across multiple Rollups
* Contract responsible for managing rollups and the verification of their batches.
* This contract will create and update rollups and store all the hashed sequenced data from them.
* The logic for sequence batches is moved to the `consensus` contracts, while the verification of all of
* them will be done in this one. In this way, the proof aggregation of the rollups will be easier on a close future.
*/
contract PolygonRollupManager is
PolygonAccessControlUpgradeable,
Expand Down Expand Up @@ -200,14 +202,14 @@ contract PolygonRollupManager is
uint64 public pendingStateTimeout;

// Time target of the verification of a batch
// Adaptatly the batchFee will be updated to achieve this target
// Adaptively the batchFee will be updated to achieve this target
uint64 public verifyBatchTimeTarget;

// Batch fee multiplier with 3 decimals that goes from 1000 - 1023
uint16 public multiplierBatchFee;

// Current POL fee per batch sequenced
// note This variable is internal, since the view function getBatchFee is likely to be ugpraded
// note This variable is internal, since the view function getBatchFee is likely to be upgraded
uint256 internal _batchFee;

// Timestamp when the last emergency state was deactivated
Expand Down Expand Up @@ -369,7 +371,7 @@ contract PolygonRollupManager is
}

/**
* @param trustedAggregator Trusted aggregatot address
* @param trustedAggregator Trusted aggregator address
* @param _pendingStateTimeout Pending state timeout
* @param _trustedAggregatorTimeout Trusted aggregator timeout
* @param admin Admin of the rollup manager
Expand Down Expand Up @@ -423,7 +425,7 @@ contract PolygonRollupManager is
_setupRole(_STOP_EMERGENCY_ROLE, admin);
_setupRole(_TWEAK_PARAMETERS_ROLE, admin);

// admin should be able to update the trsuted aggregator address
// admin should be able to update the trusted aggregator address
_setRoleAdmin(_TRUSTED_AGGREGATOR_ROLE, _TRUSTED_AGGREGATOR_ROLE_ADMIN);
_setupRole(_TRUSTED_AGGREGATOR_ROLE_ADMIN, admin);
_setupRole(_SET_FEE_ROLE, admin);
Expand Down Expand Up @@ -908,7 +910,7 @@ contract PolygonRollupManager is
}

/**
* @notice Allows an aggregator to verify multiple batches
* @notice Allows a trusted aggregator to verify multiple batches
* @param rollupID Rollup identifier
* @param pendingStateNum Init pending state, 0 if consolidated state is used
* @param initNumBatch Batch which the aggregator starts the verification
Expand Down Expand Up @@ -972,6 +974,7 @@ contract PolygonRollupManager is
* @param finalNewBatch Last batch aggregator intends to verify
* @param newLocalExitRoot New local exit root once the batch is processed
* @param newStateRoot New State root once the batch is processed
* @param beneficiary Address that will receive the verification reward
* @param proof Fflonk proof
*/
function _verifyAndRewardBatches(
Expand Down Expand Up @@ -1227,7 +1230,7 @@ contract PolygonRollupManager is
}

/**
* @notice Allows to halt the PolygonZkEVM if its possible to prove a different state root given the same batches
* @notice Allows activate the emergency state if its possible to prove a different state root given the same batches
* @param rollupID Rollup identifier
* @param initPendingStateNum Init pending state, 0 if consolidated state is used
* @param finalPendingStateNum Final pending state, that will be used to compare with the newStateRoot
Expand Down Expand Up @@ -1475,7 +1478,7 @@ contract PolygonRollupManager is
////////////////////////

/**
* @notice Function to activate emergency state, which also enables the emergency mode on both PolygonZkEVM and PolygonZkEVMBridge contracts
* @notice Function to activate emergency state, which also enables the emergency mode on both PolygonRollupManager and PolygonZkEVMBridge contracts
* If not called by the owner must not have been aggregated in a _HALT_AGGREGATION_TIMEOUT period and an emergency state was not happened in the same period
*/
function activateEmergencyState() external {
Expand All @@ -1495,7 +1498,7 @@ contract PolygonRollupManager is
}

/**
* @notice Function to deactivate emergency state on both PolygonZkEVM and PolygonZkEVMBridge contracts
* @notice Function to deactivate emergency state on both PolygonRollupManager and PolygonZkEVMBridge contracts
*/
function deactivateEmergencyState()
external
Expand All @@ -1512,7 +1515,7 @@ contract PolygonRollupManager is
}

/**
* @notice Internal function to activate emergency state on both PolygonZkEVM and PolygonZkEVMBridge contracts
* @notice Internal function to activate emergency state on both PolygonRollupManager and PolygonZkEVMBridge contracts
*/
function _activateEmergencyState() internal override {
// Activate emergency state on PolygonZkEVM Bridge
Expand Down
12 changes: 6 additions & 6 deletions contracts/v2/PolygonZkEVMBridgeV2.sol
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,8 @@ import "./interfaces/IPolygonZkEVMBridgeV2.sol";
import "../lib/EmergencyManager.sol";
import "../lib/GlobalExitRootLib.sol";

// review Possible renaming to PolygonBridge
/**
* PolygonZkEVMBridge that will be deployed on both networks Ethereum and Polygon zkEVM
* PolygonZkEVMBridge that will be deployed on Ethereum and all Polygon rollups
* Contract responsible to manage the token interactions with other networks
*/
contract PolygonZkEVMBridgeV2 is
Expand Down Expand Up @@ -142,6 +141,7 @@ contract PolygonZkEVMBridgeV2 is
* @param _polygonRollupManager polygonZkEVM address
* @notice The value of `_polygonRollupManager` on the L2 deployment of the contract will be address(0), so
* emergency state is not possible for the L2 deployment of the bridge, intentionally
* @param _gasTokenMetadata Abi encoded gas token metadata
*/
function initialize(
uint32 _networkID,
Expand Down Expand Up @@ -425,8 +425,8 @@ contract PolygonZkEVMBridgeV2 is

/**
* @notice Verify merkle proof and withdraw tokens/ether
* @param smtProofLocalExitRoot Smt proof to proof the leaf agains the exit root
* @param smtProofRollupExitRoot Smt proof to proof the rollupLocalExitRoot agains the RollupExitRoot
* @param smtProofLocalExitRoot Smt proof to proof the leaf against the network exit root
* @param smtProofRollupExitRoot Smt proof to proof the rollupLocalExitRoot against the rollups exit root
* @param globalIndex Global index is defined as:
* | 191 bits | 1 bit | 32 bits | 32 bits |
* | 0 | mainnetFlag | rollupIndex | localRootIndex |
Expand Down Expand Up @@ -578,8 +578,8 @@ contract PolygonZkEVMBridgeV2 is
* If the receiving address is an EOA, the call will result as a success
* Which means that the amount of ether will be transferred correctly, but the message
* will not trigger any execution
* @param smtProofLocalExitRoot Smt proof to proof the leaf agains the exit root
* @param smtProofRollupExitRoot Smt proof to proof the rollupLocalExitRoot agains the RollupExitRoot
* @param smtProofLocalExitRoot Smt proof to proof the leaf against the exit root
* @param smtProofRollupExitRoot Smt proof to proof the rollupLocalExitRoot against the rollups exit root
* @param globalIndex Global index is defined as:
* | 191 bits | 1 bit | 32 bits | 32 bits |
* | 0 | mainnetFlag | rollupIndex | localRootIndex |
Expand Down
3 changes: 1 addition & 2 deletions contracts/v2/PolygonZkEVMGlobalExitRootV2.sol
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import "./lib/PolygonZkEVMGlobalExitRootBaseStorage.sol";
import "../lib/GlobalExitRootLib.sol";
import "./lib/DepositContractBase.sol";

/// review Possible renaming to PolygonGlobalExitRootManager
/**
* Contract responsible for managing the exit roots across multiple networks
*/
Expand All @@ -30,7 +29,7 @@ contract PolygonZkEVMGlobalExitRootV2 is
);

/**
* @param _rollupManager Rollup contract address
* @param _rollupManager Rollup manager contract address
* @param _bridgeAddress PolygonZkEVMBridge contract address
*/
constructor(address _rollupManager, address _bridgeAddress) {
Expand Down
2 changes: 1 addition & 1 deletion contracts/v2/interfaces/IPolygonZkEVMBridgeV2.sol
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ interface IPolygonZkEVMBridgeV2 {

function wrappedTokenToTokenInfo(
address destinationAddress
) external returns (uint32, address);
) external view returns (uint32, address);

function updateGlobalExitRoot() external;

Expand Down
10 changes: 3 additions & 7 deletions contracts/v2/lib/PolygonRollupBaseEtrog.sol
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@ import "../interfaces/IPolygonZkEVMBridgeV2.sol";
import "@openzeppelin/contracts-upgradeable/token/ERC20/extensions/IERC20MetadataUpgradeable.sol";
import "./PolygonConstantsBase.sol";

// review Possible renaming to PolygonL2BaseEtrog

/**
* Contract responsible for managing the states and the updates of L2 network.
* There will be a trusted sequencer, which is able to send transactions.
Expand All @@ -28,7 +26,6 @@ contract PolygonRollupBaseEtrog is
IPolygonZkEVMVEtrogErrors,
IPolygonRollupBase
{
// Interface cehcks renaming
using SafeERC20Upgradeable for IERC20Upgradeable;

/**
Expand Down Expand Up @@ -148,7 +145,7 @@ contract PolygonRollupBaseEtrog is
// Rollup manager
PolygonRollupManager public immutable rollupManager;

// Address that will be able to adjust contract parameters or stop the emergency state
// Address that will be able to adjust contract parameters
address public admin;

// This account will be able to accept the admin role
Expand All @@ -169,7 +166,7 @@ contract PolygonRollupBaseEtrog is
// Queue of forced batches with their associated data
// ForceBatchNum --> hashedForcedBatchData
// hashedForcedBatchData: hash containing the necessary information to force a batch:
// keccak256(keccak256(bytes transactions), bytes32 globalExitRoot, unint64 minForcedTimestamp)
// keccak256(keccak256(bytes transactions), bytes32 forcedGlobalExitRoot, unint64 forcedTimestamp, bytes32 forcedBlockHashL1)
mapping(uint64 => bytes32) public forcedBatches;

// Last forced batch
Expand Down Expand Up @@ -848,15 +845,14 @@ contract PolygonRollupBaseEtrog is
* @param networkID Indicates the network identifier that will be used in the bridge
* @param _gasTokenAddress Indicates the token address that will be used to pay gas fees in the new rollup
* @param _gasTokenNetwork Indicates the native network of the token address
* @param _gasTokenMetadata Abi encoded gas token metadata
*/
function generateInitializeTransaction(
uint32 networkID,
address _gasTokenAddress,
uint32 _gasTokenNetwork,
bytes memory _gasTokenMetadata
) public view returns (bytes memory) {
// Check the ecrecover, as a sanity check, to not allow invalid transactions

bytes memory initializeBrigeData = abi.encodeCall(
IPolygonZkEVMBridgeV2.initialize,
(
Expand Down
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": 1,
"forkID": 7,
"consensusContract": "PolygonZkEVMEtrog",
"gasTokenAddress":"",
"deployerPvtKey": "",
Expand Down
4 changes: 2 additions & 2 deletions hardhat.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ const config: HardhatUserConfig = {
settings: {
optimizer: {
enabled: true,
runs: 99,
runs: 500,
},
evmVersion: "shanghai",
}, // try yul optimizer
Expand Down Expand Up @@ -121,7 +121,7 @@ const config: HardhatUserConfig = {
settings: {
optimizer: {
enabled: true,
runs: 99,
runs: 500,
},
evmVersion: "shanghai",
}, // try yul optimizer
Expand Down
6 changes: 4 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,9 @@
"saveUpgradeV2:sepolia": "mkdir -p upgrade/upgradeToV2/sepolia_$(date +%s) && cp -r upgrade/upgradeToV2/upgrade_*.json upgrade/upgradeToV2/sepolia_$(date +%s) && cp -r upgrade/upgradeToV2/deploy_*.json upgrade/upgradeToV2/sepolia_$(date +%s) && cp .openzeppelin/sepolia.json upgrade/upgradeToV2/sepolia_$(date +%s)",
"saveUpgradeV2:goerli": "mkdir -p upgrade/upgradeToV2/goerli_$(date +%s) && cp -r upgrade/upgradeToV2/upgrade_*.json upgrade/upgradeToV2/goerli_$(date +%s) && cp -r upgrade/upgradeToV2/deploy_*.json upgrade/upgradeToV2/goerli_$(date +%s) && cp .openzeppelin/goerli.json upgrade/upgradeToV2/goerli_$(date +%s)",
"upgradev2L2:timelock:polygonZKEVMTestnet": "npx hardhat run upgrade/upgradeToV2/upgradeL2ToV2.ts --network polygonZKEVMTestnet",
"upgradev2L2:timelock:polygonZKEVMMainnet": "npx hardhat run upgrade/upgradeToV2/upgradeL2ToV2.ts --network polygonZKEVMMainnet"

"upgradev2L2:timelock:polygonZKEVMMainnet": "npx hardhat run upgrade/upgradeToV2/upgradeL2ToV2.ts --network polygonZKEVMMainnet",
"upgradev2:timelock:mainnet": "npx hardhat run upgrade/upgradeToV2/upgradeToV2.ts --network mainnet && npm run saveUpgradeV2:mainnet",
"verify:upgradeV2:mainnet": "npx hardhat run upgrade/upgradeToV2/verifyContracts.ts --network mainnet",
"saveUpgradeV2:mainnet": "mkdir -p upgrade/upgradeToV2/mainnet_$(date +%s) && cp -r upgrade/upgradeToV2/upgrade_*.json upgrade/upgradeToV2/mainnet_$(date +%s) && cp -r upgrade/upgradeToV2/deploy_*.json upgrade/upgradeToV2/mainnet_$(date +%s) && cp .openzeppelin/mainnet.json upgrade/upgradeToV2/mainnet_$(date +%s)"
}
}
8 changes: 8 additions & 0 deletions test/contractsv2/PolygonRollupManager.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2210,6 +2210,10 @@ describe("Polygon Rollup Manager", () => {

await snapshotUpdateRollup.restore();

expect(await upgrades.erc1967.getImplementationAddress(newZKEVMAddress as string)).to.be.equal(
PolygonZKEVMV2Contract.target
);

await expect(rollupManagerContract.connect(timelock).updateRollup(newZKEVMAddress, etrogRollupType, "0x"))
.to.emit(rollupManagerContract, "UpdateRollup")
.withArgs(newRollupTypeID, etrogRollupType, newVerifiedBatch);
Expand All @@ -2228,6 +2232,10 @@ describe("Polygon Rollup Manager", () => {
expect(rollupDataFinal.lastVerifiedBatchBeforeUpgrade).to.be.equal(newVerifiedBatch);
expect(rollupDataFinal.rollupTypeID).to.be.equal(etrogRollupType);
expect(rollupDataFinal.rollupCompatibilityID).to.be.equal(0);

expect(await upgrades.erc1967.getImplementationAddress(newZKEVMAddress as string)).to.be.equal(
PolygonZKEVMEtrogContract.target
);
});

it("should add existing rollup and test full flow", async () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"polygonZkEVMAddress": "0x5132A183E9F3CB7C848b0AAC5Ae0c4f0491B7aB2",
"polygonZkEVMBridgeAddress": "0x2a3DD3EB832aF982ec71669E178424b10Dca2EDe",
"polygonZkEVMGlobalExitRootAddress": "0x580bda1e7A0CFAe92Fa7F6c20A3794F169CE3CFb",
"maticTokenAddress": "0x7D1AfA7B718fb893dB30A3aBc0Cfc608AaCfeBB0",
"verifierAddress": "0x4F9A0e7FD2Bf6067db6994CF12E4495Df938E6e9",
"zkEVMDeployerContract": "0xCB19eDdE626906eB1EE52357a27F62dd519608C2",
"deployerAddress": "0x7c280C055CBf830F77D6DA3a6363e961E0B91C7d",
"timelockContractAddress": "0xEf1462451C30Ea7aD8555386226059Fe837CA4EF",
"deploymentBlockNumber": 16896721,
"genesisRoot": "0x3f86b09b43e3e49a41fc20a07579b79eba044253367817d5c241d23c0e2bc5c9",
"trustedSequencer": "0x148Ee7dAF16574cD020aFa34CC658f8F3fbd2800",
"trustedSequencerURL": "https://zkevm-rpc.com/",
"chainID": 1101,
"networkName": "polygon zkEVM",
"admin": "0x242daE44F5d8fb54B198D03a94dA45B5a4413e21",
"trustedAggregator": "0xdA87c4a76922598Ac0272F4D9503a35071D686eA",
"proxyAdminAddress": "0x0F99738B2Fc14D77308337f3e2596b63aE7BCC4A",
"forkID": 4,
"salt": "0x11bbe8db4e347b4e8c937c1c8370e4b5ed33adb3db69cbdb7a38e1e50b1b82fa",
"version": "v1.1.0-fork.4"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"realVerifier": true,
"trustedSequencerURL": "https://zkevm-rpc.com/",
"networkName": "polygon zkEVM",
"version": "v1.1.0-fork.4",
"trustedSequencer": "0x148Ee7dAF16574cD020aFa34CC658f8F3fbd2800",
"chainID": 1101,
"trustedAggregator": "0xdA87c4a76922598Ac0272F4D9503a35071D686eA",
"trustedAggregatorTimeout": 432000,
"pendingStateTimeout": 432000,
"forkID": 4,
"admin": "0x242daE44F5d8fb54B198D03a94dA45B5a4413e21",
"zkEVMOwner": "0x242daE44F5d8fb54B198D03a94dA45B5a4413e21",
"timelockAddress": "0x4c1665d6651ecEfa59B9B3041951608468b18891",
"minDelayTimelock": 864000,
"salt": "0x11bbe8db4e347b4e8c937c1c8370e4b5ed33adb3db69cbdb7a38e1e50b1b82fa",
"zkEVMDeployerAddress": "0xCB19eDdE626906eB1EE52357a27F62dd519608C2",
"initialZkEVMDeployerOwner": "0x4c1665d6651ecEfa59B9B3041951608468b18891",
"maticTokenAddress": "0x7D1AfA7B718fb893dB30A3aBc0Cfc608AaCfeBB0"
}
Loading
Loading