Skip to content

Commit

Permalink
Add remove ger function at sovereign GER contracts
Browse files Browse the repository at this point in the history
  • Loading branch information
ignasirv committed Oct 9, 2024
1 parent c277903 commit c95f570
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 9 deletions.
5 changes: 5 additions & 0 deletions contracts/interfaces/IBasePolygonZkEVMGlobalExitRoot.sol
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@ interface IBasePolygonZkEVMGlobalExitRoot {
*/
error GlobalExitRootAlreadySet();

/**
* @dev Thrown when trying to remove a global exit root that is not found
*/
error GlobalExitRootNotFound();

function updateExitRoot(bytes32 newRollupExitRoot) external;

function globalExitRootMap(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,24 +12,31 @@ contract GlobalExitRootManagerL2SovereignChain is PolygonZkEVMGlobalExitRootL2 {
*/
event InsertGlobalExitRoot(bytes32 indexed newGlobalExitRoot);

/**
* @dev Emitted when a new global exit root is removed
*/
event RemoveGlobalExitRoot(bytes32 indexed removedGlobalExitRoot);

modifier onlyCoinbase() {
// Only allowed to be called by coinbase
if (block.coinbase != msg.sender) {
revert OnlyCoinbase();
}
_;
}

/**
* @param _bridgeAddress PolygonZkEVMBridge contract address
*/
constructor(
address _bridgeAddress
) PolygonZkEVMGlobalExitRootL2( _bridgeAddress) {}
) PolygonZkEVMGlobalExitRootL2(_bridgeAddress) {}

/**
* @notice Insert a new global exit root
* @param _newRoot new global exit root
* @param _newRoot new global exit root to insert
*/
function insertGlobalExitRoot(
bytes32 _newRoot
) external {
// Only allowed to be called by coinbase
if (block.coinbase != msg.sender) {
revert OnlyCoinbase();
}
function insertGlobalExitRoot(bytes32 _newRoot) external onlyCoinbase {
// do not update timestamp if already set
if (globalExitRootMap[_newRoot] == 0) {
globalExitRootMap[_newRoot] = block.timestamp;
Expand All @@ -38,4 +45,18 @@ contract GlobalExitRootManagerL2SovereignChain is PolygonZkEVMGlobalExitRootL2 {
revert GlobalExitRootAlreadySet();
}
}

/**
* @notice Remove a global exit root
* @param _root global exit root to remove
*/
function removeGlobalExitRoot(bytes32 _root) external onlyCoinbase {
// do not update timestamp if already set
if (globalExitRootMap[_root] == 0) {
revert GlobalExitRootNotFound();
} else {
globalExitRootMap[_root] = 0;
emit RemoveGlobalExitRoot(_root);
}
}
}
16 changes: 16 additions & 0 deletions test/contractsv2/BridgeL2SovereignChain.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,22 @@ describe("BridgeL2SovereignChain Contract", () => {
// Check GER has value in mapping
expect(await sovereignChainGlobalExitRoot.globalExitRootMap(computedGlobalExitRoot)).to.not.be.eq(0);

// Remove global exit root
expect(await sovereignChainGlobalExitRoot.removeGlobalExitRoot(computedGlobalExitRoot))
.to.emit(sovereignChainGlobalExitRoot, "RemoveGlobalExitRoot")
.withArgs(computedGlobalExitRoot);

// Check GER has value in mapping
expect(await sovereignChainGlobalExitRoot.globalExitRootMap(computedGlobalExitRoot)).to.be.eq(0);

// Insert global exit root again
expect(await sovereignChainGlobalExitRoot.insertGlobalExitRoot(computedGlobalExitRoot))
.to.emit(sovereignChainGlobalExitRoot, "InsertGlobalExitRoot")
.withArgs(computedGlobalExitRoot);

// Check GER has value in mapping
expect(await sovereignChainGlobalExitRoot.globalExitRootMap(computedGlobalExitRoot)).to.not.be.eq(0);

// Remove unmapped sovereign token address, should revert
await expect(
sovereignChainBridgeContract.connect(bridgeManager).removeSovereignTokenAddress(tokenAddress)
Expand Down

0 comments on commit c95f570

Please sign in to comment.