Skip to content

Commit

Permalink
update commmnets
Browse files Browse the repository at this point in the history
  • Loading branch information
invocamanman committed Jan 27, 2024
1 parent 4968a35 commit 9eeb0fb
Show file tree
Hide file tree
Showing 8 changed files with 36 additions and 30 deletions.
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
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

0 comments on commit 9eeb0fb

Please sign in to comment.