Skip to content

fix: validate hotkey registration on specific subnet in serve_axon and serve_prometheus#2541

Open
ppolewicz wants to merge 9 commits intodevnet-readyfrom
skills-devnet-ready
Open

fix: validate hotkey registration on specific subnet in serve_axon and serve_prometheus#2541
ppolewicz wants to merge 9 commits intodevnet-readyfrom
skills-devnet-ready

Conversation

@ppolewicz
Copy link
Copy Markdown
Collaborator

@ppolewicz ppolewicz commented Mar 27, 2026

Summary

Bug

serve_axon and serve_prometheus used is_hotkey_registered_on_any_network to validate whether a caller is permitted to set axon/prometheus info. This allowed a hotkey to set serving info on any subnet as long as it was registered on some subnet — even one it has no registration on.

Fix

Both serve_axon and serve_prometheus now call is_hotkey_registered_on_network(netuid, hotkey) to ensure the hotkey is actually registered on the specific subnet it is trying to serve on.

Migration: migrate_remove_orphan_axon_prom_cert_v2

A data-cleanup migration removes orphaned serving entries that were created before this fix. On-chain inspection of mainnet found:

  • 242 orphaned Axons entries across 41 subnets
  • 1 orphaned NeuronCertificate entry

Total: 243 orphaned entries. The migration iterates all Axons, Prometheus, and NeuronCertificates storage maps and removes entries where the hotkey is not registered on the corresponding subnet.

Tests

  • test_serve_axon_registered_on_different_subnet — hotkey registered on subnet A cannot serve on subnet B
  • test_serve_prometheus_registered_on_different_subnet — same check for prometheus
  • test_serve_axon_registered_on_correct_subnet — hotkey registered on the correct subnet can serve
  • test_migrate_remove_orphan_axon_prom_cert_v2 — migration correctly removes orphaned entries and leaves valid entries intact

Test plan

  • All pallet-subtensor --lib tests pass (cargo test -p pallet-subtensor --lib)
  • New serving tests confirm the fix blocks cross-subnet axon registration
  • Migration test confirms orphaned entries are removed and valid entries are preserved
  • Check that serve_axon and serve_prometheus return NotRegistered error when hotkey is not registered on the target subnet

🤖 Generated with Claude Code

@ppolewicz ppolewicz added the skip-cargo-audit This PR fails cargo audit but needs to be merged anyway label Mar 27, 2026
@ppolewicz ppolewicz changed the base branch from main to devnet-ready March 27, 2026 19:23
…d serve_prometheus

- serve_axon and serve_prometheus now check is_hotkey_registered_on_network(netuid, ...)
  instead of is_hotkey_registered_on_any_network, preventing hotkeys from setting axon
  info on subnets they are not registered on
- Add migrate_remove_orphan_axon_prom_cert_v2 migration to clean up 243 orphaned entries
  found on mainnet (242 orphaned Axons + 1 orphaned NeuronCertificate across 41 subnets)
- Add 3 new serving tests and 1 migration test
@ppolewicz ppolewicz changed the title Add Claude Code /fix, /format, and /ship skills for automated dev workflow fix: validate hotkey registration on specific subnet in serve_axon and serve_prometheus Mar 28, 2026
Replace saturating_add with + in migration test to comply with the
custom lint that bans safe math in tests (to encourage panics on bugs).
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.

1 participant