From c79a5d012655574ba99c505e47d8184070e12f84 Mon Sep 17 00:00:00 2001 From: Ignasi Date: Mon, 16 Sep 2024 16:10:39 +0200 Subject: [PATCH] Refactor GlobalExitRoot contracts for dovereign chains --- contracts/PolygonZkEVMGlobalExitRootL2.sol | 15 ++++++-- .../GlobalExitRootManagerL2SovereignChain.sol | 34 +++++++------------ 2 files changed, 25 insertions(+), 24 deletions(-) diff --git a/contracts/PolygonZkEVMGlobalExitRootL2.sol b/contracts/PolygonZkEVMGlobalExitRootL2.sol index 1a7bbe33c..b614b20b4 100644 --- a/contracts/PolygonZkEVMGlobalExitRootL2.sol +++ b/contracts/PolygonZkEVMGlobalExitRootL2.sol @@ -2,12 +2,16 @@ pragma solidity 0.8.20; import "./interfaces/IBasePolygonZkEVMGlobalExitRoot.sol"; +import {PolygonAccessControlUpgradeable} from "./v2/lib/PolygonAccessControlUpgradeable.sol"; /** * Contract responsible for managing the exit roots for the L2 and global exit roots * The special zkRom variables will be accessed and updated directly by the zkRom */ -contract PolygonZkEVMGlobalExitRootL2 is IBasePolygonZkEVMGlobalExitRoot { +contract PolygonZkEVMGlobalExitRootL2 is + IBasePolygonZkEVMGlobalExitRoot, + PolygonAccessControlUpgradeable +{ ///////////////////////////// // Special zkRom variables //////////////////////////// @@ -27,18 +31,25 @@ contract PolygonZkEVMGlobalExitRootL2 is IBasePolygonZkEVMGlobalExitRoot { // PolygonZkEVM Bridge address address public immutable bridgeAddress; + /** + * @dev This empty reserved space is put in place to allow future versions to add new + * variables without shifting down storage in the inheritance chain. + */ + uint256[50] private _gap; + /** * @param _bridgeAddress PolygonZkEVMBridge contract address */ constructor(address _bridgeAddress) { bridgeAddress = _bridgeAddress; + _disableInitializers(); } /** * @notice Update the exit root of one of the networks and the global exit root * @param newRoot new exit tree root */ - function updateExitRoot(bytes32 newRoot) external { + function updateExitRoot(bytes32 newRoot) external virtual { if (msg.sender != bridgeAddress) { revert OnlyAllowedContracts(); } diff --git a/contracts/v2/sovereignChains/GlobalExitRootManagerL2SovereignChain.sol b/contracts/v2/sovereignChains/GlobalExitRootManagerL2SovereignChain.sol index f798c75cc..bef63dbb0 100644 --- a/contracts/v2/sovereignChains/GlobalExitRootManagerL2SovereignChain.sol +++ b/contracts/v2/sovereignChains/GlobalExitRootManagerL2SovereignChain.sol @@ -3,36 +3,17 @@ pragma solidity 0.8.20; import "../../interfaces/IBasePolygonZkEVMGlobalExitRoot.sol"; import {PolygonAccessControlUpgradeable} from "../lib/PolygonAccessControlUpgradeable.sol"; +import "../../PolygonZkEVMGlobalExitRootL2.sol"; /** * Contract responsible for managing the exit roots for the Sovereign chains and global exit roots */ -contract GlobalExitRootManagerL2SovereignChain is - PolygonAccessControlUpgradeable, - IBasePolygonZkEVMGlobalExitRoot -{ - // Store every global exit root: Root --> timestamp - mapping(bytes32 => uint256) public globalExitRootMap; - - // Rollup exit root will be updated for every Sovereign chain call - bytes32 public lastRollupExitRoot; - - // Sovereign chain Bridge address - address public immutable bridgeAddress; - +contract GlobalExitRootManagerL2SovereignChain is PolygonZkEVMGlobalExitRootL2 { /** * @dev Emitted when a new global exit root is inserted */ event InsertGlobalExitRoot(bytes32 indexed newGlobalExitRoot); - /** - * @param _bridgeAddress BridgeL2SovereignChain contract address - */ - constructor(address _bridgeAddress) { - bridgeAddress = _bridgeAddress; - _disableInitializers(); - } - /** * @notice Only allows a function to be callable if its called by coinbase (trusted sequencer in sovereign chains) */ @@ -53,11 +34,20 @@ contract GlobalExitRootManagerL2SovereignChain is _; } + /** + * @param _bridgeAddress PolygonZkEVMBridge contract address + */ + constructor( + address _bridgeAddress + ) PolygonZkEVMGlobalExitRootL2(_bridgeAddress) {} + /** * @notice Update the exit root of one of the networks and the global exit root * @param newRoot new exit tree root */ - function updateExitRoot(bytes32 newRoot) external onlyBridgeAddress() { + function updateExitRoot( + bytes32 newRoot + ) external override onlyBridgeAddress { lastRollupExitRoot = newRoot; }