Skip to content

Conversation

@Senna46
Copy link
Contributor

@Senna46 Senna46 commented Sep 23, 2025

Overview

This PR addresses a runtime panic (invalid memory address or nil pointer dereference) that occurs during the handling of IBC packet acknowledgements and timeouts in the x/swap module.

Problem

The panic was triggered by unsafe type assertions and method calls on potentially nil fields within the IBC handler logic. The stack trace pointed to ShouldDeleteCompletedWaitingPacket, but further investigation revealed similar potential issues in OnAcknowledgementOutgoingInFlightPacket and OnTimeoutOutgoingInFlightPacket.

The key issues were:

  1. Unsafe type assertions like packet.Change.(*types.IncomingInFlightPacket_AckChange) could panic if the oneof field was not of the expected type, even if it wasn't nil.
  2. Method calls like t.OutgoingIndexChange.Equal(...) would panic if t.OutgoingIndexChange was nil.
  3. switch statements did not explicitly handle nil cases for oneof fields, which could lead to unexpected behavior if the field was not set.

Solution

This PR introduces several changes to make the IBC handling logic more robust and prevent panics:

  1. Safe Type Assertions: Replaced direct type assertions in ShouldDeleteCompletedWaitingPacket with the if ack, ok := ... pattern to safely check the type and value of packet.Change and packet.Forward before accessing their fields.
  2. Nil Checks: Added explicit nil checks in OnAcknowledgementOutgoingInFlightPacket and OnTimeoutOutgoingInFlightPacket before calling the .Equal() method on OutgoingIndexChange and OutgoingIndexForward fields.
  3. Improved Switch Logic: Updated the switch statements in ShouldDeleteCompletedWaitingPacket to explicitly handle the nil case for packet.Change and packet.Forward, treating it as a completed state similar to AckChange/AckForward.

These changes ensure that the packet handling logic is resilient to unexpected states and prevents the node from crashing, improving the overall stability of the swap module.

@Senna46 Senna46 changed the title fix: swap middleware feat: Prevent panic from nil pointer dereference in swap IBC handler Sep 23, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants