Skip to content

Commit

Permalink
Add missing validations for sender adapter constructors
Browse files Browse the repository at this point in the history
  • Loading branch information
ermyas committed Oct 4, 2023
1 parent 80048f9 commit 081f51f
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/adapters/axelar/AxelarSenderAdapter.sol
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ contract AxelarSenderAdapter is BaseSenderAdapter {
CONSTRUCTOR
////////////////////////////////////////////////////////////////*/
constructor(address _gasService, address _gateway, address _gac) BaseSenderAdapter(_gac) {
if (_gasService == address(0) || _gateway == address(0)) {
revert Error.ZERO_ADDRESS_INPUT();
}

gasService = IAxelarGasService(_gasService);
gateway = IAxelarGateway(_gateway);
}
Expand Down
3 changes: 3 additions & 0 deletions src/adapters/wormhole/WormholeSenderAdapter.sol
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ contract WormholeSenderAdapter is BaseSenderAdapter {
CONSTRUCTOR
////////////////////////////////////////////////////////////////*/
constructor(address _wormholeRelayer, address _gac) BaseSenderAdapter(_gac) {
if (_wormholeRelayer == address(0)) {
revert Error.ZERO_ADDRESS_INPUT();
}
relayer = IWormholeRelayer(_wormholeRelayer);
}

Expand Down
18 changes: 18 additions & 0 deletions test/unit-tests/adapters/axelar/AxelarSenderAdapter.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,24 @@ contract AxelarSenderAdapterTest is Setup {
assertEq(address(adapter.senderGAC()), contractAddress[SRC_CHAIN_ID]["GAC"]);
}

/// @dev constructor cannot be called with zero address gas service
function test_constructor_zero_address_relayer() public {
vm.expectRevert(Error.ZERO_ADDRESS_INPUT.selector);
new AxelarSenderAdapter(address(0), address(42), address(42));
}

/// @dev constructor cannot be called with zero address gateway
function test_constructor_zero_address_gateway() public {
vm.expectRevert(Error.ZERO_ADDRESS_INPUT.selector);
new AxelarSenderAdapter(address(42), address(0), address(42));
}

/// @dev constructor cannot be called with zero address GAC
function test_constructor_zero_address_gac() public {
vm.expectRevert(Error.ZERO_ADDRESS_INPUT.selector);
new AxelarSenderAdapter(address(42), address(42), address(0));
}

/// @dev dispatches message
function test_dispatch_message() public {
vm.startPrank(senderAddr);
Expand Down
12 changes: 12 additions & 0 deletions test/unit-tests/adapters/wormhole/WormholeSenderAdapter.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,18 @@ contract WormholeSenderAdapterTest is Setup {
assertEq(address(adapter.senderGAC()), contractAddress[SRC_CHAIN_ID]["GAC"]);
}

/// @dev constructor cannot be called with zero address relayer
function test_constructor_zero_address_relayer() public {
vm.expectRevert(Error.ZERO_ADDRESS_INPUT.selector);
new WormholeSenderAdapter(address(0), address(42));
}

/// @dev constructor cannot be called with zero address GAC
function test_constructor_zero_address_gac() public {
vm.expectRevert(Error.ZERO_ADDRESS_INPUT.selector);
new WormholeSenderAdapter(address(42), address(0));
}

/// @dev dispatches message
function test_dispatch_message() public {
vm.startPrank(senderAddr);
Expand Down

0 comments on commit 081f51f

Please sign in to comment.