From 5a1f32542d33f78cde63981abaf5069ea9758b94 Mon Sep 17 00:00:00 2001 From: "dcbuilder.eth" Date: Thu, 7 Sep 2023 11:58:10 +0100 Subject: [PATCH 1/2] add custom error and corresponding test --- src/PolygonWorldID.sol | 7 ++++++- src/test/PolygonWorldID.t.sol | 16 ++++++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/src/PolygonWorldID.sol b/src/PolygonWorldID.sol index 3c0c779..c31673b 100644 --- a/src/PolygonWorldID.sol +++ b/src/PolygonWorldID.sol @@ -47,6 +47,9 @@ contract PolygonWorldID is WorldIDBridge, FxBaseChildTunnel, Ownable2Step { /// @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. + error FxBaseChildRootTunnelAlreadySet(); + /////////////////////////////////////////////////////////////////////////////// /// CONSTRUCTION /// /////////////////////////////////////////////////////////////////////////////// @@ -127,7 +130,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/PolygonWorldID.t.sol b/src/test/PolygonWorldID.t.sol index 63e8252..02df54a 100644 --- a/src/test/PolygonWorldID.t.sol +++ b/src/test/PolygonWorldID.t.sol @@ -33,6 +33,9 @@ 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 FxChildTunnel when it has already been set. + error FxBaseChildRootTunnelAlreadySet(); + function setUp() public { /// @notice Initialize the PolygonWorldID contract vm.prank(owner); @@ -108,6 +111,19 @@ contract PolygonWorldIDTest is PRBTest, StdCheats { new PolygonWorldID(treeDepth, address(0)); } + /// @notice tests that the 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) From 52f2c776ee18c23595ad205aec693b0b986b2438 Mon Sep 17 00:00:00 2001 From: "dcbuilder.eth" Date: Thu, 7 Sep 2023 12:17:15 +0100 Subject: [PATCH 2/2] fix natspec --- src/PolygonStateBridge.sol | 6 ++++-- src/PolygonWorldID.sol | 6 ++++-- src/test/PolygonStateBridge.t.sol | 5 +++-- src/test/PolygonWorldID.t.sol | 5 +++-- 4 files changed, 14 insertions(+), 8 deletions(-) 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 c31673b..5cb65ea 100644 --- a/src/PolygonWorldID.sol +++ b/src/PolygonWorldID.sol @@ -44,10 +44,12 @@ 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 FxChildTunnel when it has already been set. + /// @notice Emitted when an attempt is made to set the FxBaseChildTunnel's + /// fxRootTunnel when it has already been set. error FxBaseChildRootTunnelAlreadySet(); /////////////////////////////////////////////////////////////////////////////// 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 02df54a..01b095d 100644 --- a/src/test/PolygonWorldID.t.sol +++ b/src/test/PolygonWorldID.t.sol @@ -33,7 +33,8 @@ 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 FxChildTunnel when it has already been set. + /// @notice Emitted when an attempt is made to set the FxBaseChildTunnel's + /// fxRootTunnel when it has already been set. error FxBaseChildRootTunnelAlreadySet(); function setUp() public { @@ -111,7 +112,7 @@ contract PolygonWorldIDTest is PRBTest, StdCheats { new PolygonWorldID(treeDepth, address(0)); } - /// @notice tests that the FxRootTunnel can't be set once it has already been set + /// @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));