Skip to content

Commit

Permalink
[ Informal Audit ] validate 0 length version in dispatcher channelope…
Browse files Browse the repository at this point in the history
…ninit
  • Loading branch information
RnkSngh committed Sep 9, 2024
1 parent 7de25a5 commit f1ade7e
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 0 deletions.
3 changes: 3 additions & 0 deletions contracts/core/Dispatcher.sol
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,9 @@ contract Dispatcher is Ownable2StepUpgradeable, UUPSUpgradeable, ReentrancyGuard
if (connectionHops.length < 2 || bytes(counterpartyPortId).length == 0) {
revert IBCErrors.invalidCounterParty();
}
if(bytes(version).length == 0) {
revert IBCErrors.invalidVersion();
}

emit ChannelOpenInit(msg.sender, version, ordering, feeEnabled, connectionHops, counterpartyPortId);
}
Expand Down
1 change: 1 addition & 0 deletions contracts/libs/IbcErrors.sol
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ library IBCErrors {
error notEnoughGas();
error invalidCharacter();
error invalidPacket();
error invalidVersion();

// packet sequence related errors.
error invalidPacketSequence();
Expand Down
13 changes: 13 additions & 0 deletions test/Dispatcher/Dispatcher.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,19 @@ abstract contract ChannelHandshakeTestSuite is ChannelHandshakeUtils {
}
}
}

function test_chanOpenInit_fail_invalidVersion() public {
// When localEnd initiates, counterparty version is only available in channelOpenAck
ChannelHandshakeSetting[8] memory settings = createSettings2(true);
for (uint256 i = 0; i < settings.length; i++) {
LocalEnd memory le = _local;
ChannelEnd memory re = _remote;
// no remote version applied in openChannel
le.versionCall = "";
vm.expectRevert(abi.encodeWithSelector(IBCErrors.invalidVersion.selector));
channelOpenInit(le, re, settings[i], false);
}
}
}

contract ChannelHandshakeTest is ChannelHandshakeTestSuite {
Expand Down

0 comments on commit f1ade7e

Please sign in to comment.