Skip to content

Commit

Permalink
Add missing validation in chain id mapping updates
Browse files Browse the repository at this point in the history
  • Loading branch information
ermyas committed Oct 8, 2023
1 parent f85f71e commit 8a99e67
Show file tree
Hide file tree
Showing 4 changed files with 24 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 @@ -81,6 +81,10 @@ contract AxelarSenderAdapter is BaseSenderAdapter {
}

for (uint256 i; i < arrLength;) {
if (_origIds[i] == 0) {
revert Error.ZERO_CHAIN_ID();
}

chainIdMap[_origIds[i]] = _axlIds[i];

unchecked {
Expand Down
4 changes: 4 additions & 0 deletions src/adapters/wormhole/WormholeSenderAdapter.sol
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,10 @@ contract WormholeSenderAdapter is BaseSenderAdapter {
}

for (uint256 i; i < arrLength;) {
if (_origIds[i] == 0) {
revert Error.ZERO_CHAIN_ID();
}

chainIdMap[_origIds[i]] = _whIds[i];

unchecked {
Expand Down
8 changes: 8 additions & 0 deletions test/unit-tests/adapters/axelar/AxelarSenderAdapter.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -133,4 +133,12 @@ contract AxelarSenderAdapterTest is Setup {
vm.expectRevert(Error.ARRAY_LENGTH_MISMATCHED.selector);
adapter.setChainIdMap(new uint256[](0), new string[](1));
}

/// @dev cannot set chain ID map with invalid chain ID
function test_set_chain_id_map_zero_chain_id() public {
vm.startPrank(owner);

vm.expectRevert(Error.ZERO_CHAIN_ID.selector);
adapter.setChainIdMap(new uint256[](1), new string[](1));
}
}
8 changes: 8 additions & 0 deletions test/unit-tests/adapters/wormhole/WormholeSenderAdapter.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -130,4 +130,12 @@ contract WormholeSenderAdapterTest is Setup {
vm.expectRevert(Error.ARRAY_LENGTH_MISMATCHED.selector);
adapter.setChainIdMap(new uint256[](0), new uint16[](1));
}

/// @dev cannot set chain ID map with invalid chain ID
function test_set_chain_id_map_zero_chain_id() public {
vm.startPrank(owner);

vm.expectRevert(Error.ZERO_CHAIN_ID.selector);
adapter.setChainIdMap(new uint256[](1), new uint16[](1));
}
}

0 comments on commit 8a99e67

Please sign in to comment.