Skip to content

Commit

Permalink
Refactor GlobalExitRoot contracts for dovereign chains
Browse files Browse the repository at this point in the history
  • Loading branch information
ignasirv committed Sep 16, 2024
1 parent 6a40828 commit c79a5d0
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 24 deletions.
15 changes: 13 additions & 2 deletions contracts/PolygonZkEVMGlobalExitRootL2.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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
////////////////////////////
Expand All @@ -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();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
*/
Expand All @@ -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;
}

Expand Down

0 comments on commit c79a5d0

Please sign in to comment.