Introducing a new way to review your PRs.

Read the announcement

lfdt-ibc / ibc-go

Inter-Blockchain Communication Protocol (IBC) implementation in Golang.

View on GitHub

20 documents · Updated Nov 13, 2026

docs / ibc-application-modules

IBC application modules and middleware

IBC application modules give cross-chain packets a useful meaning. They move fungible tokens, create and use remote accounts, run general messages, and add policy or event hooks around packet delivery. Core IBC verifies the channel and packet path. These applications decide what state change the packet causes.

Application model

Application module contract

An application module binds a port to an IBC channel and owns the business result of a packet. Core IBC calls it during channel setup and packet handling. The module sends packets and writes acknowledgements through an IBC wrapper so other middleware can remain in the path. The main application families are fungible token transfer, interchain accounts, and generalized message passing.

References: modules/…/module.go• L13-18 modules/…/module.go• L83-117 modules/…/module.go• L120-166 modules/…/ibc_module.go• L31-41

Packet result flow

The packet contract separates transport from application work. After core IBC verifies a packet, the destination application applies its state change and returns success, failure, or an asynchronous result. The source application later handles the acknowledgement or timeout. This pattern lets each application define its own state change while using the same delivery result.

The shared flow is:

sequenceDiagram
    participant S as Source application
    participant C as Core IBC
    participant R as Relayer
    participant D as Destination application

    S->>C: Send packet
    C-->>R: Packet and commitment
    R->>C: Relay packet proof
    C->>D: Receive callback
    D-->>C: Result or async result
    C-->>R: Acknowledgement
    R->>C: Relay acknowledgement
    C->>S: Acknowledgement callback
    C->>S: Timeout callback when delivery expires

References: modules/…/module.go• L83-108 modules/…/module.go• L120-152 modules/…/module.go• L11-65

Application capabilities

Fungible token transfer

The transfer application moves a denomination, amount, sender, receiver, and optional memo across an IBC path. It keeps supply consistent by escrowing native tokens or burning vouchers on send. The destination then unescrows tokens or mints vouchers. A failed acknowledgement or timeout refunds the send-side action. See IBC fungible token transfer for denomination traces and accounting rules.

Classic transfer channels negotiate an application version during the channel handshake. IBC v2 transfer packets carry their port, version, encoding, and token data in a payload. Both paths apply sender checks and reject packet data that does not match the transfer contract.

References: modules/…/ibc_module.go• L43-72 modules/…/ibc_module.go• L166-216 modules/…/ibc_module.go• L38-85 modules/…/ibc_module.go• L88-166 modules/…/relay.go• L20-51 modules/…/relay.go• L109-243

Interchain accounts

Interchain accounts let a controller chain ask a host chain to run a transaction as a remote account. The channel handshake records the account identity and the connection between the two chains. The controller sends encoded messages. The host checks the registered account, allowed message types, and message signers before it runs the full set atomically. The host returns the execution result in the acknowledgement path. See interchain accounts for controller and host roles.

The controller side owns outgoing account requests. The host side receives them and does not send a packet back on the account channel. A channel timeout or close therefore affects the controller's ability to use the active account path rather than creating a normal response packet.

References: modules/…/handshake.go• L18-86 modules/…/relay.go• L16-55 modules/…/handshake.go• L16-92 modules/…/relay.go• L19-49 modules/…/relay.go• L51-128

Generalized message passing

Generalized message passing uses an IBC v2 payload to carry a sender, receiver, salt, memo, and message bytes. The destination derives a repeatable account identity from the destination client, sender, and salt. It creates the account when needed and executes the contained Cosmos messages as one atomic transaction. Signer checks make that derived account the authorization boundary. See generalized message passing for the cross-chain dispatch model.

The packet supports more than one wire encoding, but the application still requires a valid version and a valid packet shape. The acknowledgement carries the remote execution result. Send and receive validation occurs before the remote state change.

References: modules/…/packet.go• L32-67 modules/…/packet.go• L70-126 modules/…/account.go• L23-65 modules/…/ibc_module.go• L36-72 modules/…/ibc_module.go• L75-160 modules/…/relay.go• L19-48 modules/…/relay.go• L51-127

Version models

IBC Classic applications

IBC Classic applications negotiate an application version during the channel handshake. They receive complete packet callbacks for receive, acknowledgement, and timeout events. They send packets and asynchronous acknowledgements through ICS4Wrapper, which allows middleware to inspect the same events. Transfer and interchain accounts use this model in their Classic paths.

References: modules/…/module.go• L26-117 modules/…/module.go• L120-152 modules/…/ibc_module.go• L75-155 modules/…/ibc_module.go• L38-108

IBC v2 applications

IBC v2 puts the application version and encoding in each payload instead of relying on a channel handshake. A packet can carry one or more application payloads. Each application callback receives client identifiers, a sequence, and the payload. The callback returns a packet result or handles a timeout or acknowledgement. The v2 transfer and generalized message applications use this contract.

Each payload must identify its ports, version, encoding, and value. This lets core IBC validate the packet shape before the application interprets its business data. Middleware can decode a payload through the base application's packet-data interface when it needs application-specific information.

References: modules/…/module.go• L11-80 modules/…/packet.go• L14-33 modules/…/packet.go• L36-88 modules/…/ibc_module.go• L38-55 modules/…/ibc_module.go• L36-50

Middleware behavior

Middleware stack

Middleware wraps an application module to inspect or change the same channel and packet callbacks. It passes ordinary work to the underlying application. It can also reject a send, change receive handling, defer an acknowledgement, or update policy state. The ICS4Wrapper path covers outgoing packets and acknowledgement writes. The application callback path covers incoming packets and packet results.

Middleware must stay in both directions of the stack. The application sends through the outer wrapper, while the wrapper forwards callbacks to the base application. A middleware that needs packet fields asks the base application to decode them. Bypassing either path removes policy, forwarding, or callback behavior from part of the packet lifecycle. See callbacks and rate-limiting middleware for shared policy effects.

References: modules/…/module.go• L110-166 modules/…/ibc_middleware.go• L29-50 modules/…/ibc_middleware.go• L332-363 modules/…/ibc_middleware.go• L58-83 modules/…/ibc_middleware.go• L111-181

Packet forwarding

Packet-forward middleware turns selected token packets into a chain of transfers. It reads forwarding metadata from the transfer memo, receives the token into a controlled intermediate address, and sends a new transfer to the next hop. It keeps a link between the new packet and the prior packet so a later acknowledgement or timeout can be returned to the prior hop. Optional retries can send the next hop again after a timeout. See packet forwarding middleware for the multi-hop flow.

The forwarded packet has no immediate final acknowledgement at the first destination. The middleware writes that result only after the next hop succeeds or fails. This keeps token recovery tied to the final outcome of the forwarding chain.

References: modules/…/forward.go• L24-49 modules/…/ibc_middleware.go• L116-208 modules/…/ibc_middleware.go• L234-329 modules/…/keeper.go• L103-173 modules/…/keeper.go• L183-320

Callback execution

Callback middleware lets a packet opt in to a contract call through callback data in the application packet. It can call the contract after a send, receive, acknowledgement, or timeout. A configured gas limit bounds the callback work. A receive callback can change a successful receive into a failed result. Callbacks after an acknowledgement or timeout report their errors without stopping the packet lifecycle.

The same idea applies to IBC v2. The middleware reads callback data from the payload's application data and can handle an asynchronous acknowledgement when the application later writes it. Invalid opt-in data blocks the stage that must validate it. A callback that is not requested does not change the application flow. See callbacks and rate-limiting middleware for callback boundaries and retry behavior.

References: modules/…/callbacks.go• L50-70 modules/…/callbacks.go• L101-176 modules/…/ibc_middleware.go• L90-135 modules/…/ibc_middleware.go• L137-219 modules/…/ibc_middleware.go• L222-313 modules/…/ibc_middleware.go• L106-156 modules/…/ibc_middleware.go• L158-231 modules/…/ibc_middleware.go• L372-456

Rate-limit enforcement

Rate-limiting middleware tracks token flow by channel or client and denomination. It checks outgoing flow before a packet is sent. It checks incoming flow before the base application receives the packet. A successful result clears the pending marker. An error acknowledgement or timeout reverses the matching flow. An asynchronous result stays pending until its later acknowledgement is written.

The limiter can deny blacklisted denominations, exceeded quotas, or other disallowed flows. It also supports address-pair exceptions. For IBC v2 transfer payloads, the middleware derives the same transfer view before applying the Classic flow rules. See callbacks and rate-limiting middleware for quota state and administrative controls.

References: modules/…/ibc_middleware.go• L66-121 modules/…/ibc_middleware.go• L124-181 modules/…/ibc_middleware.go• L58-129 modules/…/ibc_middleware.go• L132-169 modules/…/flow.go• L20-86 modules/…/packet.go• L183-323

Cross-application relationships

Shared packet data

Transfer, interchain accounts, and generalized message passing give packets different meanings. They still share the same transport result model and the same middleware boundary. Middleware uses the base application's packet-data decoder to inspect that meaning without owning the application's state change. This keeps token accounting, remote execution, and message dispatch inside their applications while policy layers remain reusable.

The Classic path uses channel and packet data together. The v2 path uses payload metadata and application data. A middleware must use the matching decoder and result contract for the path it wraps.

References: modules/…/module.go• L155-166 modules/…/module.go• L67-80 modules/…/ibc_middleware.go• L83-86 modules/…/ibc_middleware.go• L372-376 modules/…/ibc_middleware.go• L49-56

Failure and recovery boundaries

An application failure becomes a failed acknowledgement or a timeout result. The source application then decides how to recover its state. Token transfer refunds funds. Account and message applications report failed remote execution. Middleware adds recovery state for forwarding and rate limits. Each layer must see the same final result so it can clear or reverse its pending work.

Asynchronous acknowledgement changes the timing rather than the meaning of the result. The receive side keeps its pending work until a later acknowledgement write. The forwarding and rate-limit layers therefore need to process both the initial asynchronous result and the final acknowledgement.

References: modules/…/relay.go• L208-243 modules/…/ibc_module.go• L111-158 modules/…/ibc_module.go• L130-169 modules/…/ibc_middleware.go• L206-208 modules/…/ibc_middleware.go• L124-150

Change checklist

When these files or sections are changed, remember to consider these:

  • Keep Classic callback rules and v2 callback rules aligned with the packet or payload shape that each path accepts.
  • When changing packet data, payload data, or acknowledgement rules, update every middleware that decodes or interprets that data.
  • When changing asynchronous acknowledgement behavior, preserve pending-flow cleanup in rate limiting, forwarding state, and callback execution.
  • When changing an application's send path, keep its ICS4Wrapper or v2 acknowledgement wrapper connected so middleware can enforce policy and observe results.
  • When changing interchain account or GMP authorization rules, review account identity derivation and signer checks before message routing.
  • When changing transfer denomination rules, review forwarding and rate-limit denomination parsing because both derive policy keys from transfer traces.

Important failure modes

TriggerConsequenceGuard
An application packet or v2 payload uses the wrong port, version, encoding, or client formatThe application rejects it before its business state changesValidate the path-specific application contract before send and receive
A transfer acknowledgement fails or a transfer times outThe source chain must refund by unescrowing or reminting the tokenKeep denomination traces and escrow or voucher accounting consistent
A host receives an ICA packet while disabled or with a missing account, disallowed message, or wrong signerThe host returns an error and does not execute the remote transactionCheck host parameters, the registered account, allowed messages, and every message signer
GMP derives the wrong account identity or a message has a signer other than that accountThe remote transaction is rejected or could target the wrong authorization boundaryKeep client ID, sender, salt, and signer checks consistent
Forward metadata is malformed or a forwarded packet has no tracked in-flight stateThe packet cannot be forwarded or its result cannot be returned to the prior hopValidate metadata and retain the original packet link until acknowledgement or timeout
A rate limit is exceeded or pending flow is not reversed after failureThe packet is denied or quota state remains wrong for later transfersApply checks through the wrapper and process success, error, timeout, and async acknowledgement paths
A packet opts into a callback with invalid data or too little reserved gasSend or receive can be rejected, or the callback is recorded as failed without stopping later lifecycle workValidate callback data at opt-in and enforce execution and commit gas limits

Key files

FileWhy to read it
modules/…/module.goDefines the Classic application, wrapper, middleware, and packet decoding contracts.
modules/…/module.goDefines the IBC v2 application callbacks, payload decoding, and asynchronous acknowledgement wrapper.
modules/…/packet.goShows the v2 packet and payload shape that carries application version and encoding.
modules/…/ibc_module.go and modules/…/ibc_module.goShow the Classic and v2 transfer boundaries between IBC callbacks and token logic.
modules/…/relay.goShows token escrow, voucher creation, acknowledgement recovery, and timeout recovery.
modules/…/ibc_middleware.go and modules/…/relay.goShow controller-side channel use and outgoing account transaction flow.
modules/…/ibc_module.go and modules/…/relay.goShow host-side packet handling, authorization, and atomic remote execution.
modules/…/ibc_module.go and modules/…/relay.goShow the generalized message packet boundary and remote account execution.
modules/…/ibc_middleware.go and modules/…/keeper.goShow forwarding decisions and acknowledgement or timeout propagation.
modules/…/ibc_middleware.go and modules/…/ibc_middleware.goShow Classic and v2 callback points and their effect on packet handling.
modules/…/ibc_middleware.go and modules/…/ibc_middleware.goShow quota checks at send and receive boundaries and pending-flow cleanup.