From e986574f41d10f132723e682cdb6e7535ea1c03c Mon Sep 17 00:00:00 2001 From: "dcbuilder.eth" Date: Thu, 7 Sep 2023 11:32:24 +0100 Subject: [PATCH 1/2] minor typo fixes --- src/OpStateBridge.sol | 12 ++++++------ src/PolygonStateBridge.sol | 2 +- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/OpStateBridge.sol b/src/OpStateBridge.sol index 6b1d2b3..7125347 100644 --- a/src/OpStateBridge.sol +++ b/src/OpStateBridge.sol @@ -44,7 +44,7 @@ contract OpStateBridge is Ownable2Step { /// EVENTS /// /////////////////////////////////////////////////////////////////// - /// @notice Emitted when the the StateBridge gives ownership of the OPWorldID contract + /// @notice Emitted when the StateBridge gives ownership of the OPWorldID contract /// to the WorldID Identity Manager contract away /// @param previousOwner The previous owner of the OPWorldID contract /// @param newOwner The new owner of the OPWorldID contract @@ -54,23 +54,23 @@ contract OpStateBridge is Ownable2Step { address indexed previousOwner, address indexed newOwner, bool isLocal ); - /// @notice Emitted when the the StateBridge sends a root to the OPWorldID contract + /// @notice Emitted when the StateBridge sends a root to the OPWorldID contract /// @param root The root sent to the OPWorldID contract on the OP Stack chain event RootPropagated(uint256 root); - /// @notice Emitted when the the StateBridge sets the root history expiry for OpWorldID and PolygonWorldID + /// @notice Emitted when the StateBridge sets the root history expiry for OpWorldID and PolygonWorldID /// @param rootHistoryExpiry The new root history expiry event SetRootHistoryExpiry(uint256 rootHistoryExpiry); - /// @notice Emitted when the the StateBridge sets the gas limit for sendRootOp + /// @notice Emitted when the StateBridge sets the gas limit for sendRootOp /// @param _opGasLimit The new opGasLimit for sendRootOp event SetGasLimitPropagateRoot(uint32 _opGasLimit); - /// @notice Emitted when the the StateBridge sets the gas limit for SetRootHistoryExpiry + /// @notice Emitted when the StateBridge sets the gas limit for SetRootHistoryExpiry /// @param _opGasLimit The new opGasLimit for SetRootHistoryExpiry event SetGasLimitSetRootHistoryExpiry(uint32 _opGasLimit); - /// @notice Emitted when the the StateBridge sets the gas limit for transferOwnershipOp + /// @notice Emitted when the StateBridge sets the gas limit for transferOwnershipOp /// @param _opGasLimit The new opGasLimit for transferOwnershipOptimism event SetGasLimitTransferOwnershipOp(uint32 _opGasLimit); diff --git a/src/PolygonStateBridge.sol b/src/PolygonStateBridge.sol index 3533966..20fc176 100644 --- a/src/PolygonStateBridge.sol +++ b/src/PolygonStateBridge.sol @@ -25,7 +25,7 @@ contract PolygonStateBridge is FxBaseRootTunnel, Ownable2Step { /// EVENTS /// /////////////////////////////////////////////////////////////////// - /// @notice Emitted when the the StateBridge sets the root history expiry for OpWorldID and PolygonWorldID + /// @notice Emitted when the StateBridge sets the root history expiry for OpWorldID and PolygonWorldID /// @param rootHistoryExpiry The new root history expiry event SetRootHistoryExpiry(uint256 rootHistoryExpiry); From fecf229fd5eea23d6dffed818fbe69d6b59618f3 Mon Sep 17 00:00:00 2001 From: "dcbuilder.eth" Date: Thu, 7 Sep 2023 11:45:04 +0100 Subject: [PATCH 2/2] add custom error and corresponding test --- src/PolygonStateBridge.sol | 7 ++++++- src/test/PolygonStateBridge.t.sol | 16 ++++++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/src/PolygonStateBridge.sol b/src/PolygonStateBridge.sol index 20fc176..fe43733 100644 --- a/src/PolygonStateBridge.sol +++ b/src/PolygonStateBridge.sol @@ -46,6 +46,9 @@ contract PolygonStateBridge is FxBaseRootTunnel, 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 FxBaseRootChildTunnelAlreadySet(); + /////////////////////////////////////////////////////////////////// /// CONSTRUCTOR /// /////////////////////////////////////////////////////////////////// @@ -115,7 +118,9 @@ contract PolygonStateBridge is FxBaseRootTunnel, Ownable2Step { /// @custom:reverts string If the root tunnel has already been set. /// @custom:reverts AddressZero If the `_fxChildTunnel` is the zero address. function setFxChildTunnel(address _fxChildTunnel) public virtual override onlyOwner { - require(fxChildTunnel == address(0x0), "FxBaseRootTunnel: CHILD_TUNNEL_ALREADY_SET"); + if (fxChildTunnel != address(0x0)) { + revert FxBaseRootChildTunnelAlreadySet(); + } if (_fxChildTunnel == address(0x0)) { revert AddressZero(); diff --git a/src/test/PolygonStateBridge.t.sol b/src/test/PolygonStateBridge.t.sol index ba89f11..b3717c5 100644 --- a/src/test/PolygonStateBridge.t.sol +++ b/src/test/PolygonStateBridge.t.sol @@ -60,6 +60,9 @@ 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. + error FxBaseRootChildTunnelAlreadySet(); + function setUp() public { /// @notice Create a fork of the Ethereum mainnet mainnetFork = vm.createFork(MAINNET_RPC_URL); @@ -193,6 +196,19 @@ contract PolygonStateBridgeTest is PRBTest, StdCheats { polygonStateBridge.setFxChildTunnel(address(0)); } + /// @notice tests that the FxChildTunnel can't be set once it has already been set + function test_cannotSetFxChildTunnelMoreThanOnce_reverts(address _fxChildTunnel) public { + vm.assume(_fxChildTunnel != address(0)); + + vm.prank(owner); + polygonStateBridge.setFxChildTunnel(_fxChildTunnel); + + vm.expectRevert(FxBaseRootChildTunnelAlreadySet.selector); + + vm.prank(owner); + polygonStateBridge.setFxChildTunnel(_fxChildTunnel); + } + /// @notice tests that the StateBridge contract's ownership can't be changed by a non-owner /// @param newOwner The new owner of the StateBridge contract (foundry fuzz) function test_notOwner_transferOwnership_reverts(address nonOwner, address newOwner) public {