[Security] Add defensive Coins length check in IsTradingHalt
Resolve #2582
This MR adds defense-in-depth against a potential index-out-of-bounds panic in IsTradingHalt when processing a MsgSwap with an empty Coins slice.
Summary
- Add an early return to
IsGlobalTradingHaltedwhenMsgSwap.Tx.Coinsis empty (first switch block, line 17) - Move the
Coins[0].Assetaccess inside the existinglen(m.Tx.Coins) > 0guard in the second switch block, fixing dead-code where the length check occurred after the access - Add unit test verifying empty Coins does not panic and correctly falls back to global trading halt
Test plan
-
Existing
KeeperHaltSuite.TestIsTradingHaltpasses (84 tests in keeper/v1) -
New test case verifies empty Coins returns
falsewhen no halt, andtruewhen global halt is set -
make buildsucceeds -
make lintpasses