Synopsis
The “channel” abstraction provides message delivery semantics to the interblockchain communication protocol, in three categories: ordering, exactly-once delivery, and module permissioning. A channel serves as a conduit for packets passing between a module on one chain and a module on another, ensuring that packets are executed only once, delivered in the order in which they were sent (if necessary), and delivered only to the corresponding module owning the other end of the channel on the destination chain. Each channel is associated with a particular connection, and a connection may have any number of associated channels, allowing the use of common identifiers and amortising the cost of header verification across all the channels utilising a connection & light client. Channels are payload-agnostic. The modules which send and receive IBC packets decide how to construct packet data and how to act upon the incoming packet data, and must utilise their own application logic to determine which state transactions to apply according to what data the packet contains.Motivation
The interblockchain communication protocol uses a cross-chain message passing model. IBC packets are relayed from one blockchain to the other by external relayer processes. ChainA and chain B confirm new blocks independently, and packets from one chain to the other may be delayed, censored, or re-ordered arbitrarily. Packets are visible to relayers and can be read from a blockchain by any relayer process and submitted to any other blockchain.
The IBC protocol must provide ordering (for ordered channels) and exactly-once delivery guarantees to allow applications to reason about the combined state of connected modules on two chains.
Example: An application may wish to allow a single tokenized asset to be transferred between and held on multiple blockchains while preserving fungibility and conservation of supply. The application can mint asset vouchers on chainIn order to provide the desired ordering, exactly-once delivery, and module permissioning semantics to the application layer, the interblockchain communication protocol must implement an abstraction to enforce these semantics — channels are this abstraction.Bwhen a particular IBC packet is committed to chainB, and require outgoing sends of that packet on chainAto escrow an equal amount of the asset on chainAuntil the vouchers are later redeemed back to chainAwith an IBC packet in the reverse direction. This ordering guarantee along with correct application logic can ensure that total supply is preserved across both chains and that any vouchers minted on chainBcan later be redeemed back to chainA.
Definitions
ConsensusState is as defined in ICS 2.
Connection is as defined in ICS 3.
Port and authenticateCapability are as defined in ICS 5.
hash is a generic collision-resistant hash function, the specifics of which must be agreed on by the modules utilising the channel. hash can be defined differently by different chains.
Identifier, get, set, delete, getCurrentHeight, and module-system related primitives are as defined in ICS 24.
See upgrades spec for definition of pendingInflightPackets and restoreChannel.
A channel is a pipeline for exactly-once packet delivery between specific modules on separate blockchains, which has at least one end capable of sending packets and one end capable of receiving packets.
A bidirectional channel is a channel where packets can flow in both directions: from A to B and from B to A.
A unidirectional channel is a channel where packets can only flow in one direction: from A to B (or from B to A, the order of naming is arbitrary).
An ordered channel is a channel where packets are delivered exactly in the order which they were sent. This channel type offers a very strict guarantee of ordering. Either, the packets are received in the order they were sent, or if a packet in the sequence times out; then all future packets are also not receivable and the channel closes.
An ordered_allow_timeout channel is a less strict version of the ordered channel. Here, the channel logic will take a best effort approach to delivering the packets in order. In a stream of packets, the channel will relay all packets in order and if a packet in the stream times out, the timeout logic for that packet will execute and the rest of the later packets will continue processing in order. Thus, we do not close the channel on a timeout with this channel type.
An unordered channel is a channel where packets can be delivered in any order, which may differ from the order in which they were sent.
- The
stateis the current state of the channel end. - The
orderingfield indicates whether the channel isunordered,ordered, orordered_allow_timeout. - The
counterpartyPortIdentifieridentifies the port on the counterparty chain which owns the other end of the channel. - The
counterpartyChannelIdentifieridentifies the channel end on the counterparty chain. - The
nextSequenceSend, stored separately, tracks the sequence number for the next packet to be sent. - The
nextSequenceRecv, stored separately, tracks the sequence number for the next packet to be received. - The
nextSequenceAck, stored separately, tracks the sequence number for the next packet to be acknowledged. - The
connectionHopsstores the list of connection identifiers ordered starting from the receiving end towards the sender.connectionHops[0]is the connection end on the receiving chain. More than one connection hop indicates a multi-hop channel. - The
versionstring stores an opaque channel version, which is agreed upon during the handshake. This can determine module-level configuration such as which packet encoding is used for the channel. This version is not used by the core IBC protocol. If the version string contains structured metadata for the application to parse and interpret, then it is considered best practice to encode all metadata in a JSON struct and include the marshalled string in the version field.
upgradeSequence.
Channel ends have a state:
- A channel end in
INITstate has just started the opening handshake. - A channel end in
TRYOPENstate has acknowledged the handshake step on the counterparty chain. - A channel end in
OPENstate has completed the handshake and is ready to send and receive packets. - A channel end in
CLOSEDstate has been closed and can no longer be used to send or receive packets.
FLUSHING and FLUSHCOMPLETE.
A Packet, in the interblockchain communication protocol, is a particular interface defined as follows:
- The
sequencenumber corresponds to the order of sends and receives, where a packet with an earlier sequence number must be sent and received before a packet with a later sequence number. - The
timeoutHeightindicates a consensus height on the destination chain after which the packet will no longer be processed, and will instead count as having timed-out. - The
timeoutTimestampindicates a timestamp on the destination chain after which the packet will no longer be processed, and will instead count as having timed-out. - The
sourcePortidentifies the port on the sending chain. - The
sourceChannelidentifies the channel end on the sending chain. - The
destPortidentifies the port on the receiving chain. - The
destChannelidentifies the channel end on the receiving chain. - The
datais an opaque value which can be defined by the application logic of the associated modules.
Packet is never directly serialised. Rather it is an intermediary structure used in certain function calls that may need to be created or processed by modules calling the IBC handler.
An OpaquePacket is a packet, but cloaked in an obscuring data type by the host state machine, such that a module cannot act upon it other than to pass it to the IBC handler. The IBC handler can cast a Packet to an OpaquePacket and vice versa.
recvPacket.
Desired Properties
Efficiency
- The speed of packet transmission and confirmation should be limited only by the speed of the underlying chains. Proofs should be batchable where possible.
Exactly-once delivery
- IBC packets sent on one end of a channel should be delivered exactly once to the other end.
- No network synchrony assumptions should be required for exactly-once safety. If one or both of the chains halt, packets may be delivered no more than once, and once the chains resume packets should be able to flow again.
Ordering
- On ordered channels, packets should be sent and received in the same order: if packet x is sent before packet y by a channel end on chain
A, packet x must be received before packet y by the corresponding channel end on chainB. If packet x is sent before packet y by a channel and packet x is timed out; then packet y and any packet sent after x cannot be received. - On ordered_allow_timeout channels, packets should be sent and received in the same order: if packet x is sent before packet y by a channel end on chain
A, packet x must be received or timed out before packet y by the corresponding channel end on chainB. - On unordered channels, packets may be sent and received in any order. Unordered packets, like ordered packets, have individual timeouts specified in terms of the destination chain’s height.
Permissioning
- Channels should be permissioned to one module on each end, determined during the handshake and immutable afterwards (higher-level logic could tokenize channel ownership by tokenising ownership of the port). Only the module associated with a channel end should be able to send or receive on it.
Technical Specification
Dataflow visualisation
The architecture of clients, connections, channels and packets:
Preliminaries
Store paths
Channel structures are stored under a store path prefix unique to a combination of a port identifier and channel identifier:channelCapabilityPath:
nextSequenceSend, nextSequenceRecv, and nextSequenceAck unsigned integer counters are stored separately so they can be proved individually:
packetReceiptPath. In the case of a successful receive, the destination chain writes a sentinel success value of SUCCESSFUL_RECEIPT.
Some channel types MAY write a sentinel timeout value TIMEOUT_RECEIPT if the packet is received after the specified timeout.
packetAcknowledgementPath:
Versioning
During the handshake process, two ends of a channel come to agreement on a version bytestring associated with that channel. The contents of this version bytestring are and will remain opaque to the IBC core protocol. Host state machines MAY utilise the version data to indicate supported IBC/APP protocols, agree on packet encoding formats, or negotiate other channel-related metadata related to custom logic on top of IBC. Host state machines MAY also safely ignore the version data or specify an empty string.Sub-protocols
Note: If the host state machine is utilising object capability authentication (see ICS 005), all functions utilising ports take an additional capability parameter.
Identifier validation
Channels are stored under a unique(portIdentifier, channelIdentifier) prefix.
The validation function validatePortIdentifier MAY be provided.
validateChannelIdentifier function will always return true.
Channel lifecycle management
| Initiator | Datagram | Chain acted upon | Prior state (A, B) | Posterior state (A, B) |
|---|---|---|---|---|
| Actor | ChanOpenInit | A | (none, none) | (INIT, none) |
| Relayer | ChanOpenTry | B | (INIT, none) | (INIT, TRYOPEN) |
| Relayer | ChanOpenAck | A | (INIT, TRYOPEN) | (OPEN, TRYOPEN) |
| Relayer | ChanOpenConfirm | B | (OPEN, TRYOPEN) | (OPEN, OPEN) |
| Initiator | Datagram | Chain acted upon | Prior state (A, B) | Posterior state (A, B) |
|---|---|---|---|---|
| Actor | ChanCloseInit | A | (OPEN, OPEN) | (CLOSED, OPEN) |
| Relayer | ChanCloseConfirm | B | (CLOSED, OPEN) | (CLOSED, CLOSED) |
| Actor | ChanCloseFrozen | A or B | (OPEN, OPEN) | (CLOSED, CLOSED) |
Opening handshake
ThechanOpenInit function is called by a module to initiate a channel opening handshake with a module on another chain. Functions chanOpenInit and chanOpenTry do no set the new channel end in state because the channel version might be modified by the application callback. A function writeChannel should be used to write the channel end in state after executing the application callback:
handleChanOpenInit and handleChanOpenTry in Channel lifecycle management for more details.
The opening channel must provide the identifiers of the local channel identifier, local port, remote port, and remote channel identifier.
When the opening handshake is complete, the module which initiates the handshake will own the end of the created channel on the host ledger, and the counterparty module which
it specifies will own the other end of the created channel on the counterparty chain. Once a channel is created, ownership cannot be changed (although higher-level abstractions
could be implemented to provide this).
Chains MUST implement a function generateIdentifier which chooses an identifier, e.g. by incrementing a counter:
chanOpenTry function is called by a module to accept the first step of a channel opening handshake initiated by a module on another chain.
chanOpenAck is called by the handshake-originating module to acknowledge the acceptance of the initial request by the
counterparty module on the other chain.
chanOpenConfirm function is called by the handshake-accepting module to acknowledge the acknowledgement
of the handshake-originating module on the other chain and finish the channel opening handshake.
Closing handshake
ThechanCloseInit function is called by either module to close their end of the channel. Once closed, channels cannot be reopened.
Calling modules MAY atomically execute appropriate application logic in conjunction with calling chanCloseInit.
Any in-flight packets can be timed-out as soon as a channel is closed.
chanCloseConfirm function is called by the counterparty module to close their end of the channel,
since the other end has been closed.
Calling modules MAY atomically execute appropriate application logic in conjunction with calling chanCloseConfirm.
Once closed, channels cannot be reopened and identifiers cannot be reused. Identifier reuse is prevented because
we want to prevent potential replay of previously sent packets. The replay problem is analogous to using sequence
numbers with signed messages, except where the light client algorithm “signs” the messages (IBC packets), and the replay
prevention sequence is the combination of port identifier, channel identifier, and packet sequence - hence we cannot
allow the same port identifier & channel identifier to be reused again with a sequence reset to zero, since this
might allow packets to be replayed. It would be possible to safely reuse identifiers if timeouts of a particular
maximum height/time were mandated & tracked, and future specification versions may incorporate this feature.
chanCloseFrozen function is called by a relayer to force close a multi-hop channel if any client state in the
channel path is frozen. A relayer should send proof of the frozen client state to each end of the channel with a
proof of the frozen client state in the channel path starting from each channel end up until the first frozen client.
The multi-hop proof for each channel end will be different and consist of a proof formed starting from each channel
end up to the frozen client.
The multi-hop proof starts with a chain with a frozen client for the misbehaving chain. However, the frozen client exists
on the next blockchain in the channel path so the key/value proof is indexed to evaluate on the consensus state holding
that client state. The client state path requires knowledge of the client id which can be determined from the
connectionEnd on the misbehaving chain prior to the misbehavior submission.
Once frozen, it is possible for a channel to be unfrozen (reactivated) via governance processes once the misbehavior in
the channel path has been resolved. However, this process is out-of-protocol.
Example:
Given a multi-hop channel path over connections from chain A to chain E and misbehaving chain C
A <--> B <--x C x--> D <--> E
Assume any relayer submits evidence of misbehavior to chain B and chain D to freeze their respective clients for chain C.
A relayer may then provide a multi-hop proof of the frozen client on chain B to chain A to close the channel on chain A, and another relayer (or the same one) may also relay a multi-hop proof of the frozen client on chain D to chain E to close the channel end on chain E.
However, it must also be proven that the frozen client state corresponds to a specific hop in the channel path.
Therefore, a proof of the connection end on chain B with counterparty connection end on chain C must also be provided along with the client state proof to prove that the clientID for the client state matches the clientID in the connection end. Furthermore, the connectionID for the connection end MUST match the expected ID from the channel’s connectionHops field.
Multihop utility functions
Packet flow & handling
A day in the life of a packet
The following sequence of steps must occur for a packet to be sent from module 1 on machine A to module 2 on machine B, starting from scratch. The module can interface with the IBC handler through ICS 25 or ICS 26.- Initial client & port setup, in any order
- Establishment of a connection & channel, optimistic send, in order
- Connection opening handshake started from A to B by module 1 (see ICS 3)
- Channel opening handshake started from 1 to 2 using the newly created connection (this ICS)
- Packet sent over the newly created channel from 1 to 2 (this ICS)
- Successful completion of handshakes (if either handshake fails, the connection/channel can be closed & the packet timed-out)
- Connection opening handshake completes successfully (see ICS 3) (this will require participation of a relayer process)
- Channel opening handshake completes successfully (this ICS) (this will require participation of a relayer process)
- Packet confirmation on machine B, module 2 (or packet timeout if the timeout height has passed) (this will require participation of a relayer process)
- Acknowledgement (possibly) relayed back from module 2 on machine B to module 1 on machine A
Sending packets
ThesendPacket function is called by a module in order to send data (in the form of an IBC packet) on a channel end owned by the calling module.
Calling modules MUST execute application logic atomically in conjunction with calling sendPacket.
The IBC handler performs the following steps in order:
- Checks that the channel is opened to send packets
- Checks that the calling module owns the sending port (see ICS 5)
- Checks that the timeout height specified has not already passed on the destination chain
- Increments the send sequence counter associated with the channel
- Stores a constant-size commitment to the packet data & packet timeout
- Returns the sequence number of the sent packet
Receiving packets
TherecvPacket function is called by a module in order to receive an IBC packet sent on the corresponding channel end on the counterparty chain.
Atomically in conjunction with calling recvPacket, calling modules MUST either execute application logic or queue the packet for future execution.
The IBC handler performs the following steps in order:
- Checks that the channel & connection are open to receive packets
- Checks that the calling module owns the receiving port
- Checks that the packet metadata matches the channel & connection information
- Checks that the packet sequence is the next sequence the channel end expects to receive (for ordered and ordered_allow_timeout channels)
- Checks that the timeout height and timestamp have not yet passed
- Checks the inclusion proof of packet data commitment in the outgoing chain’s state
- Optionally (in case channel upgrades and deletion of acknowledgements and packet receipts are implemented): reject any packet with a sequence already used before a successful channel upgrade
- Sets a store path to indicate that the packet has been received (unordered channels only)
- Increments the packet receive sequence associated with the channel end (ordered and ordered_allow_timeout channels only)
relayer that signed and submitted the packet to enable a module to optionally provide some rewards. This provides a foundation for fee payment, but can be used for other techniques as well (like calculating a leaderboard).
Writing acknowledgements
ThewriteAcknowledgement function is called by a module in order to write data which resulted from processing an IBC packet that the sending chain can then verify, a sort of “execution receipt” or “RPC call response”.
Calling modules MUST execute application logic atomically in conjunction with calling writeAcknowledgement.
This is an asynchronous acknowledgement, the contents of which do not need to be determined when the packet is received, only when processing is complete. In the synchronous case, writeAcknowledgement can be called in the same transaction (atomically) with recvPacket.
Acknowledging packets is not required; however, if an ordered channel uses acknowledgements, either all or no packets must be acknowledged (since the acknowledgements are processed in order). Note that if packets are not acknowledged, packet commitments cannot be deleted on the source chain. Future versions of IBC may include ways for modules to specify whether or not they will be acknowledging packets in order to allow for cleanup.
writeAcknowledgement does not check if the packet being acknowledged was actually received, because this would result in proofs being verified twice for acknowledged packets. This aspect of correctness is the responsibility of the calling module.
The calling module MUST only call writeAcknowledgement with a packet previously received from recvPacket.
The IBC handler performs the following steps in order:
- Checks that an acknowledgement for this packet has not yet been written
- Sets the opaque acknowledgement value at a store path unique to the packet
Processing acknowledgements
TheacknowledgePacket function is called by a module to process the acknowledgement of a packet previously sent by
the calling module on a channel to a counterparty module on the counterparty chain.
acknowledgePacket also cleans up the packet commitment, which is no longer necessary since the packet has been received and acted upon.
Calling modules MAY atomically execute appropriate application acknowledgement-handling logic in conjunction with calling acknowledgePacket.
We pass the relayer address just as in Receiving packets to allow for possible incentivization here as well.
Acknowledgement Envelope
The acknowledgement returned from the remote chain is defined as arbitrary bytes in the IBC protocol. This data may either encode a successful execution or a failure (anything besides a timeout). There is no generic way to distinguish the two cases, which requires that any client-side packet visualiser understands every app-specific protocol in order to distinguish the case of successful or failed relay. In order to reduce this issue, we offer an additional specification for acknowledgement formats, which SHOULD be used by the app-specific protocols.0xaa (result)
or 0xb2 (error).
Timeouts
Application semantics may require some timeout: an upper limit to how long the chain will wait for a transaction to be processed before considering it an error. Since the two chains have different local clocks, this is an obvious attack vector for a double spend - an attacker may delay the relay of the receipt or wait to send the packet until right after the timeout - so applications cannot safely implement naive timeout logic themselves. Note that in order to avoid any possible “double-spend” attacks, the timeout algorithm requires that the destination chain is running and reachable. One can prove nothing in a complete network partition, and must wait to connect; the timeout must be proven on the recipient chain, not simply the absence of a response on the sending chain.Sending end
ThetimeoutPacket function is called by a module which originally attempted to send a packet to a counterparty module,
where the timeout height or timeout timestamp has passed on the counterparty chain without the packet being committed, to prove that the packet
can no longer be executed and to allow the calling module to safely perform appropriate state transitions.
Calling modules MAY atomically execute appropriate application timeout-handling logic in conjunction with calling timeoutPacket.
In the case of an ordered channel, timeoutPacket checks the recvSequence of the receiving channel end and closes the channel if a packet has timed out.
In the case of an unordered channel, timeoutPacket checks the absence of the receipt key (which will have been written if the packet was received). Unordered channels are expected to continue in the face of timed-out packets.
If relations are enforced between timeout heights of subsequent packets, safe bulk timeouts of all packets prior to a timed-out packet can be performed. This specification omits details for now.
We pass the relayer address just as in Receiving packets to allow for possible incentivization here as well.
Timing-out on close
ThetimeoutOnClose function is called by a module in order to prove that the channel
to which an unreceived packet was addressed has been closed, so the packet will never be received
(even if the timeoutHeight or timeoutTimestamp has not yet been reached).
Calling modules MAY atomically execute appropriate application timeout-handling logic in conjunction with calling timeoutOnClose.
We pass the relayer address just as in Receiving packets to allow for possible incentivization here as well.
Cleaning up state
Packets must be acknowledged in order to be cleaned-up.Reasoning about race conditions
Simultaneous handshake attempts
If two machines simultaneously initiate channel opening handshakes with each other, attempting to use the same identifiers, both will fail and new identifiers must be used.Identifier allocation
There is an unavoidable race condition on identifier allocation on the destination chain. Modules would be well-advised to utilise pseudo-random, non-valuable identifiers. Managing to claim the identifier that another module wishes to use, however, while annoying, cannot man-in-the-middle a handshake since the receiving module must already own the port to which the handshake was targeted.Timeouts / packet confirmation
There is no race condition between a packet timeout and packet confirmation, as the packet will either have passed the timeout height prior to receipt or not.Man-in-the-middle attacks during handshakes
Verification of cross-chain state prevents man-in-the-middle attacks for both connection handshakes & channel handshakes since all information (source, destination client, channel, etc.) is known by the module which starts the handshake and confirmed prior to handshake completion.Connection / channel closure with in-flight packets
If a connection or channel is closed while packets are in-flight, the packets can no longer be received on the destination chain and can be timed-out on the source chain.Querying channels
Channels can be queried withqueryChannel:
Properties & Invariants
- The unique combinations of channel & port identifiers are first-come-first-serve: once a pair has been allocated, only the modules owning the ports in question can send or receive on that channel.
- Packets are delivered exactly once, assuming that the chains are live within the timeout window, and in case of timeout can be timed-out exactly once on the sending chain.
- The channel handshake cannot be man-in-the-middle attacked by another module on either blockchain or another blockchain’s IBC handler.
Backwards Compatibility
Not applicable.Forwards Compatibility
Data structures & encoding can be versioned at the connection or channel level. Channel logic is completely agnostic to packet data formats, which can be changed by the modules any way they like at any time.Example Implementations
- Implementation of ICS 04 in Go can be found in ibc-go repository.
- Implementation of ICS 04 in Rust can be found in ibc-rs repository.
History
Jun 5, 2019 - Draft submitted Jul 4, 2019 - Modifications for unordered channels & acknowledgements Jul 16, 2019 - Alterations for multi-hop routing future compatibility Jul 29, 2019 - Revisions to handle timeouts after connection closure Aug 13, 2019 - Various edits Aug 25, 2019 - Cleanup Jan 10, 2022 - Add ORDERED_ALLOW_TIMEOUT channel type and appropriate logic Mar 28, 2023 - AddwriteChannel function to write channel end after executing application callback
Dec 4, 2024 - Remove the description for optimistic packet sending