From 6ec302bac56a240e5094e51663b04a9bfb442dc4 Mon Sep 17 00:00:00 2001 From: alpurkan17 Date: Mon, 18 May 2026 20:11:01 +0000 Subject: [PATCH] fix: guard handle_pat_check against deregistered hotkey TOCTOU race (#1297) handle_pat_check calls metagraph.hotkeys.index(hotkey) without first verifying the hotkey is still registered. A metagraph refresh between blacklist pass and handler execution causes an uncaught ValueError that crashes the axon coroutine. Fix matches handle_pat_broadcast pattern: reject early with a clear rejection_reason when the hotkey is not in metagraph.hotkeys. --- gittensor/validator/pat_handler.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/gittensor/validator/pat_handler.py b/gittensor/validator/pat_handler.py index 1c6d9b78..8d0c3d68 100644 --- a/gittensor/validator/pat_handler.py +++ b/gittensor/validator/pat_handler.py @@ -105,6 +105,11 @@ async def priority_pat_broadcast(validator: 'Validator', synapse: PatBroadcastSy async def handle_pat_check(validator: 'Validator', synapse: PatCheckSynapse) -> PatCheckSynapse: """Check if the validator has the miner's PAT stored and re-validate it.""" hotkey = _get_hotkey(synapse) + if hotkey not in validator.metagraph.hotkeys: + synapse.has_pat = False + synapse.pat_valid = False + synapse.rejection_reason = 'Hotkey not registered on subnet' + return synapse uid = validator.metagraph.hotkeys.index(hotkey) entry = pat_storage.get_pat_by_uid(uid)