Assessment reports>Packet Forward Middleware>Threat Model>Type: IBCMiddleware

Type: IBCMiddleware

The IBCMiddleware type implements the IBCModule and ICS4Wrapper interfaces, and it has nontrivial implementations of {OnRecvPacket, OnAcknowledgementPacket, OnTimeoutPacket}. All the other methods for the IBCModule interface pass the arguments unmodified to the middleware's app's corresponding methods, and all the methods for the ICS4Wrapper interface pass the arguments unmodified to the middleware's keeper's corresponding methods.

Function: OnRecvPacket

The OnRecvPacket function does the following:

  • It passes packets of types other than FungibleTokenPacketData up the module stack.

  • If the FungibleTokenPacketData's memo field is not JSON or does not have a "forward" key, it passes it up the module stack.

  • If the memo field does not unmarshal as a PacketMetadata, it acknowledges the packet with an error.

  • If the metadata specifies an empty receiver, invalid port, or invalid channel, it acknowledges the packet with an error.

  • It computes the temporary address Bech32(SHA256(SHA256("packetforwardmiddleware") || packet.DestinationChannel || "/" || data.Sender)).

  • If ProcessedKey is unset or set to false in the context (see Finding ref), receiveFunds receives the transfer by passing a modified packet (with the replaced recipient and an empty memo) to receive the funds to the temporary address on the current chain; if an error occurs in receiving the transfer (including a deferred acknowledgment), it acknowledges the original packet with an error.

  • If DisableDenomCompositionKey is unset or set to false in the context, it removes the counterparty's path prefix from the denom and converts it to a native denom if no path remains.

  • If the metadata specifies a nonpositive time-out duration, it uses the IBCMiddleware's forwardTimeout as a default.

  • If the metadata does not specify an amount of retries, it uses the IBCMiddleware's retriesOnTimeout as a default.

  • It invokes the Keeper.ForwardTransferPacket function to forward the packet with the above modifications to the next chain; if an error occurs in forwarding the packet, it acknowledges the original packet with an error.

  • It does not synchronously acknowledge the packet; it defers acknowledgment to OnAcknowledgementPacket/OnTimeoutPacket for the forwarded packet.

Function: OnAcknowledgementPacket

The OnAcknowledgementPacket function does the following:

  • It passes acknowledgments for packets of types other than FungibleTokenPacketData up the module stack.

  • If the acknowledgment data does not unmarshal as an Acknowledgement, it returns an error.

  • It calls Keeper.GetAndClearInFlightPacket to get the packet InFlightData and number of remaining retries.

  • If the InFlightData is present, it calls and returns the result of Keeper.WriteAcknowledgementForForwardedPacket.

  • If the InFlightData is absent, it passes the acknowledgment up the module stack.

Function: OnTimeoutPacket

The OnTimeoutPacket function does the following:

  • It passes time-outs for packets of types other than FungibleTokenPacketData up the module stack.

  • It retrieves the InFlightData via Keeper.TimeoutShouldRetry.

  • If the InFlightData is out of retries, it removes it via RemoveInFlightPacket and notifies the previous hop of the error with Keeper.WriteAcknowledgementForForwardedPacket.

  • If the InFlightData has remaining retries, it handles the underlying time-out on the current chain and then calls Keeper.RetryTimeout.

  • If there is no InFlightData, it passes the time-out up the module stack.

Zellic © 2025Back to top ↑