Skip to content

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

Open
ppolewicz wants to merge 198 commits intomainfrom
fix/serve-axon-registration-check
Open

fix: validate hotkey registration on specific subnet in serve_axon and serve_prometheus#2545
ppolewicz wants to merge 198 commits intomainfrom
fix/serve-axon-registration-check

Conversation

@ppolewicz
Copy link
Copy Markdown
Collaborator

Summary

  • serve_axon and serve_prometheus used is_hotkey_registered_on_any_network instead of is_hotkey_registered_on_network(netuid, ...), allowing a hotkey registered on any subnet to serve axon/prometheus info on a subnet it is not actually registered on
  • Fixed both checks to require registration on the specific target netuid
  • Added migrate_remove_orphan_axon_prom_cert_v2 migration to clean up the 243 orphaned Axons/NeuronCertificates entries that accumulated on mainnet due to this bug (confirmed via mainnet state inspection script)

Details

Bug: validate_serve_axon and do_serve_prometheus both called is_hotkey_registered_on_any_network, so a hotkey registered on subnet 3 could call serve_axon for subnet 7, writing garbage entries into Axons, Prometheus, and NeuronCertificates for a subnet it had no uid on.

Fix: Both checks now call is_hotkey_registered_on_network(netuid, hotkey) which checks Uids::contains_key(netuid, hotkey).

Migration: A mainnet inspection script (scripts/inspect_orphan_axons.py) found 243 orphaned entries across 41 subnets. This is well within migration safety limits (threshold: 1 000). The migration migrate_remove_orphan_axon_prom_cert_v2 clears them identically to the earlier migrate_remove_unknown_neuron_axon_cert_prom migration but with a new HasMigrationRun key so it runs again.

Test plan

  • test_serve_axon_rejects_hotkey_registered_on_other_network — hotkey on subnet 1 cannot serve axon on subnet 2
  • test_serve_axon_requires_registration_on_target_network — hotkey on correct subnet succeeds
  • test_serve_prometheus_rejects_hotkey_registered_on_other_network — same guard for prometheus
  • test_migrate_remove_orphan_axon_prom_cert_v2 — migration cleans orphaned entries and is idempotent

Note: This PR targets main and is intended to be merged after the skills-devnet-ready branch is merged. Once that merge happens, the diff here will reduce to only the serve_axon–specific commits.

🤖 Generated with Claude Code

gztensor and others added 30 commits January 8, 2026 12:22
shamil-gadelshin and others added 27 commits March 20, 2026 18:54
…-for-ledger-support

Enable `metadata-hash` feature in localnet builds
Add balances to validators on chainspec clone.
Fixes failing types generation for e2e tests
…hip workflow

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
…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
Replace saturating_add with + in migration test to comply with the
custom lint that bans safe math in tests (to encourage panics on bugs).
@ppolewicz ppolewicz added the skip-cargo-audit This PR fails cargo audit but needs to be merged anyway label Mar 28, 2026
…tion check before IP validation in prometheus; fix migration test setup

- Remove redundant `validate_axon_data` call in `do_serve_axon` (already called earlier)
- Move registration check before IP validation in `do_serve_prometheus`
- Add `target: "runtime"` to migration log in migrate_remove_orphan_axon_prom_cert_v2
- Fix migration test: update setup_for args and matching assert
- Use saturating_add in migration test
- Add test_serve_axon_with_cert_rejects_unregistered_hotkey test
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.

10 participants