Skip to content

fix(registration): require the new owner's consent for a node-owner swap - #78

Open
faizsarwar wants to merge 3 commits into
mainfrom
fix/registration-node-owner-swap-consent
Open

faizsarwar wants to merge 3 commits into
mainfrom
fix/registration-node-owner-swap-consent

Conversation

@faizsarwar

Copy link
Copy Markdown
Collaborator

Closes #69.

Problem

swap_node_owner(node_id, new_owner) (call 11) moved a node onto new_owner with
only the current owner's signature — the new owner never consented. An owner
could call swap_node_owner(node_id, victim) against any account with no node of
its own: the swap succeeds, victim now owns a node it never asked for, and from
then on victim can't register its own node (every registration path fails with
OwnerAlreadyRegistered). victim also becomes a registered family for Arion's
is_registered_family. Griefing / denial-of-registration against any node-less
account, at no cost (Pays::No), with no funds moved.

Fix

Consenting two-step transfer, per the issue's proposed design:

  • offer_node_owner(node_id, new_owner) — signed by the current owner. Verifies
    ownership, pre-checks the target isn't banned / already registered, and stores
    PendingOwnerSwap[node_id] = (new_owner, expiry).
  • accept_node_owner(node_id) — signed by the proposed new owner. This is where
    consent happens. Re-checks AccountBanned and OwnerAlreadyRegistered at accept
    time
    , rejects and cleans up expired offers, then performs the transfer.
  • cancel_node_owner_offer(node_id) — current owner withdraws a pending offer.
  • swap_node_owner is now root-only, kept as an operator-recovery escape hatch.

The core transfer is extracted into a private do_swap_node_owner so the root path
and the accept path are identical; NodeOwnerSwapped still fires on the actual
transfer either way.

Details

  • New storage PendingOwnerSwap: node_id -> (new_owner, expiry_block) (additive —
    no migration needed).
  • New config constant OwnerSwapOfferExpiry, set to 7 days on mainnet; offers
    past expiry are rejected and removed on accept.
  • New events NodeOwnerSwapOffered / NodeOwnerSwapOfferCancelled; new errors
    NoPendingOwnerSwap / NotPendingNewOwner / OwnerSwapOfferExpired.
  • New call indices 16/17/18; index 11 reused for the now-root-only swap_node_owner.

Testing

  • cargo check -p pallet-registration and -p hippius-mainnet-runtime: clean.

Notes / for review

  • Chose the two-step design over the single-call signed-message alternative — it's
    simpler and needs no nonce map.
  • Offer expiry is 7 days (the issue only said "N blocks"); change the
    OwnerSwapOfferExpiry constant if you want a different window.
  • Kept swap_node_owner as root-only rather than removing it; drop it entirely if
    you'd prefer no single-signature path at all.
  • No unit tests — the pallet's mock.rs/tests.rs are still the unmodified
    Substrate template (TemplateModule), with no working Config for Test. Wiring a
    real mock is out of scope here; happy to do it as a follow-up.

…adjacent)

swap_node_owner moved a node onto any account with only the current
owner's signature, letting an owner park a node on a victim that never
consented and blocking that victim from ever registering its own node
(OwnerAlreadyRegistered), at no cost.

Replace it with a consenting two-step flow:
- offer_node_owner (current owner proposes, stored with an expiry)
- accept_node_owner (proposed owner consents; banned / already-registered
  re-checked at accept time)
- cancel_node_owner_offer (current owner withdraws)

swap_node_owner is now root-only for operator recovery, sharing the core
transfer via do_swap_node_owner. Offers expire after OwnerSwapOfferExpiry
(7 days on mainnet).
accept_node_owner transferred the node from whoever currently owned it,
but the pending offer only recorded the proposed new owner. If ownership
changed between offer and accept -- an operator root swap, or a
deregister followed by a fresh registration of the same node id -- a
stale offer could still move the node away from a current owner who
never offered it, defeating the consent the two-step flow exists for.

Record the offering owner in PendingOwnerSwap and, at accept time,
require the node to still be owned by that account; otherwise reject
with OwnerSwapOfferStale and drop the stale entry.
…s or goes

PendingOwnerSwap was only cleared on accept/cancel, so an offer could
outlive the state it referenced: a node that was deregistered, garbage-
collected, or root-swapped to another owner left a stale offer in
storage (a leak, and the window the previous commit now rejects at
accept time).

Clear the offer at every point the node leaves its current owner:
do_swap_node_owner (covers the root path and accept), the
do_unregister_main_node teardown, and the on_initialize GC that prunes
conflicting registrations. accept_node_owner no longer removes the entry
itself -- do_swap_node_owner does it on success.
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.

registration: swap_node_owner moves a node to an account that never consented

1 participant