diff --git a/src/PolygonStateBridge.sol b/src/PolygonStateBridge.sol index fe43733..a671740 100644 --- a/src/PolygonStateBridge.sol +++ b/src/PolygonStateBridge.sol @@ -43,10 +43,12 @@ contract PolygonStateBridge is FxBaseRootTunnel, Ownable2Step { /// @notice Emitted when an attempt is made to renounce ownership. error CannotRenounceOwnership(); - /// @notice Emitted when an attempt is made to set the FxChildTunnel to the zero address. + /// @notice Emitted when an attempt is made to set the FxBaseRootTunnel, + /// FxChildTunnel, CheckpointManager or WorldIDIdentityManager addresses to the zero address. error AddressZero(); - /// @notice Emitted when an attempt is made to set the FxChildTunnel when it has already been set. + /// @notice Emitted when an attempt is made to set the FxBaseRootTunnel's + /// fxChildTunnel when it has already been set. error FxBaseRootChildTunnelAlreadySet(); /////////////////////////////////////////////////////////////////// diff --git a/src/PolygonWorldID.sol b/src/PolygonWorldID.sol index 3c0c779..5cb65ea 100644 --- a/src/PolygonWorldID.sol +++ b/src/PolygonWorldID.sol @@ -44,9 +44,14 @@ contract PolygonWorldID is WorldIDBridge, FxBaseChildTunnel, Ownable2Step { /// @notice Emitted when an attempt is made to renounce ownership. error CannotRenounceOwnership(); - /// @notice Emitted when an attempt is made to set the FxChildTunnel to the zero address. + /// @notice Emitted when an attempt is made to set the FxBaseChildTunnel or + /// the FxRoot Tunnel to the zero address. error AddressZero(); + /// @notice Emitted when an attempt is made to set the FxBaseChildTunnel's + /// fxRootTunnel when it has already been set. + error FxBaseChildRootTunnelAlreadySet(); + /////////////////////////////////////////////////////////////////////////////// /// CONSTRUCTION /// /////////////////////////////////////////////////////////////////////////////// @@ -127,7 +132,9 @@ contract PolygonWorldID is WorldIDBridge, FxBaseChildTunnel, Ownable2Step { /// /// @custom:reverts string If the root tunnel has already been set. function setFxRootTunnel(address _fxRootTunnel) external virtual override onlyOwner { - require(fxRootTunnel == address(0x0), "FxBaseChildTunnel: ROOT_TUNNEL_ALREADY_SET"); + if (fxRootTunnel != address(0)) { + revert FxBaseChildRootTunnelAlreadySet(); + } if (_fxRootTunnel == address(0x0)) { revert AddressZero(); diff --git a/src/test/PolygonStateBridge.t.sol b/src/test/PolygonStateBridge.t.sol index b3717c5..698ae15 100644 --- a/src/test/PolygonStateBridge.t.sol +++ b/src/test/PolygonStateBridge.t.sol @@ -60,7 +60,8 @@ contract PolygonStateBridgeTest is PRBTest, StdCheats { /// @notice Emitted when an attempt is made to set the FxChildTunnel to the zero address. error AddressZero(); - /// @notice Emitted when an attempt is made to set the FxChildTunnel when it has already been set. + /// @notice Emitted when an attempt is made to set the FxBaseRootTunnel's + /// fxChildTunnel when it has already been set. error FxBaseRootChildTunnelAlreadySet(); function setUp() public { @@ -196,7 +197,7 @@ contract PolygonStateBridgeTest is PRBTest, StdCheats { polygonStateBridge.setFxChildTunnel(address(0)); } - /// @notice tests that the FxChildTunnel can't be set once it has already been set + /// @notice tests that the FxBaseRootTunnel's fxChildTunnel can't be set once it has already been set function test_cannotSetFxChildTunnelMoreThanOnce_reverts(address _fxChildTunnel) public { vm.assume(_fxChildTunnel != address(0)); diff --git a/src/test/PolygonWorldID.t.sol b/src/test/PolygonWorldID.t.sol index 63e8252..01b095d 100644 --- a/src/test/PolygonWorldID.t.sol +++ b/src/test/PolygonWorldID.t.sol @@ -33,6 +33,10 @@ contract PolygonWorldIDTest is PRBTest, StdCheats { /// @notice Thrown when setFxRootTunnel is called for the first time event SetFxRootTunnel(address fxRootTunnel); + /// @notice Emitted when an attempt is made to set the FxBaseChildTunnel's + /// fxRootTunnel when it has already been set. + error FxBaseChildRootTunnelAlreadySet(); + function setUp() public { /// @notice Initialize the PolygonWorldID contract vm.prank(owner); @@ -108,6 +112,19 @@ contract PolygonWorldIDTest is PRBTest, StdCheats { new PolygonWorldID(treeDepth, address(0)); } + /// @notice tests that the FxBaseChildTunnel's fxRootTunnel can't be set once it has already been set + function test_cannotSetFxRootTunnelMoreThanOnce_reverts(address _fxRootTunnel) public { + vm.assume(_fxRootTunnel != address(0)); + + vm.prank(owner); + id.setFxRootTunnel(_fxRootTunnel); + + vm.expectRevert(FxBaseChildRootTunnelAlreadySet.selector); + + vm.prank(owner); + id.setFxRootTunnel(_fxRootTunnel); + } + /// @notice Tests that a nonPendingOwner can't accept ownership of PolygonWorldID /// @param newOwner the new owner of the contract function test_notOwner_acceptOwnership_reverts(address newOwner, address randomAddress)