Skip to content

Commit

Permalink
Add destination chain validation
Browse files Browse the repository at this point in the history
  • Loading branch information
ermyas committed Sep 15, 2023
1 parent 2eb86d6 commit a58c217
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 9 deletions.
4 changes: 4 additions & 0 deletions src/MultiMessageSender.sol
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,10 @@ contract MultiMessageSender {
revert Error.ZERO_CHAIN_ID();
}

if (_dstChainId == block.chainid) {
revert Error.INVALID_DST_CHAIN();
}

if (_target == address(0)) {
revert Error.INVALID_TARGET();
}
Expand Down
12 changes: 6 additions & 6 deletions src/adapters/axelar/AxelarReceiverAdapter.sol
Original file line number Diff line number Diff line change
Expand Up @@ -80,16 +80,16 @@ contract AxelarReceiverAdapter is IAxelarExecutable, IMessageReceiverAdapter {
revert Error.INVALID_SENDER_CHAIN_ID();
}

/// @dev step-2: validate the contract call
if (!gateway.validateContractCall(commandId, sourceChain, sourceAddress, keccak256(payload))) {
revert Error.NOT_APPROVED_BY_GATEWAY();
}

/// @dev step-3: validate the source address
/// @dev step-2: validate the source address
if (sourceAddress.toAddress() != senderAdapter) {
revert Error.INVALID_SENDER_ADAPTER();
}

/// @dev step-3: validate the contract call
if (!gateway.validateContractCall(commandId, sourceChain, sourceAddress, keccak256(payload))) {
revert Error.NOT_APPROVED_BY_GATEWAY();
}

/// decode the cross-chain payload
AdapterPayload memory decodedPayload = abi.decode(payload, (AdapterPayload));
bytes32 msgId = decodedPayload.msgId;
Expand Down
2 changes: 1 addition & 1 deletion src/adapters/wormhole/WormholeSenderAdapter.sol
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ contract WormholeSenderAdapter is BaseSenderAdapter {
uint16 wormChainId = chainIdMap[_toChainId];

if (wormChainId == 0) {
revert Error.ZERO_CHAIN_ID();
revert Error.INVALID_DST_CHAIN();
}

msgId = _getNewMessageId(_toChainId, _to);
Expand Down
8 changes: 8 additions & 0 deletions test/unit-tests/MultiMessageSender.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,14 @@ contract MultiMessageSenderTest is Setup {
sender.remoteCall(DST_CHAIN_ID, address(42), bytes("42"), 0, invalidExpMax, excludedAdapters);
}

/// @dev dst chain cannot be the the sender chain
function test_remote_call_chain_id_is_sender_chain() public {
vm.startPrank(caller);

vm.expectRevert(Error.INVALID_DST_CHAIN.selector);
sender.remoteCall(block.chainid, address(42), bytes("42"), 0, EXPIRATION_CONSTANT);
}

/// @dev cannot call with dst chain ID of 0
function test_remote_call_zero_chain_id() public {
vm.startPrank(caller);
Expand Down
4 changes: 2 additions & 2 deletions test/unit-tests/adapters/wormhole/WormholeSenderAdapter.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ contract WormholeSenderAdapterTest is Setup {
}

/// @dev cannot dispatch message to invalid dst chain
function test_dispatch_message_zero_chain_id() public {
function test_dispatch_message_unknown_chain_id() public {
// clear chain ID map entry first
vm.startPrank(owner);
uint256[] memory origIds = new uint256[](1);
Expand All @@ -79,7 +79,7 @@ contract WormholeSenderAdapterTest is Setup {
vm.startPrank(senderAddr);
vm.deal(senderAddr, 1 ether);

vm.expectRevert(Error.ZERO_CHAIN_ID.selector);
vm.expectRevert(Error.INVALID_DST_CHAIN.selector);
adapter.dispatchMessage{value: 1 ether}(DST_CHAIN_ID, address(42), bytes("42"));
}

Expand Down

0 comments on commit a58c217

Please sign in to comment.