Skip to content

smartcontract: detect orphaned ResourceExtension accounts in resource verify#3566

Merged
elitegreg merged 2 commits intomainfrom
gm/resource-verify-orphans
Apr 24, 2026
Merged

smartcontract: detect orphaned ResourceExtension accounts in resource verify#3566
elitegreg merged 2 commits intomainfrom
gm/resource-verify-orphans

Conversation

@elitegreg
Copy link
Copy Markdown
Contributor

Summary

  • Extend `doublezero resource verify` to detect `ResourceExtension` accounts on-chain whose PDA does not correspond to any currently-expected resource type (global singleton or per-device extension for a live device/prefix). These accumulate when devices are deleted or a device's `dz_prefixes` list shrinks.
  • With `--fix`, propose closing each orphan in the existing y/N confirmation flow and close via a new `CloseResourceByPubkeyCommand`.
  • Global singletons `VrfIds` and `AdminGroupBits` — not currently verified against usage — are still recognized as legitimate, not flagged as orphans.

Design notes

  • The on-chain `process_closeaccount_resource_extension` only needs the resource account + owner + globalstate, so for orphans (whose `ResourceType` can no longer be derived from live state) we bypass `GetResourceCommand` and pass pubkey/owner directly. Existing `CloseResourceCommand` now delegates to `CloseResourceByPubkeyCommand`.
  • Expected-PDA set is built from loaded state: 8 globals + `TunnelIds(device, 0)` and `DzPrefixBlock(device, i)` for `i in 0..device.dz_prefixes.len()` per device. Anything else in `resource_extensions` is an orphan.
  • Closing requires foundation allowlist membership — failures surface with the same `FAILED: ...` shape used elsewhere in the fix flow.

Testing Verification

  • 4 new unit tests in `verify.rs`:
    • Orphan detection when a device is deleted (dangling `TunnelIds`).
    • Orphan detection when `dz_prefixes` shrinks (stale `DzPrefixBlock(device, i>=len)`).
    • `VrfIds` / `AdminGroupBits` globals present but not verified — confirmed not flagged.
    • Report output contains the new "Orphaned resource extensions" section with the orphan PDA and `associated_with` pubkey.

@elitegreg elitegreg enabled auto-merge (squash) April 22, 2026 18:33
… verify

Extend "doublezero resource verify" to detect ResourceExtension accounts
whose PDA does not correspond to any currently-expected resource type
(global singleton or per-device extension for a live device/prefix).
These accumulate when devices are deleted or a device's dz_prefixes list
shrinks. With --fix, close them via the existing y/N confirmation flow.

Adds CloseResourceByPubkeyCommand to the SDK so orphans (whose
ResourceType is no longer derivable from onchain state) can be closed by
PDA directly. CloseResourceCommand now delegates to it.
@elitegreg elitegreg force-pushed the gm/resource-verify-orphans branch from b98a4b7 to 890e082 Compare April 23, 2026 19:38
Comment thread smartcontract/sdk/rs/src/commands/resource/closeaccount.rs
Comment thread smartcontract/cli/src/resource/verify.rs
@elitegreg elitegreg merged commit 36decfe into main Apr 24, 2026
40 of 41 checks passed
@elitegreg elitegreg deleted the gm/resource-verify-orphans branch April 24, 2026 19:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants