Skip to content

Commit 0471691

Browse files
authored
Merge pull request #315 from hyperledger-labs/audit-202409-ibc-15
IBC-15: Deviations from IBC specs Signed-off-by: Jun Kimura <jun.kimura@datachain.jp>
2 parents 61c65ec + 476a6d8 commit 0471691

File tree

3 files changed

+33
-0
lines changed

3 files changed

+33
-0
lines changed

contracts/core/04-channel/IBCChannelHandshake.sol

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,10 @@ contract IBCChannelHandshake is IBCModuleManager, IIBCChannelHandshake, IIBCChan
5555
}
5656

5757
string memory channelId = generateChannelIdentifier();
58+
ChannelStorage storage channelStorage = getChannelStorage()[msg_.portId][channelId];
59+
if (channelStorage.channel.state != Channel.State.STATE_UNINITIALIZED_UNSPECIFIED) {
60+
revert IBCChannelAlreadyChannelExists();
61+
}
5862
initializeSequences(msg_.portId, channelId);
5963
emit GeneratedChannelIdentifier(channelId);
6064

@@ -130,6 +134,10 @@ contract IBCChannelHandshake is IBCModuleManager, IIBCChannelHandshake, IIBCChan
130134
);
131135

132136
string memory channelId = generateChannelIdentifier();
137+
ChannelStorage storage channelStorage = getChannelStorage()[msg_.portId][channelId];
138+
if (channelStorage.channel.state != Channel.State.STATE_UNINITIALIZED_UNSPECIFIED) {
139+
revert IBCChannelAlreadyChannelExists();
140+
}
133141
initializeSequences(msg_.portId, channelId);
134142
emit GeneratedChannelIdentifier(channelId);
135143

contracts/core/04-channel/IIBCChannelErrors.sol

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ import {Height} from "../../proto/Client.sol";
55
import {Channel} from "../../proto/Channel.sol";
66

77
interface IIBCChannelErrors {
8+
error IBCChannelAlreadyChannelExists();
9+
810
/// @param state channel state
911
error IBCChannelUnexpectedChannelState(Channel.State state);
1012

docs/architecture.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,29 @@ The `IBCHandler` is the main contract that has a storage and receives function c
4343

4444
Each contract inherits the [`IBCStore`](../contracts/core/24-host/IBCStore.sol) contract, which defines the common storage layout, and calls from the `IBCHandler` to each contract are performed using `delegatecall`. This approach allows the contracts to share common state between each other.
4545

46+
## Main deviations from IBC spec
47+
48+
Acknowledgements: We would like to acknowledge the Quantstamp audit team for pointing out these deviations.
49+
50+
The following are the main deviations from the IBC spec. Further details can be found in the audit report.
51+
52+
### authenticateCapability Function
53+
54+
Audit Report Comment:
55+
> This function does not exist in the ibc-solidity implementation as a single function, as described in the ICS specs. Instead, the owner of the `IBCHandler` contract will invoke `bindPort()` to assign module addresses to given ports in the provable store of the `IBCHandler`. Throughout connection and channel handshakes, capabilities are authenticated through functions such as `IBCModuleManager.lookupModuleByPort()` and `lookupModuleByChannel()`, which verify that a non-zero address is mapped at the port or channel. Module callback functions, such as `onRecvPacket()`, will only be invoked on the module addresses assigned by the admin.
56+
57+
### Packet Reception
58+
59+
Audit Report Comment:
60+
> Specs allow a packet to be received more than once, with just an identical event emitted. However, in the implementation, a packet cannot be received more than once; the transaction will revert.
61+
62+
We believe that this deviation is acceptable because the relayer can detect duplicated packet relay errors through the results of `estimateGas` or `debug_traceTransaction` and thereby avoid further relay.
63+
64+
### Unsupported Features
65+
66+
Audit Report Comment:
67+
> Overall, we note that ibc-solidity does not support multi-hop connections or for the `ORDERED_ALLOW_TIMEOUT` channel ordering mechanism,as described in the ICS-Specs. Therefore, all logic associated with that is not present in the ibc-solidity implementation.
68+
4669
## Store and Commitment
4770

4871
In IBC, two types of stores are defined: `provableStore` and `privateStore`. The following are the requirements for each store:

0 commit comments

Comments
 (0)