Skip to content

Commit

Permalink
Review comment and add override at initialize function
Browse files Browse the repository at this point in the history
  • Loading branch information
ignasirv committed Oct 10, 2024
1 parent c95f570 commit 3e8ba6f
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 6 deletions.
5 changes: 5 additions & 0 deletions contracts/v2/interfaces/IBridgeL2SovereignChains.sol
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,11 @@ interface IBridgeL2SovereignChains is IPolygonZkEVMBridgeV2 {
*/
error InvalidSovereignWETHAddressParams();

/**
* @dev Thrown when initializing sovereign bridge with invalid sovereign WETH token params
*/
error InvalidInitializeFunction();

function initialize(
uint32 _networkID,
address _gasTokenAddress,
Expand Down
25 changes: 20 additions & 5 deletions contracts/v2/sovereignChains/BridgeL2SovereignChain.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,6 @@

pragma solidity 0.8.20;

import "@openzeppelin/contracts-upgradeable/token/ERC20/utils/SafeERC20Upgradeable.sol";
import "../../lib/TokenWrapped.sol";
import "../../interfaces/IBasePolygonZkEVMGlobalExitRoot.sol";
import "../interfaces/IBridgeL2SovereignChains.sol";
import "../PolygonZkEVMBridgeV2.sol";

Expand All @@ -28,7 +25,7 @@ contract BridgeL2SovereignChain is
/**
* @dev Emitted when a bridge manager is updated
*/
event BridgeManagerUpdated(address bridgeManager);
event SetBridgeManager(address bridgeManager);

/**
* @dev Emitted when a token address is remapped by a sovereign token address
Expand Down Expand Up @@ -138,6 +135,24 @@ contract BridgeL2SovereignChain is
__ReentrancyGuard_init();
}

/**
* @notice Override the function to prevent the contract from being initialized with this initializer
*/
function initialize(
uint32, // _networkID
address, //_gasTokenAddress
uint32, //_gasTokenNetwork
IBasePolygonZkEVMGlobalExitRoot, //_globalExitRootManager
address, //_polygonRollupManager
bytes memory //_gasTokenMetadata
)
external
override(IPolygonZkEVMBridgeV2, PolygonZkEVMBridgeV2)
initializer
{
revert InvalidInitializeFunction();
}

modifier onlyBridgeManager() {
if (bridgeManager != msg.sender) {
revert OnlyBridgeManager();
Expand All @@ -154,7 +169,7 @@ contract BridgeL2SovereignChain is
) external onlyBridgeManager {
if (_bridgeManager == address(0)) revert NotValidBridgeManager();
bridgeManager = _bridgeManager;
emit BridgeManagerUpdated(bridgeManager);
emit SetBridgeManager(bridgeManager);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion test/contractsv2/BridgeL2SovereignChain.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -429,7 +429,7 @@ describe("BridgeL2SovereignChain Contract", () => {
).to.be.revertedWithCustomError(sovereignChainBridgeContract, "OnlyBridgeManager");
// Set rollupManager as bridge manager
await expect(sovereignChainBridgeContract.connect(bridgeManager).setBridgeManager(rollupManager.address))
.to.emit(sovereignChainBridgeContract, "BridgeManagerUpdated")
.to.emit(sovereignChainBridgeContract, "SetBridgeManager")
.withArgs(rollupManager.address);

// invalid token address
Expand Down

0 comments on commit 3e8ba6f

Please sign in to comment.