Skip to content

Coldkey swap dispatch guard#2468

Merged
sam0x17 merged 11 commits intodevnet-readyfrom
coldkey-swap-dispatch-guard
Feb 27, 2026
Merged

Coldkey swap dispatch guard#2468
sam0x17 merged 11 commits intodevnet-readyfrom
coldkey-swap-dispatch-guard

Conversation

@l0r1s
Copy link
Collaborator

@l0r1s l0r1s commented Feb 26, 2026

Refactor CheckColdkeySwap from TransactionExtension to DispatchGuard

Motivation

The previous CheckColdkeySwap implementation was a TransactionExtension that manually unwrapped one level of proxy calls to find the real account. This was fragile — nested proxies (proxy(proxy(real, call))) could bypass the check entirely.

By moving to a DispatchGuard, the check fires at every call.dispatch(origin) site, including inside the proxy pallet's do_proxy(). This automatically handles any nesting depth with the real resolved origin, without any manual proxy unwrapping.

Changes

  • Replaced the CheckColdkeySwap TransactionExtension with a DispatchGuard implementation in a new guards/ module
  • Added ColdkeySwapActive and ColdkeySwapDisputed pallet errors.
  • Cleaned up SubtensorTransactionExtension by removing the inlined guard call and its extra trait bounds
  • Deprecated the ColdkeyInSwapSchedule CustomTransactionError variant (coldkey swap now uses announcements and the check moved to the DispatchGuard) and removed the unused ColdkeySwapDisputed and InvalidRealAccount variants

Test coverage

  • No active swap allows calls through
  • None and Root origins bypass the guard
  • Active swap blocks forbidden calls (remark, add_stake, remove_stake, set_weights, register_network)
  • Active swap allows authorized calls (announce_coldkey_swap, swap_coldkey_announced, dispute_coldkey_swap, submit_encrypted)
  • Disputed swap blocks all calls (forbidden + authorized)
  • Proxied forbidden call is blocked at the inner dispatch level
  • Nested proxy (2 levels deep) is blocked at the innermost dispatch level

@l0r1s
Copy link
Collaborator Author

l0r1s commented Feb 26, 2026

@ales-otf you may be interested in the implementation of a guard for the rate limiting

@l0r1s l0r1s added the skip-cargo-audit This PR fails cargo audit but needs to be merged anyway label Feb 26, 2026
Copy link
Contributor

@open-junius open-junius left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me.

@sam0x17 sam0x17 merged commit 0ec8c10 into devnet-ready Feb 27, 2026
178 of 185 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

skip-cargo-audit This PR fails cargo audit but needs to be merged anyway

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants