Skip to content

Commit

Permalink
Merge pull request #107 from worldcoin/dcbuild3r/minor-fixes
Browse files Browse the repository at this point in the history
minor audit fixes
  • Loading branch information
dcbuild3r authored Sep 7, 2023
2 parents 5e65dd0 + fecf229 commit 26da155
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 8 deletions.
12 changes: 6 additions & 6 deletions src/OpStateBridge.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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);

Expand Down
9 changes: 7 additions & 2 deletions src/PolygonStateBridge.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand All @@ -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 ///
///////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -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();
Expand Down
16 changes: 16 additions & 0 deletions src/test/PolygonStateBridge.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit 26da155

Please sign in to comment.