Skip to content

Commit

Permalink
feat: add rollup manager verification
Browse files Browse the repository at this point in the history
Signed-off-by: JDawg287 <[email protected]>
  • Loading branch information
JDawg287 committed Aug 21, 2024
1 parent 4b913ee commit c0c7c8b
Show file tree
Hide file tree
Showing 2 changed files with 99 additions and 8 deletions.
105 changes: 98 additions & 7 deletions script/DeployContracts.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,26 @@ import {IPolygonZkEVMGlobalExitRootV2} from "contracts/interfaces/IPolygonZkEVMG
contract DeployContracts is Script {
using stdJson for string;

bytes32 constant DEFAULT_ADMIN_ROLE = bytes32(0);
bytes32 constant ADD_ROLLUP_TYPE_ROLE = keccak256("ADD_ROLLUP_TYPE_ROLE");
bytes32 constant OBSOLETE_ROLLUP_TYPE_ROLE =
keccak256("OBSOLETE_ROLLUP_TYPE_ROLE");
bytes32 constant CREATE_ROLLUP_ROLE = keccak256("CREATE_ROLLUP_ROLE");
bytes32 constant ADD_EXISTING_ROLLUP_ROLE =
keccak256("ADD_EXISTING_ROLLUP_ROLE");
bytes32 constant UPDATE_ROLLUP_ROLE = keccak256("UPDATE_ROLLUP_ROLE");
bytes32 constant TRUSTED_AGGREGATOR_ROLE =
keccak256("TRUSTED_AGGREGATOR_ROLE");
bytes32 constant TRUSTED_AGGREGATOR_ROLE_ADMIN =
keccak256("TRUSTED_AGGREGATOR_ROLE_ADMIN");
bytes32 constant TWEAK_PARAMETERS_ROLE = keccak256("TWEAK_PARAMETERS_ROLE");
bytes32 constant SET_FEE_ROLE = keccak256("SET_FEE_ROLE");
bytes32 constant STOP_EMERGENCY_ROLE = keccak256("STOP_EMERGENCY_ROLE");
bytes32 constant EMERGENCY_COUNCIL_ROLE =
keccak256("EMERGENCY_COUNCIL_ROLE");
bytes32 constant EMERGENCY_COUNCIL_ADMIN =
keccak256("EMERGENCY_COUNCIL_ADMIN");

address constant GAS_TOKEN_ADDR_MAINNET = address(0);
uint256 constant NETWORK_ID_MAINNET = 0;
uint256 constant GAS_TOKEN_NETWORK_MAINNET = 0;
Expand Down Expand Up @@ -65,7 +85,11 @@ contract DeployContracts is Script {
computedRollupManagerAddress,
bridgeProxy
);
_deployRollupManager(globalExitRootManager, bridgeProxy);
address rolluplManagerAddr = _deployRollupManager(
globalExitRootManager,
bridgeProxy
);
_verifyRollupManager(rolluplManagerAddr, bridgeProxy);
}

function loadConfig() public {
Expand Down Expand Up @@ -259,12 +283,13 @@ contract DeployContracts is Script {
address bridgeAddr
) internal returns (address) {
vm.startBroadcast(deployerPvtKey);
PolygonZkEVMGlobalExitRootV2 globalExitRootManagerImpl = new PolygonZkEVMGlobalExitRootV2(
PolygonZkEVMGlobalExitRootV2 globalExitRootManager = new PolygonZkEVMGlobalExitRootV2(
rollupManagerAddr,
bridgeAddr
);
address globalExitRootManagerProxy = _proxify(
address(globalExitRootManagerImpl)
address(globalExitRootManager),
""
);
vm.stopBroadcast();

Expand All @@ -282,12 +307,27 @@ contract DeployContracts is Script {
address bridgeAddr
) internal returns (address) {
vm.startBroadcast(deployerPvtKey);
PolygonRollupManagerNotUpgraded rollupManagerImpl = new PolygonRollupManagerNotUpgraded(
PolygonRollupManagerNotUpgraded rollupManager = new PolygonRollupManagerNotUpgraded(
IPolygonZkEVMGlobalExitRootV2(globalExitRootManagerAddr),
IERC20Upgradeable(polTokenAddress),
IPolygonZkEVMBridge(bridgeAddr)
);
address rollupManagerProxy = _proxify(address(rollupManagerImpl));
address rollupManagerProxy = _proxify(
address(rollupManager),
abi.encodeWithSelector(
rollupManager.initialize.selector,
trustedAggregator,
pendingStateTimeout,
trustedAggregatorTimeout,
admin,
timelockAdminAddress,
emergencyCouncilAddress,
bytes32(0),
bytes32(0),
0,
0
)
);
vm.stopBroadcast();

console.log("\n----------------------\n");
Expand All @@ -296,6 +336,54 @@ contract DeployContracts is Script {
return rollupManagerProxy;
}

function _verifyRollupManager(
address rolluplManagerAddr,
address bridgeProxyAddr
) internal view {
PolygonRollupManagerNotUpgraded rollupManager = PolygonRollupManagerNotUpgraded(
rolluplManagerAddr
);
assert(
address(rollupManager.globalExitRootManager()) ==
computedGlobalExitRootManagerAddress
);
assert(address(rollupManager.bridgeAddress()) == bridgeProxyAddr);
assert(address(rollupManager.pol()) == polTokenAddress);

assert(rollupManager.hasRole(DEFAULT_ADMIN_ROLE, timelockAdminAddress));
assert(
rollupManager.hasRole(ADD_ROLLUP_TYPE_ROLE, timelockAdminAddress)
);
assert(
rollupManager.hasRole(
ADD_EXISTING_ROLLUP_ROLE,
timelockAdminAddress
)
);
assert(rollupManager.hasRole(UPDATE_ROLLUP_ROLE, timelockAdminAddress));
assert(rollupManager.hasRole(OBSOLETE_ROLLUP_TYPE_ROLE, admin));
assert(rollupManager.hasRole(CREATE_ROLLUP_ROLE, admin));
assert(rollupManager.hasRole(STOP_EMERGENCY_ROLE, admin));
assert(rollupManager.hasRole(TWEAK_PARAMETERS_ROLE, admin));
assert(
rollupManager.hasRole(TRUSTED_AGGREGATOR_ROLE, trustedAggregator)
);
assert(rollupManager.hasRole(TRUSTED_AGGREGATOR_ROLE_ADMIN, admin));
assert(rollupManager.hasRole(SET_FEE_ROLE, admin));
assert(
rollupManager.hasRole(
EMERGENCY_COUNCIL_ROLE,
emergencyCouncilAddress
)
);
assert(
rollupManager.hasRole(
EMERGENCY_COUNCIL_ADMIN,
emergencyCouncilAddress
)
);
}

function _computeDeployAddresses() internal {
uint256 nonceProxyGlobalExitRootManager = vm.getNonce(
vm.addr(deployerPvtKey)
Expand All @@ -313,11 +401,14 @@ contract DeployContracts is Script {
);
}

function _proxify(address logic) internal returns (address proxy) {
function _proxify(
address logic,
bytes memory data
) internal returns (address proxy) {
TransparentUpgradeableProxy proxy_ = new TransparentUpgradeableProxy(
logic,
msg.sender,
""
data
);
return (address(proxy_));
}
Expand Down
2 changes: 1 addition & 1 deletion script/inputs/deployParameters.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"polTokenAddress": "0x0000000000000000000000000000000000000000",
"salt": "0x0000000000000000000000000000000000000000000000000000000000000000",
"timelockAdminAddress": "0x9Ab254be10F6Df45E5c58Ba2cE6CB3c9a1aff954",
"trustedAggregator": "0x0000000000000000000000000000000000000000",
"trustedAggregator": "0x9Ab254be10F6Df45E5c58Ba2cE6CB3c9a1aff954",
"trustedAggregatorTimeout": 604799,
"zkEVMDeployerAddress": "0x68dA8647cD6e61f87e868e55b6Db96507b904019"
}

0 comments on commit c0c7c8b

Please sign in to comment.