From 80048f980883caa34fd4618814c83742eadc16ca Mon Sep 17 00:00:00 2001 From: Ermyas Abebe Date: Thu, 5 Oct 2023 10:06:22 +1100 Subject: [PATCH] Add zero parameter value checks for MMR constructor --- src/MultiBridgeMessageReceiver.sol | 10 +++++++++- test/unit-tests/MultiBridgeMessageReceiver.t.sol | 12 ++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/src/MultiBridgeMessageReceiver.sol b/src/MultiBridgeMessageReceiver.sol index e9e0843..960b5ce 100644 --- a/src/MultiBridgeMessageReceiver.sol +++ b/src/MultiBridgeMessageReceiver.sol @@ -74,8 +74,16 @@ contract MultiBridgeMessageReceiver is IMultiBridgeMessageReceiver, ExecutorAwar /// @notice sets the initial parameters constructor(uint256 _srcChainId, address _gac) { - srcChainId = _srcChainId; + if (_gac == address(0)) { + revert Error.ZERO_ADDRESS_INPUT(); + } + + if (_srcChainId == 0) { + revert Error.INVALID_SENDER_CHAIN_ID(); + } + gac = IGAC(_gac); + srcChainId = _srcChainId; } /*///////////////////////////////////////////////////////////////// diff --git a/test/unit-tests/MultiBridgeMessageReceiver.t.sol b/test/unit-tests/MultiBridgeMessageReceiver.t.sol index ea2db45..f1b7e32 100644 --- a/test/unit-tests/MultiBridgeMessageReceiver.t.sol +++ b/test/unit-tests/MultiBridgeMessageReceiver.t.sol @@ -37,6 +37,18 @@ contract MultiBridgeMessageReceiverTest is Setup { timelockAddr = contractAddress[DST_CHAIN_ID]["TIMELOCK"]; } + /// @dev cannot be called with zero source chain id + function test_constructor_zero_chain_id_input() public { + vm.expectRevert(Error.INVALID_SENDER_CHAIN_ID.selector); + new MultiBridgeMessageReceiver(0, address(42)); + } + + /// @dev cannot be called with zero address GAC + function test_constructor_zero_gac_address_input() public { + vm.expectRevert(Error.ZERO_ADDRESS_INPUT.selector); + new MultiBridgeMessageReceiver(1, address(0)); + } + /// @dev receives message from one adapter function test_receive_message() public { vm.startPrank(wormholeAdapterAddr);