Skip to content
Business logic Audit finding Intermediate

IBC channel version negotiation bypass in IBC hooks middleware

The IBC hooks middleware's OnChanOpenInit function returns the original version parameter instead of the finalVersion negotiated by the underlying application. This causes version mismatches between channel endpoints and breaks the version negotiation chain that hooks are meant to participate in.

Rhaydden Follow

Originally disclosed on Code4rena

Submitted by Rhaydden

https://github.com/initia-labs/initia//blob/f5cd97d3aadd694d511c61ce5f55a772f4d2b904/x/ibc-hooks/ibc_middleware.go#L61

Finding description and impact

The OnChanOpenInit function in ibc_middleware.go incorrectly returns the original version parameter instead of the negotiated finalVersion returned by the underlying app.

38: func (im IBCMiddleware) OnChanOpenInit(
39: 	ctx sdk.Context,
40: 	order channeltypes.Order,
41: 	connectionHops []string,
42: 	portID string,
43: 	channelID string,
44: 	channelCap *capabilitytypes.Capability,
45: 	counterparty channeltypes.Counterparty,
46: 	version string,
47: ) (string, error) {
48: 	if hook, ok := im.ICS4Middleware.Hooks.(OnChanOpenInitOverrideHooks); ok {
49: 		return hook.OnChanOpenInitOverride(im, ctx, order, connectionHops, portID, channelID, channelCap, counterparty, version)
50: 	}
51:
52: 	if hook, ok := im.ICS4Middleware.Hooks.(OnChanOpenInitBeforeHooks); ok {
53: 		hook.OnChanOpenInitBeforeHook(ctx, order, connectionHops, portID, channelID, channelCap, counterparty, version)
54: 	}
55:
56: 	finalVersion, err := im.App.OnChanOpenInit(ctx, order, connectionHops, portID, channelID, channelCap, counterparty, version)
57:
58: 	if hook, ok := im.ICS4Middleware.Hooks.(OnChanOpenInitAfterHooks); ok {
59: 		hook.OnChanOpenInitAfterHook(ctx, order, connectionHops, portID, channelID, channelCap, counterparty, version, finalVersion, err)
60: 	}
61: 	return version, err      ❌
62: }

The middleware ignores any version modifications made by the underlying application during channel initialization leading to version mismatches between channel endpoints. This renders OnChanOpenInitOverrideHooks completely ineffective for version negotiation.

16: type OnChanOpenInitOverrideHooks interface {
17: 	OnChanOpenInitOverride(im IBCMiddleware, ctx sdk.Context, order channeltypes.Order, connectionHops []string, portID string, channelID string, channelCap *capabilitytypes.Capability, counterparty channeltypes.Counterparty, version string) (string, error)
18: }

Also, it provides incorrect version information to OnChanOpenInitAfterHooks.

22: type OnChanOpenInitAfterHooks interface {
23: 	OnChanOpenInitAfterHook(ctx sdk.Context, order channeltypes.Order, connectionHops []string, portID string, channelID string, channelCap *capabilitytypes.Capability, counterparty channeltypes.Counterparty, version string, finalVersion string, err error)
24: }

As a result, the version negotiation chain that hooks are designed to participate in broken.

Recommended mitigation steps

func (im IBCMiddleware) OnChanOpenInit(
    ctx sdk.Context,
    order channeltypes.Order,
    connectionHops []string,
    portID string,
    channelID string,
    channelCap *capabilitytypes.Capability,
    counterparty channeltypes.Counterparty,
    version string,
) (string, error) {
    if hook, ok := im.ICS4Middleware.Hooks.(OnChanOpenInitOverrideHooks); ok {
        return hook.OnChanOpenInitOverride(im, ctx, order, connectionHops, portID, channelID, channelCap, counterparty, version)
    }

    if hook, ok := im.ICS4Middleware.Hooks.(OnChanOpenInitBeforeHooks); ok {
        hook.OnChanOpenInitBeforeHook(ctx, order, connectionHops, portID, channelID, channelCap, counterparty, version)
    }

    finalVersion, err := im.App.OnChanOpenInit(ctx, order, connectionHops, portID, channelID, channelCap, counterparty, version)

    if hook, ok := im.ICS4Middleware.Hooks.(OnChanOpenInitAfterHooks); ok {
        hook.OnChanOpenInitAfterHook(ctx, order, connectionHops, portID, channelID, channelCap, counterparty, version, finalVersion, err)
    }
-   return version, err
+   return finalVersion, err
}

beer-1 (Initia) confirmed and commented:

Fixed here.

Initia mitigated:

Fixed to return final version.

Status: Mitigation confirmed. Full details in reports from 0xAlix2, berndartmueller and Franfran.


The original report as published on Code4rena, by Rhaydden. Images and videos are our own copies; raw HTML is shown as text. View it on Code4rena.

Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.

How it worked

Root cause

The middleware returns the input version variable rather than the finalVersion returned by the underlying app.

What the attacker needed

IBC hooks middleware in use; channel initialisation occurs

The fix

The middleware was fixed to return finalVersion instead of version.

Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.

Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.

When two blockchains open a channel, they agree on a version string. The middleware here is supposed to pass along the version that the app underneath actually agreed to, but it sends back the original request instead. That means the two sides can end up thinking they agreed on different versions.

What is Business logic?

The application works as coded but not as intended: a negative price, a skipped payment step, a limit that can be crossed.

More by Rhaydden

View all

36 more disclosed reports, best first.

More from Initia Cosmos

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Business logic flaws

The lesson behind this report.

The application works as coded but not as intended: a negative price, a skipped payment step, a limit that can be crossed.