diff --git a/contracts/v2/PolygonRollupManager.sol b/contracts/v2/PolygonRollupManager.sol index 7cd32139c..dd8240b9c 100644 --- a/contracts/v2/PolygonRollupManager.sol +++ b/contracts/v2/PolygonRollupManager.sol @@ -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, @@ -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 @@ -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 @@ -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); @@ -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 @@ -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( @@ -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 @@ -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 { @@ -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 @@ -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 diff --git a/contracts/v2/PolygonZkEVMBridgeV2.sol b/contracts/v2/PolygonZkEVMBridgeV2.sol index 9e1c86624..8f88fa8e5 100644 --- a/contracts/v2/PolygonZkEVMBridgeV2.sol +++ b/contracts/v2/PolygonZkEVMBridgeV2.sol @@ -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 @@ -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, @@ -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 | @@ -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 | diff --git a/contracts/v2/PolygonZkEVMGlobalExitRootV2.sol b/contracts/v2/PolygonZkEVMGlobalExitRootV2.sol index f0c8da74b..824ac3e8f 100644 --- a/contracts/v2/PolygonZkEVMGlobalExitRootV2.sol +++ b/contracts/v2/PolygonZkEVMGlobalExitRootV2.sol @@ -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 */ @@ -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) { diff --git a/contracts/v2/interfaces/IPolygonZkEVMBridgeV2.sol b/contracts/v2/interfaces/IPolygonZkEVMBridgeV2.sol index 389ef54dd..aab8c6af8 100644 --- a/contracts/v2/interfaces/IPolygonZkEVMBridgeV2.sol +++ b/contracts/v2/interfaces/IPolygonZkEVMBridgeV2.sol @@ -91,7 +91,7 @@ interface IPolygonZkEVMBridgeV2 { function wrappedTokenToTokenInfo( address destinationAddress - ) external returns (uint32, address); + ) external view returns (uint32, address); function updateGlobalExitRoot() external; diff --git a/contracts/v2/lib/PolygonRollupBaseEtrog.sol b/contracts/v2/lib/PolygonRollupBaseEtrog.sol index 89da97fc2..09c59e003 100644 --- a/contracts/v2/lib/PolygonRollupBaseEtrog.sol +++ b/contracts/v2/lib/PolygonRollupBaseEtrog.sol @@ -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. @@ -28,7 +26,6 @@ contract PolygonRollupBaseEtrog is IPolygonZkEVMVEtrogErrors, IPolygonRollupBase { - // Interface cehcks renaming using SafeERC20Upgradeable for IERC20Upgradeable; /** @@ -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 @@ -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 @@ -848,6 +845,7 @@ 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, @@ -855,8 +853,6 @@ contract PolygonRollupBaseEtrog is 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, ( diff --git a/deployment/v2/create_rollup_parameters.json.example b/deployment/v2/create_rollup_parameters.json.example index dc6dd2f8e..c37fbcdd4 100644 --- a/deployment/v2/create_rollup_parameters.json.example +++ b/deployment/v2/create_rollup_parameters.json.example @@ -6,7 +6,7 @@ "trustedSequencer":"0x617b3a3528F9cDd6630fd3301B9c8911F7Bf063D", "chainID": 1001, "adminZkEVM":"0x617b3a3528F9cDd6630fd3301B9c8911F7Bf063D", - "forkID": 1, + "forkID": 7, "consensusContract": "PolygonZkEVMEtrog", "gasTokenAddress":"", "deployerPvtKey": "", diff --git a/hardhat.config.ts b/hardhat.config.ts index 51fb887b6..30d4cdf4c 100644 --- a/hardhat.config.ts +++ b/hardhat.config.ts @@ -80,7 +80,7 @@ const config: HardhatUserConfig = { settings: { optimizer: { enabled: true, - runs: 99, + runs: 500, }, evmVersion: "shanghai", }, // try yul optimizer @@ -121,7 +121,7 @@ const config: HardhatUserConfig = { settings: { optimizer: { enabled: true, - runs: 99, + runs: 500, }, evmVersion: "shanghai", }, // try yul optimizer diff --git a/test/contractsv2/PolygonRollupManager.test.ts b/test/contractsv2/PolygonRollupManager.test.ts index 2d814532a..2eaec4d78 100644 --- a/test/contractsv2/PolygonRollupManager.test.ts +++ b/test/contractsv2/PolygonRollupManager.test.ts @@ -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); @@ -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 () => {