Skip to content

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

Open
ppolewicz wants to merge 13 commits intodevnet-readyfrom
fix/serve-axon-registration-check
Open

fix: validate hotkey registration on specific subnet in serve_axon and serve_prometheus#2545
ppolewicz wants to merge 13 commits intodevnet-readyfrom
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

@ppolewicz ppolewicz added the skip-cargo-audit This PR fails cargo audit but needs to be merged anyway label Mar 28, 2026
@ppolewicz ppolewicz changed the base branch from main to devnet-ready April 7, 2026 17:53
ppolewicz and others added 10 commits April 7, 2026 17:56
…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
…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
@ppolewicz ppolewicz force-pushed the fix/serve-axon-registration-check branch from edda939 to 4d30375 Compare April 7, 2026 17:58
Removes an orphaned `<<<<<<< HEAD` conflict marker at line 3145 of
migration.rs that caused `cargo clippy` to fail with an
"encountered diff marker" error.
The merge target (devnet-ready) has staking.rs with imports that are
not alphabetically sorted, which causes `cargo fmt --check` to fail on
the merge commit. Bring the file from devnet-ready and apply rustfmt so
the merged result is correctly formatted.
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